-
Notifications
You must be signed in to change notification settings - Fork 656
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
Implement ExplicitBucketBoundaries advisory for Histograms #4361
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks. Any clue on the docs CI error? I would say to add to nitpick_ignore.
Nope, it's really hard for me to understand where this is coming from. Tried using |
Appear to work fine with the flask implementation after updating the create_histogram calls for HTTP_SERVER_REQUEST_DURATION:
|
We can probably use a TypedDict or just add
|
Moved to TypedDict, thanks for the hint! |
3c8b98e
to
181596b
Compare
@@ -56,3 +55,7 @@ | |||
], | |||
..., | |||
] | |||
|
|||
|
|||
class MetricsInstrumentAdvisory(TypedDict): |
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.
Did you consider using a dataclass instead of typed dict? IMO dataclass is a little cleaner and has validation for users not using typing, but maybe there are some tradeoffs
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.
Nope, I'll fix the other comments and then look at this
if raise_error: | ||
raise ValueError( | ||
"Advisory must be a dict with explicit_bucket_boundaries key containing a sequence of numbers" | ||
) |
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.
Copied from the spec, emphasis mine
When a Meter creates an instrument, it SHOULD validate the instrument advisory parameters. If an advisory parameter is not valid, the Meter SHOULD emit an error notifying the user and proceed as if the parameter was not provided.
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.
Corrected, thanks!
7500.0, | ||
10000.0, | ||
), | ||
boundaries: Optional[Sequence[float]] = None, |
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.
Any reason to not leave the default as _DEFAULT_EXPLICIT_BUCKET_HISTOGRAM_AGGREGATION_BOUNDARIES
? I'm wondering because this allows explicitly passing None
now
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.
@aabmass Yeah, now you can pass None boundaries but then the defaults boundaries are used. Also this is more pythonic I guess?
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.
What's the reason user would pass None instead of allowing the default?
instrumentation_scope=instrumentation_scope, | ||
measurement_consumer=measurement_consumer, | ||
) | ||
self.advisory = advisory |
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.
This is a new part of the public API right? Should we make it protected or do users have any reason to read it?
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.
Made it private
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/instrument.py
Outdated
Show resolved
Hide resolved
CHANGELOG.md
Outdated
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.
Is this covered already?
If multiple identical Instruments are created with different advisory parameters, the Meter MUST return an instrument using the first-seen advisory parameters and log an appropriate error as described in duplicate instrument registrations.
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.
Our duplicate instrument check is already wrong and printing the warning when two identical instruments are created instead of conflicting ones. I've a local branch updating it here
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 see tests are red there, will fix and open a PR tomorrow
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.
Is this requirement covered when using Default aggregation?
Explicit Bucket Histogram Aggregation, with the ExplicitBucketBoundaries advisory parameter if provided
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 think we use it already
CHANGELOG.md
Outdated
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 also think we are missing tests for the new behavior. Would be nice to see integration tests for the cross product of
- views/no views
- advisory/no advisory
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 can add tests for interaction with views for sure. What kind of integration tests are you thinking for advisory? I've added a test for create_histogram method that is what instrumentations are using for creating them.
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.
Something high level like this test https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-sdk/tests/metrics/integration_test/test_disable_default_views.py. I guess just to capture the possible use cases and make sure we don't have unexpected behavior e.g.
- User does nothing -> advisory buckets are used
- User passes default aggregation to histogram -> advisory buckets are used
- User passes ExplicitBucketHistogramAggregation -> view buckets are used
22b40b0
to
c148618
Compare
Description
This adds basic support for the advisory attribute of Instruments and implements ExplicitBucketBoundaries advisory for Histograms.
Fixes #4140
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Contrib Repo Change?
Checklist: