-
Notifications
You must be signed in to change notification settings - Fork 250
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
fix: fix that metrics aggregation @data_points.clear will cause hdps cleared #1532
Merged
robertlaurin
merged 4 commits into
open-telemetry:main
from
xuan-cao-swi:fix-metrics-sdk-data-points
Dec 7, 2023
Merged
fix: fix that metrics aggregation @data_points.clear will cause hdps cleared #1532
robertlaurin
merged 4 commits into
open-telemetry:main
from
xuan-cao-swi:fix-metrics-sdk-data-points
Dec 7, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xuan-cao-swi
requested review from
fbogsany,
mwear,
robertlaurin,
dazuma,
ericmustin,
arielvalentin,
ahayworth,
plantfansam and
robbkidd
as code owners
October 20, 2023 16:10
arielvalentin
approved these changes
Oct 25, 2023
mwear
approved these changes
Nov 7, 2023
This was referenced Nov 21, 2023
kaylareopelle
approved these changes
Dec 4, 2023
This was referenced Dec 4, 2023
Failing lint test in jaeger exporter has a fix in #1550. |
robbkidd
approved these changes
Dec 7, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirmed locally that this change resolves the metrics_sdk test suite failures that appear in the PR adding the test suite to CI.
bash-5.1$ git rev-parse --abbrev-ref HEAD
main
bash-5.1$ rake test
Run options: --seed 35051
# Running:
.......S.........S.................S....
Finished in 0.007356s, 5438.1075 runs/s, 19577.1871 assertions/s.
40 runs, 144 assertions, 0 failures, 0 errors, 3 skips
You have skipped tests. Run with --verbose for details.
The Diff Applied
diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/aggregation/explicit_bucket_histogram.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/aggregation/explicit_bucket_histogram.rb
index 641fa51e..58d87cca 100644
--- a/metrics_sdk/lib/opentelemetry/sdk/metrics/aggregation/explicit_bucket_histogram.rb
+++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/aggregation/explicit_bucket_histogram.rb
@@ -32,9 +32,10 @@ module OpenTelemetry
def collect(start_time, end_time)
if @aggregation_temporality == :delta
# Set timestamps and 'move' data point values to result.
- hdps = @data_points.each_value do |hdp|
+ hdps = @data_points.values.map! do |hdp|
hdp.start_time_unix_nano = start_time
hdp.time_unix_nano = end_time
+ hdp
end
@data_points.clear
hdps
diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/aggregation/sum.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/aggregation/sum.rb
index a4bb50f7..31f8ac66 100644
--- a/metrics_sdk/lib/opentelemetry/sdk/metrics/aggregation/sum.rb
+++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/aggregation/sum.rb
@@ -19,9 +19,10 @@ module OpenTelemetry
def collect(start_time, end_time)
if @aggregation_temporality == :delta
# Set timestamps and 'move' data point values to result.
- ndps = @data_points.each_value do |ndp|
+ ndps = @data_points.values.map! do |ndp|
ndp.start_time_unix_nano = start_time
ndp.time_unix_nano = end_time
+ ndp
end
@data_points.clear
ndps
robertlaurin
approved these changes
Dec 7, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In metrics aggregation explicit_bucket_histogram and sum, if the aggregation_temporality is delta,
@data_points
will be cleared at the end of appending time (L39), this will also clear the hdps since they are referenced (i.e. reference variables)Changing the
hdps = @data_points.each_value do |hdp| ... end
tohdps = @data_points.values.map do |hdp| ... end
also changes the data structure returned from collect (i.e. ExplicitBucketHistogram.collect) if aggregation_temporality is delta. The first one return the original@data_points
structure and second one returns array ofHistogramDataPoint
).I think changing the data structure should be fine because when aggregation_temporality is not delta,
collect
will also return array ofHistogramDataPoint
(code); furthermore, the test case for metrics sdk also expecting array ofHistogramDataPoint
from collect (test case).I checked the specification, but couldn't find anything related to data structure of return object from collect; but if there is something, then
@data_points
needs deep copy, also the test case needs change.Test