Skip to content

[chore](prometheusreceiver): use type and unit as identifier in tests #38645

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

Merged

Conversation

krajorama
Copy link
Member

@krajorama krajorama commented Mar 14, 2025

I'd like to fix a technical dept from #28663 where the Prometheus receiver didn't allow receiving both classic and native histogram for the same metric name. To test the implementation, the assertions must not assume that the metric name alone is identifying in OpenTelemetry.

No new tests added, I just refactored to make name+type+unit the identifier.

Also I made it implicit that doCompare fails on metrics that were not expected - excluding the 5 scrape metrics. This means that assertMetricAbsent is not needed anymore.

@github-actions github-actions bot added the receiver/prometheus Prometheus receiver label Mar 14, 2025
@github-actions github-actions bot requested review from Aneurysm9 and dashpole March 14, 2025 21:32
@krajorama krajorama force-pushed the promreceiver-identifying branch 3 times, most recently from a217a55 to 09cbd64 Compare March 15, 2025 08:06
@krajorama krajorama changed the title refactor(receiver/prometheusreceiver): use type and unit as identifier in test [chore](prometheusreceiver): use type and unit as identifier in tests Mar 15, 2025
@krajorama krajorama force-pushed the promreceiver-identifying branch 4 times, most recently from 191b7b5 to d751e3e Compare March 15, 2025 11:22
I'd like to fix a technical dept from open-telemetry#28663 where the Promtheus reveiver
didn't allow receiving both classic and native histogram for the same
metric name. To test the implementation, the assertions must not assume
that the metric name alone is identifying in OpenTelemetry.

No new tests added, I just refactored to make name+type+unit the
identifier.

Also I made it implicit that doCompare fails on metrics that were not
expected - excluding the 5 scrape metrics. This means that
assertMetricAbsent is not needed anymore.

Signed-off-by: György Krajcsovits <[email protected]>
@atoulme
Copy link
Contributor

atoulme commented Mar 17, 2025

@Aneurysm9, @dashpole please review as codeowners.

@krajorama
Copy link
Member Author

The PR #38652 depends on this.

@@ -154,8 +158,9 @@ func verifyRenameMetric(t *testing.T, td *testData, resourceMetrics []pmetric.Re
compareAttributes(map[string]string{"method": "post", "port": "6381"}),
},
},
}),
assertMetricAbsent("rpc_duration_total"),
Copy link
Member Author

Choose a reason for hiding this comment

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

note to reviewers: no longer needed as doCompare does 1-1 check

Comment on lines -195 to -197
assertMetricAbsent("http_go_threads"),
assertMetricAbsent("http_connected_total"),
assertMetricAbsent("redis_http_requests_total"),
Copy link
Member Author

Choose a reason for hiding this comment

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

note to reviewers: no longer needed as doCompare does 1-1 check

[]dataPointExpectation{{
histogramPointComparator: []histogramPointComparator{
compareHistogram(1213, 456, []float64{0.5, 10}, []uint64{789, 222, 202}),
},
}},
),
// When the native histograms feature is off, no native histograms are scraped.
assertMetricAbsent("test_native_histogram"),
Copy link
Member Author

Choose a reason for hiding this comment

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

note to reviewers: no longer needed as doCompare does 1-1 check

[]dataPointExpectation{{
histogramPointComparator: []histogramPointComparator{
compareHistogram(1213, 456, []float64{0.5, 10}, []uint64{789, 222, 202}),
},
}},
),
// When the native histograms feature is off, no native histograms are scraped.
assertMetricAbsent("test_native_histogram"),
Copy link
Member Author

Choose a reason for hiding this comment

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

note to reviewers: no longer needed as doCompare does 1-1 check


