Skip to content

Conversation

xuan-cao-swi
Copy link
Contributor

Description

  1. added merge logic for exponential histogram when the temporality cumulative
  2. added more test case cover merge logic and when scale/bucket size out of range

Test

Test case are copied from python metrics sdk, and modified based on ruby metrics sdk data structure.

Copy link
Contributor

👋 This pull request has been marked as stale because it has been open with no activity. You can: comment on the issue or remove the stale label to hold stale off for a while, add the keep label to hold stale off permanently, or do nothing. If you do nothing this pull request will be closed eventually by the stale bot

@akahn
Copy link

akahn commented Sep 8, 2025

As an end-user what is the result of not having this fix? If we use exponential histograms, are they not accurate?

@xuan-cao-swi
Copy link
Contributor Author

This pr is for adding merge logic for cumulative aggregation.
If you use delta aggregation, it should be accurate (no merge logic required since data will be dropped each time), but if you use cumulative, then it was expecting user's collector/collection side have the merge logic ; otherwise the result is unexpected.

@akahn
Copy link

akahn commented Sep 18, 2025

expecting user's collector/collection side have the merge logic

We use Alloy as the collector—how do I know whether it is able to handle histogram merges? I'm trying to understand whether I need this patch in order to use exponential histograms with the Ruby SDK today.

@xuan-cao-swi
Copy link
Contributor Author

I believe the alloy does merge the exponential histogram bucket (histogram.go)

Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

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

I'm going to take another pass, but two small cleanup points in the meantime

def collect(start_time, end_time, data_points)
if @aggregation_temporality.delta?
# Set timestamps and 'move' data point values to result.
# puts "data_points.inspect: #{data_points.inspect}"
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to keep the puts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@previous_count = {} # 0
@previous_zero_count = {} # 0
@previous_scale = {} # nil
# @start_time_unix_nano = {} #nil
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@kaylareopelle
Copy link
Contributor

@xuan-cao-swi - Could you send me a link to the Python implementation you used? I'd like to compare the two.

@xuan-cao-swi
Copy link
Contributor Author

@kaylareopelle - Yes, _merge function and when the merge is required

Comment on lines 16 to 17
MINIMAL_SCALE = -10
MAXIMAL_SCALE = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the MAXIMAL_SCALE constant used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was used for scale check, but now it's not used since we check scale at exponential histogram class

Comment on lines 16 to 17
MINIMAL_SCALE = 1
MAXIMAL_SCALE = 20
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are these constants used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

end
end

# Integration tests moved from exponential_bucket_histogram_integration_test.rb
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this comment. Isn't this the file we're in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I was meant to move python integration test into this file. Python exp histogram separates the integration test out of main exp histogram test case.

Comment on lines 1043 to 1045
# _(metric_data.sum).must_be_within_epsilon(previous_metric_data.sum, 1e-10)

# omit the test case for now before cumulative aggregation is tested
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to omit this case since the PR is fixing the merge logic for cumulative?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the comment is outdated (removed)

size
end

# checked, only issue is if @previous_scale is nil, then get_low_high may throw error
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this error stop a user's application? Or is it rescued somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the confusion. @previous_scale[attributes] = current_scale if @previous_scale[attributes].nil? will ensure @previous_scale/previous_scale never be nil.

end
end

# checked
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

3 participants