Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Metrics API and aggregator #2247

Merged
merged 17 commits into from
Mar 12, 2024
Merged

Add Metrics API and aggregator #2247

merged 17 commits into from
Mar 12, 2024

Conversation

sl0thentr0py
Copy link
Member

@sl0thentr0py sl0thentr0py commented Feb 16, 2024

  • new Sentry::Metrics module with 4 apis that map to the new 4 Sentry::Metrics::Metric classes
    • increment - simple counter
    • distribution - array of observations
    • gauge - statistics (last/min/max/sum/count)
    • set - unique values
  • new Sentry::Metrics::Aggregator that starts a thread that flushes pending metric buckets in 5 second intervals
    • buckets are a nested hash of timestamp (rolled to 10 second intervals) -> metric keys -> actual metric instance
    • there is a random flush_shift once per startup to create jittering
    • flushable buckets are sent in a new statsd type envelope that is not json so made a small change to the Envelope::Item
    • tag key/values are sanitized for unicode/special characters according to the two regexes

Reference spec - https://develop.sentry.dev/sdk/metrics/

part of #2246

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

Merging #2247 (0e87bab) into master (478c4cf) will increase coverage by 0.12%.
The diff coverage is 99.50%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2247      +/-   ##
==========================================
+ Coverage   97.41%   97.54%   +0.12%     
==========================================
  Files         102      110       +8     
  Lines        3828     4026     +198     
==========================================
+ Hits         3729     3927     +198     
  Misses         99       99              
Components Coverage Δ
sentry-ruby 98.23% <99.50%> (+0.08%) ⬆️
sentry-rails 95.05% <ø> (ø)
sentry-sidekiq 94.70% <ø> (ø)
sentry-resque 92.30% <ø> (+1.53%) ⬆️
sentry-delayed_job 95.60% <ø> (ø)
sentry-opentelemetry 100.00% <ø> (ø)
Files Coverage Δ
sentry-ruby/lib/sentry-ruby.rb 96.56% <100.00%> (+0.12%) ⬆️
sentry-ruby/lib/sentry/configuration.rb 98.80% <100.00%> (+0.01%) ⬆️
sentry-ruby/lib/sentry/envelope.rb 97.95% <100.00%> (ø)
sentry-ruby/lib/sentry/metrics.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/metrics/configuration.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/metrics/counter_metric.rb 100.00% <100.00%> (ø)
...try-ruby/lib/sentry/metrics/distribution_metric.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/metrics/gauge_metric.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/metrics/metric.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/metrics/set_metric.rb 100.00% <100.00%> (ø)
... and 3 more

... and 1 file with indirect coverage changes

@sl0thentr0py sl0thentr0py force-pushed the neel/metrics-base branch 3 times, most recently from 11f2f29 to ac951a0 Compare February 21, 2024 14:13
@sl0thentr0py sl0thentr0py force-pushed the neel/metrics-base branch 6 times, most recently from 31f2de9 to 034b84d Compare February 28, 2024 14:25
@sl0thentr0py sl0thentr0py marked this pull request as ready for review February 28, 2024 16:03
@sl0thentr0py sl0thentr0py changed the title metrics wip Add Metrics API and aggregator Feb 28, 2024
@sl0thentr0py sl0thentr0py mentioned this pull request Feb 28, 2024
Copy link
Member

@cleptric cleptric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the units defined somewhere? Or do we rely on people just following docs for the supported default units?

sentry-ruby/lib/sentry/metrics.rb Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/metrics/aggregator.rb Show resolved Hide resolved
@smeubank smeubank linked an issue Feb 29, 2024 that may be closed by this pull request
@sl0thentr0py
Copy link
Member Author

will add unit lists in separate PR

Copy link
Member

@antonpirker antonpirker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments.
I had not yet time to look at the tests.

sentry-ruby/lib/sentry/metrics/set_metric.rb Show resolved Hide resolved
sentry-ruby/lib/sentry/metrics/aggregator.rb Show resolved Hide resolved
sentry-ruby/lib/sentry/metrics/aggregator.rb Show resolved Hide resolved
sentry-ruby/lib/sentry/metrics/aggregator.rb Show resolved Hide resolved

context 'with pending buckets' do
before do
allow(Time).to receive(:now).and_return(fake_time)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should start using timecop for these tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now it's simple enough, if you really want I can refactor all the time related tests separately.

sentry-ruby/lib/sentry/envelope.rb Outdated Show resolved Hide resolved
Copy link
Member

@antonpirker antonpirker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my limited understanding of Ruby this looks OK. Could not find anything that was screaming at me. (It also looks quite similar to the Python implementation.)

@sl0thentr0py
Copy link
Member Author

@st0012 im gonna start merging these because we want to ship this week. If you have things you want changed, feel free to leave reviews anyway, I can change them separately.

@sl0thentr0py sl0thentr0py merged commit d13923b into master Mar 12, 2024
123 checks passed
@sl0thentr0py sl0thentr0py deleted the neel/metrics-base branch March 12, 2024 12:52
@sl0thentr0py sl0thentr0py restored the neel/metrics-base branch March 12, 2024 12:59
@sl0thentr0py sl0thentr0py deleted the neel/metrics-base branch March 12, 2024 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ruby] Add metrics
4 participants