func assertMetricAbsent(name string) testExpectation {
Copy link
Member Author

Choose a reason for hiding this comment

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

note to reviewers: no longer needed as doCompare does 1-1 check

Copy link
Contributor

github-actions bot commented Apr 3, 2025

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Apr 3, 2025
@krajorama
Copy link
Member Author

not stale, waiting for reviewer, bump

@andrzej-stencel
Copy link
Member

andrzej-stencel commented Apr 3, 2025

@Aneurysm9 @dashpole can you review as codeowners?

@ArthurSens
Copy link
Member

@andrzej-stencel, given that the current codeowners are absent. Could @krajorama and I become codeowners for the Prometheus receiver?

I can vouch for Krajo. He is a Prometheus maintainer just like I am and surely knows the scraping components.

Copy link
Member

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

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

I've spent a decent amount of time just trying to understand the test framework, rather than understanding the change you're making 😅

LGTM, I've added a comment while I was trying to understand everything but I think I've got it already

Comment on lines -502 to -504
func compareMetricUnit(unit string) metricTypeComparator {
return func(t *testing.T, metric pmetric.Metric) {
assert.Equal(t, unit, metric.Unit(), "Metric unit does not match")
Copy link
Member

Choose a reason for hiding this comment

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

Just wrapping my head around the changes here. compareMetricUnit doesn't exist anymore because unit comparison is being done on line 540, right? Same applies to compareMetricType

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, since they are identifying now, it doesn't make sense to check them independent of the name

@ArthurSens ArthurSens added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Apr 15, 2025
@andrzej-stencel
Copy link
Member

@andrzej-stencel, given that the current codeowners are absent. Could @krajorama and I become codeowners for the Prometheus receiver?

I can vouch for Krajo. He is a Prometheus maintainer just like I am and surely knows the scraping components.

This sounds great to me! ❤️

@andrzej-stencel andrzej-stencel merged commit 75d6464 into open-telemetry:main Apr 16, 2025
192 checks passed
@github-actions github-actions bot added this to the next release milestone Apr 16, 2025
akshays-19 pushed a commit to akshays-19/opentelemetry-collector-contrib that referenced this pull request Apr 23, 2025
…open-telemetry#38645)

I'd like to fix a technical dept from open-telemetry#28663 where the Prometheus
receiver didn't allow receiving both classic and native histogram for
the same metric name. To test the implementation, the assertions must
not assume that the metric name alone is identifying in OpenTelemetry.

No new tests added, I just refactored to make name+type+unit the
identifier.

Also I made it implicit that `doCompare` fails on metrics that were not
expected - excluding the 5 scrape metrics. This means that
`assertMetricAbsent` is not needed anymore.

Signed-off-by: György Krajcsovits <[email protected]>
Fiery-Fenix pushed a commit to Fiery-Fenix/opentelemetry-collector-contrib that referenced this pull request Apr 24, 2025
…open-telemetry#38645)

I'd like to fix a technical dept from open-telemetry#28663 where the Prometheus
receiver didn't allow receiving both classic and native histogram for
the same metric name. To test the implementation, the assertions must
not assume that the metric name alone is identifying in OpenTelemetry.

No new tests added, I just refactored to make name+type+unit the
identifier.

Also I made it implicit that `doCompare` fails on metrics that were not
expected - excluding the 5 scrape metrics. This means that
`assertMetricAbsent` is not needed anymore.

Signed-off-by: György Krajcsovits <[email protected]>
songy23 pushed a commit that referenced this pull request Apr 25, 2025
Depends on #38645 for testing.

#### Description

This is technical dept from #28663, especially in migration
scenarios we want to receive both versions of the same histogram,
the classic explicit and exponential bucket histogram.

The current internal model of the receiver does not allow this, so
I modified the model to not only key metrics by metric family name,
but also whether it's an exponential histogram.

Some callbacks from Promtheus scrape don't tell us what the metric type
is up front.

For AppendExemplar to work I made transaction stateful to remember if it
appended an exponential histogram before.
For Append of staleness marker to work, I modified the algorithm to
discover exponential histogram from the cached metadata and the name.
Due to prometheus/prometheus#16217 I also had
to modify AppendExemplar to detect trying to add exemplars from native
histograms even if native histograms are turned off.

#### Link to tracking issue
Related to #26555 

#### Testing
Unit test updated.

#### Documentation
N/A - does not contradict.

---------

Signed-off-by: György Krajcsovits <[email protected]>
vincentfree pushed a commit to ing-bank/opentelemetry-collector-contrib that referenced this pull request May 6, 2025
…telemetry#39451)

Depends on open-telemetry#38645 for testing.

#### Description

This is technical dept from open-telemetry#28663, especially in migration
scenarios we want to receive both versions of the same histogram,
the classic explicit and exponential bucket histogram.

The current internal model of the receiver does not allow this, so
I modified the model to not only key metrics by metric family name,
but also whether it's an exponential histogram.

Some callbacks from Promtheus scrape don't tell us what the metric type
is up front.

For AppendExemplar to work I made transaction stateful to remember if it
appended an exponential histogram before.
For Append of staleness marker to work, I modified the algorithm to
discover exponential histogram from the cached metadata and the name.
Due to prometheus/prometheus#16217 I also had
to modify AppendExemplar to detect trying to add exemplars from native
histograms even if native histograms are turned off.

#### Link to tracking issue
Related to open-telemetry#26555 

#### Testing
Unit test updated.

#### Documentation
N/A - does not contradict.

---------

Signed-off-by: György Krajcsovits <[email protected]>
vincentfree pushed a commit to ing-bank/opentelemetry-collector-contrib that referenced this pull request May 20, 2025
…telemetry#39451)

Depends on open-telemetry#38645 for testing.

#### Description

This is technical dept from open-telemetry#28663, especially in migration
scenarios we want to receive both versions of the same histogram,
the classic explicit and exponential bucket histogram.

The current internal model of the receiver does not allow this, so
I modified the model to not only key metrics by metric family name,
but also whether it's an exponential histogram.

Some callbacks from Promtheus scrape don't tell us what the metric type
is up front.

For AppendExemplar to work I made transaction stateful to remember if it
appended an exponential histogram before.
For Append of staleness marker to work, I modified the algorithm to
discover exponential histogram from the cached metadata and the name.
Due to prometheus/prometheus#16217 I also had
to modify AppendExemplar to detect trying to add exemplars from native
histograms even if native histograms are turned off.

#### Link to tracking issue
Related to open-telemetry#26555 

#### Testing
Unit test updated.

#### Documentation
N/A - does not contradict.

---------

Signed-off-by: György Krajcsovits <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
receiver/prometheus Prometheus receiver Skip Changelog PRs that do not require a CHANGELOG.md entry waiting-for-code-owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants