feat(exporter/prometheus): add default_aggregation parameter to PrometheusMetricReader#5117
feat(exporter/prometheus): add default_aggregation parameter to PrometheusMetricReader#5117Manvi2402 wants to merge 5 commits intoopen-telemetry:mainfrom
Conversation
…theusMetricReader
MikeGoldsmith
left a comment
There was a problem hiding this comment.
This looks good, thanks @Manvi2402. I've left some things to tweak.
I think it's gonna conflict with @herin049's PR (#5118). Whoever's PR merges later will likely have a conflict to resolve.
| def test_default_aggregation(self): | ||
| """Test that default_aggregation parameter is passed to MetricReader.""" | ||
| custom_aggregation = { | ||
| HistogramInstrument: ExplicitBucketHistogramAggregation( | ||
| boundaries=[1.0, 5.0, 10.0] | ||
| ) | ||
| } | ||
| reader = PrometheusMetricReader( | ||
| default_aggregation=custom_aggregation | ||
| ) | ||
| self.assertEqual( | ||
| reader._instrument_class_aggregation[ | ||
| HistogramInstrument | ||
| ].__class__, | ||
| ExplicitBucketHistogramAggregation, | ||
| ) | ||
| reader.shutdown() |
There was a problem hiding this comment.
Indentation is wrong, this won't get run.
| def test_default_aggregation(self): | |
| """Test that default_aggregation parameter is passed to MetricReader.""" | |
| custom_aggregation = { | |
| HistogramInstrument: ExplicitBucketHistogramAggregation( | |
| boundaries=[1.0, 5.0, 10.0] | |
| ) | |
| } | |
| reader = PrometheusMetricReader( | |
| default_aggregation=custom_aggregation | |
| ) | |
| self.assertEqual( | |
| reader._instrument_class_aggregation[ | |
| HistogramInstrument | |
| ].__class__, | |
| ExplicitBucketHistogramAggregation, | |
| ) | |
| reader.shutdown() | |
| def test_default_aggregation(self): | |
| """Test that default_aggregation parameter is passed to MetricReader.""" | |
| custom_aggregation = { | |
| HistogramInstrument: ExplicitBucketHistogramAggregation( | |
| boundaries=[1.0, 5.0, 10.0] | |
| ) | |
| reader = PrometheusMetricReader( | |
| default_aggregation=custom_aggregation | |
| ) | |
| self.assertEqual( | |
| reader._instrument_class_aggregation[ | |
| HistogramInstrument | |
| ].__class__, | |
| ExplicitBucketHistogramAggregation, | |
| ) | |
| reader.shutdown() |
There was a problem hiding this comment.
Fixed the indentation and updated the test to use public API instead of internal attributes
| ObservableUpDownCounter: AggregationTemporality.CUMULATIVE, | ||
| ObservableGauge: AggregationTemporality.CUMULATIVE, | ||
| }, | ||
| preferred_aggregation=default_aggregation, |
There was a problem hiding this comment.
Why call this default_aggregation here? Would be nice to keep consistent as preferred_aggregation.
There was a problem hiding this comment.
Renamed to preferred_aggregation for consistency.
| ## Unreleased | ||
|
|
||
| - `opentelemetry-exporter-prometheus`: Add `default_aggregation` parameter to `PrometheusMetricReader` to allow configuring default aggregation per instrument kind | ||
| ([#5109](https://github.com/open-telemetry/opentelemetry-python/issues/5109)) |
There was a problem hiding this comment.
| ([#5109](https://github.com/open-telemetry/opentelemetry-python/issues/5109)) | |
| ([#5117](https://github.com/open-telemetry/opentelemetry-python/issues/5117)) |
There was a problem hiding this comment.
We prefer the changelog to use the PR number, not the associated issue number. You're welcome to add the issue number to the PR description if it's not there already 🙂
There was a problem hiding this comment.
Thanks for clarifying. Updated the changelog to use the PR number and also renamed default_aggregation to preferred_aggregation in the changelog entry.
Description
Add
default_aggregationparameter toPrometheusMetricReaderto allow configuring default aggregation per instrument kind, aligning with the Prometheus Exporter spec.Fixes #5109
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
test_default_aggregationin test_prometheus_exporter.pythat verifies custom aggregation is correctly passed to the MetricReader.
Does This PR Require a Contrib Repo Change?
Checklist: