Skip to content
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

Honorning buckets passed as part of PrometheusMetrics initialization … #174 #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Rdgarg
Copy link

@Rdgarg Rdgarg commented Mar 27, 2024

Honoring buckets passed as part of PrometheusMetrics initialization in Histogram metrics.

@Rdgarg Rdgarg marked this pull request as ready for review March 27, 2024 11:56
@Rdgarg
Copy link
Author

Rdgarg commented Mar 27, 2024

#174

@Rdgarg Rdgarg changed the title Honorning buckets passed as part of PrometheusMetrics initialization …#174 Honorning buckets passed as part of PrometheusMetrics initialization … #174 Mar 27, 2024
@coveralls
Copy link

Coverage Status

coverage: 84.835% (+1.2%) from 83.617%
when pulling a461ff4 on Rdgarg:HonoringBucketsInHistogram
into 9e20f3f on rycus86:master.

@@ -679,6 +679,10 @@ def _track(self, metric_type, metric_call, metric_kwargs, name, description, lab

labels = self._get_combined_labels(labels)

if metric_type is Histogram:
Copy link
Owner

Choose a reason for hiding this comment

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

OK, I think the change is good, but I'm not sure this should hang off self.buckets.
The doc on that one says

:param buckets: the time buckets for request latencies (will use the default when `None`)

So up until now, it would only affect the default request latency metrics the library adds, not the manually decorated histogram metrics (you can add buckets=(...) on those specifically).
If you'd like to avoid duplicating the buckets, you can either make it a variable, or we could look at adding a default_histogram_buckets parameter here instead.

What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

Hi,

I dont think I fully got it. What do you mean by

If you'd like to avoid duplicating the buckets, you can either make it a variable, or we could look at adding a default_histogram_buckets parameter here instead.

Copy link
Owner

Choose a reason for hiding this comment

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

I meant, from your example, you could do this:

buckets = (0.005, 0.1, 0.2, INF)
metrics = PrometheusMetrics(app, buckets=buckets)
shorten_url_duration = metrics.histogram('shorten_url_duration', 'Duration of shorten_url call', buckets=buckets)

Copy link
Author

Choose a reason for hiding this comment

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

I was already doing that :P
But shouldn't the buckets which got passed during PrometheusMetrics initialization be honored while creating a histogram metrics.

Copy link
Owner

Choose a reason for hiding this comment

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

We could do that, but we would change what that buckets parameter does currently on PrometheusMetrics where the docs say the time buckets for request latencies, which is why I suggested that perhaps a different variable could work there as some consumers might use this parameter currently and expect it to only apply to request latencies but not to custom histograms.
At that point though, manually declaring the buckets there may be cleaner?

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.

3 participants