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

Fix prometheus integration test #5783

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,16 @@ void endToEnd() {
Objects.requireNonNull(
resource.getAttributes().get(ResourceAttributes.TELEMETRY_SDK_VERSION))));

assertThat(resourceMetrics.getScopeMetricsCount()).isEqualTo(1);
ScopeMetrics scopeMetrics = resourceMetrics.getScopeMetrics(0);
assertThat(scopeMetrics.getScope().getName()).isEqualTo("otelcol/prometheusreceiver");
assertThat(resourceMetrics.getScopeMetricsCount()).isEqualTo(2);
ScopeMetrics testScopeMetrics =
resourceMetrics.getScopeMetricsList().stream()
.filter(scopeMetrics -> scopeMetrics.getScope().getName().equals("test"))
.findFirst()
.orElseThrow(() -> new IllegalStateException("missing scope with name \"test\""));
assertThat(testScopeMetrics.getScope().getVersion()).isEqualTo("1.0.0");

Optional<Metric> optRequestTotal =
scopeMetrics.getMetricsList().stream()
testScopeMetrics.getMetricsList().stream()
.filter(metric -> metric.getName().equals("requests_total"))
.findFirst();
assertThat(optRequestTotal).isPresent();
Expand All @@ -181,28 +185,6 @@ void endToEnd() {
// same name in different scopes
stringKeyValue("otel_scope_name", "test"),
stringKeyValue("otel_scope_version", "1.0.0"));

// Scope is serialized as info type metric, which is transformed to non-monotonic cumulative sum
Optional<Metric> optTestScopeInfo =
scopeMetrics.getMetricsList().stream()
.filter(metric -> metric.getName().equals("otel_scope_info"))
.findFirst();
assertThat(optTestScopeInfo).isPresent();
Metric testScopeInfo = optTestScopeInfo.get();
assertThat(testScopeInfo.getDataCase()).isEqualTo(Metric.DataCase.SUM);

Sum testScopeInfoSum = testScopeInfo.getSum();
assertThat(testScopeInfoSum.getAggregationTemporality())
.isEqualTo(AggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE);
assertThat(testScopeInfoSum.getIsMonotonic()).isFalse();
assertThat(testScopeInfoSum.getDataPointsCount()).isEqualTo(1);

NumberDataPoint testScopeInfoDataPoint = testScopeInfoSum.getDataPoints(0);
assertThat(testScopeInfoDataPoint.getAsDouble()).isEqualTo(1.0);
assertThat(testScopeInfoDataPoint.getAttributesList())
.containsExactlyInAnyOrder(
stringKeyValue("otel_scope_name", "test"),
stringKeyValue("otel_scope_version", "1.0.0"));
}

private static KeyValue stringKeyValue(String key, String value) {
Expand Down