-
Notifications
You must be signed in to change notification settings - Fork 3
NH-124861: redo token calculation #238
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
Changes from all commits
b942e60
5c4633a
9531249
bd6d513
7fef008
f9a4c8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ rubocop_result.txt | |
| git_push.sh | ||
| test_run.sh | ||
| test.js | ||
| review.txt | ||
|
|
||
| # act.secrets | ||
| act.secrets | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ class OboeSampler | |
| TRIGGERED_TRACE_ATTRIBUTE = 'TriggeredTrace' | ||
|
|
||
| TRACESTATE_REGEXP = /^[0-9a-f]{16}-[0-9a-f]{2}$/ | ||
| BUCKET_INTERVAL = 1000 | ||
| DICE_SCALE = 1_000_000 | ||
|
|
||
| OTEL_SAMPLING_DECISION = ::OpenTelemetry::SDK::Trace::Samplers::Decision | ||
|
|
@@ -30,16 +29,14 @@ def initialize(logger) | |
| @counters = SolarWindsAPM::Metrics::Counter.new | ||
| @buckets = { | ||
| SolarWindsAPM::BucketType::DEFAULT => | ||
| SolarWindsAPM::TokenBucket.new(SolarWindsAPM::TokenBucketSettings.new(nil, nil, BUCKET_INTERVAL, 'DEFUALT')), | ||
| SolarWindsAPM::TokenBucket.new(SolarWindsAPM::TokenBucketSettings.new(nil, nil, 'DEFUALT')), | ||
| SolarWindsAPM::BucketType::TRIGGER_RELAXED => | ||
| SolarWindsAPM::TokenBucket.new(SolarWindsAPM::TokenBucketSettings.new(nil, nil, BUCKET_INTERVAL, 'TRIGGER_RELAXED')), | ||
| SolarWindsAPM::TokenBucket.new(SolarWindsAPM::TokenBucketSettings.new(nil, nil, 'TRIGGER_RELAXED')), | ||
| SolarWindsAPM::BucketType::TRIGGER_STRICT => | ||
| SolarWindsAPM::TokenBucket.new(SolarWindsAPM::TokenBucketSettings.new(nil, nil, BUCKET_INTERVAL, 'TRIGGER_STRICT')) | ||
| SolarWindsAPM::TokenBucket.new(SolarWindsAPM::TokenBucketSettings.new(nil, nil, 'TRIGGER_STRICT')) | ||
| } | ||
| @settings = {} # parsed setting from swo backend | ||
| @settings_mutex = ::Mutex.new | ||
|
|
||
| @buckets.each_value(&:start) | ||
| end | ||
|
|
||
| # return sampling result | ||
|
|
@@ -289,9 +286,9 @@ def disabled_algo(sample_state) | |
| end | ||
|
|
||
| def update_settings(settings) | ||
| return unless settings[:timestamp] > (@settings[:timestamp] || 0) | ||
|
|
||
| @settings_mutex.synchronize do | ||
| return unless settings[:timestamp] > (@settings[:timestamp] || 0) | ||
|
|
||
| @settings = settings | ||
| @buckets.each do |type, bucket| | ||
| bucket.update(@settings[:buckets][type]) if @settings[:buckets][type] | ||
|
|
@@ -324,18 +321,20 @@ def sw_from_span_and_decision(parent_span, otel_decision) | |
| end | ||
|
|
||
| def get_settings(params) | ||
| return if @settings.empty? | ||
|
|
||
| expiry = (@settings[:timestamp] + @settings[:ttl]) * 1000 | ||
| time_now = Time.now.to_i * 1000 | ||
| if time_now > expiry | ||
| @logger.debug { "[#{self.class}/#{__method__}] settings expired, removing" } | ||
| @settings = {} | ||
| return | ||
| @settings_mutex.synchronize do | ||
| return if @settings.empty? | ||
|
xuan-cao-swi marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was looking with copilot help on the question of early returns from a mutex synchronized block, whether that would release the lock. Seems yes (at least for MRI) but also seems
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, they will return nil and be handled by unless sample_state.settings
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm but i see before that line there's also https://github.com/solarwinds/apm-ruby/blob/NH-124861/lib/solarwinds_apm/sampling/oboe_sampler.rb#L77
which would throw an error if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think sample_state will be nil. It will always create the struct from
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OMG i can't read, yes you're right. But now also seeing https://github.com/solarwinds/apm-ruby/blob/7.1.0/lib/solarwinds_apm/sampling/oboe_sampler.rb#L133
which would access a possibly nill
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i see. |
||
|
|
||
| expiry = (@settings[:timestamp] + @settings[:ttl]) * 1000 | ||
| time_now = Time.now.to_i * 1000 | ||
| if time_now > expiry | ||
| @logger.debug { "[#{self.class}/#{__method__}] settings expired, removing" } | ||
| @settings = {} | ||
| return | ||
| end | ||
| sampling_setting = SolarWindsAPM::SamplingSettings.merge(@settings, local_settings(params)) | ||
| @logger.debug { "[#{self.class}/#{__method__}] sampling_setting: #{sampling_setting.inspect}" } | ||
| sampling_setting | ||
| end | ||
| sampling_setting = SolarWindsAPM::SamplingSettings.merge(@settings, local_settings(params)) | ||
| @logger.debug { "[#{self.class}/#{__method__}] sampling_setting: #{sampling_setting.inspect}" } | ||
| sampling_setting | ||
| end | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.