-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[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
[chore](prometheusreceiver): use type and unit as identifier in tests #38645
Conversation
a217a55
to
09cbd64
Compare
191b7b5
to
d751e3e
Compare
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]>
d751e3e
to
0ec4ee9
Compare
@Aneurysm9, @dashpole please review as codeowners. |
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"), |
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.
note to reviewers: no longer needed as doCompare does 1-1 check
assertMetricAbsent("http_go_threads"), | ||
assertMetricAbsent("http_connected_total"), | ||
assertMetricAbsent("redis_http_requests_total"), |
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.
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"), |
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.
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"), |
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.
note to reviewers: no longer needed as doCompare does 1-1 check
|
||
func assertMetricAbsent(name string) testExpectation { |
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.
note to reviewers: no longer needed as doCompare does 1-1 check
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
not stale, waiting for reviewer, bump |
@Aneurysm9 @dashpole can you review as codeowners? |
@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. |
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'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
func compareMetricUnit(unit string) metricTypeComparator { | ||
return func(t *testing.T, metric pmetric.Metric) { | ||
assert.Equal(t, unit, metric.Unit(), "Metric unit does not match") |
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.
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
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.
yes, since they are identifying now, it doesn't make sense to check them independent of the name
This sounds great to me! ❤️ |
…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]>
…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]>
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]>
…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]>
…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]>
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 thatassertMetricAbsent
is not needed anymore.