Skip to content

Add Metrics API and aggregator#2247

Merged
sl0thentr0py merged 17 commits into
masterfrom
neel/metrics-base
Mar 12, 2024
Merged

Add Metrics API and aggregator#2247
sl0thentr0py merged 17 commits into
masterfrom
neel/metrics-base

Conversation

@sl0thentr0py

@sl0thentr0py sl0thentr0py commented Feb 16, 2024

Copy link
Copy Markdown
Member
  • 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

@codecov

codecov Bot commented Feb 16, 2024

Copy link
Copy Markdown

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
@sl0thentr0py
sl0thentr0py requested a review from st0012 February 28, 2024 16:12

@cleptric cleptric left a comment

Copy link
Copy Markdown
Member

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?

Comment thread sentry-ruby/lib/sentry/metrics.rb Outdated
Comment thread sentry-ruby/lib/sentry/metrics/aggregator.rb
Comment thread sentry-ruby/lib/sentry/metrics/aggregator.rb
@smeubank smeubank linked an issue Feb 29, 2024 that may be closed by this pull request
@sl0thentr0py

Copy link
Copy Markdown
Member Author

will add unit lists in separate PR

@antonpirker antonpirker left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread sentry-ruby/lib/sentry/metrics/set_metric.rb
Comment thread sentry-ruby/lib/sentry/metrics/aggregator.rb
Comment thread sentry-ruby/lib/sentry/metrics/aggregator.rb
Comment thread sentry-ruby/lib/sentry/metrics/aggregator.rb

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread sentry-ruby/lib/sentry/envelope.rb Outdated
@sl0thentr0py
sl0thentr0py requested a review from st0012 March 11, 2024 18:58

@antonpirker antonpirker left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
@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