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

Add check for metrics name to prevent add duplicated _total suffix #5308

Merged
Merged
Show file tree
Hide file tree
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 @@ -513,7 +513,7 @@ String contentType() {

@Override
String headerName(String name, PrometheusType type) {
if (type == PrometheusType.COUNTER) {
if (type == PrometheusType.COUNTER && !name.endsWith("_total")) {
return name + "_total";
}
return name;
Expand Down Expand Up @@ -652,7 +652,7 @@ static Collection<? extends PointData> getPoints(MetricData metricData) {

private static String metricName(String rawMetricName, PrometheusType type) {
String name = NameSanitizer.INSTANCE.apply(rawMetricName);
if (type == PrometheusType.COUNTER) {
if (type == PrometheusType.COUNTER && !name.endsWith("_total")) {
name = name + "_total";
}
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ class SerializerTest {
1633950672000000000L,
Attributes.of(TYPE, "mcds"),
5))));

private static final MetricData MONOTONIC_CUMULATIVE_DOUBLE_SUM_WITH_SUFFIX_TOTAL =
ImmutableMetricData.createDoubleSum(
Resource.create(Attributes.of(stringKey("kr"), "vr")),
InstrumentationScopeInfo.builder("full")
.setVersion("version")
.setAttributes(Attributes.of(stringKey("ks"), "vs"))
.build(),
"monotonic.cumulative.double.sum.suffix.total",
"description",
"1",
ImmutableSumData.create(
/* isMonotonic= */ true,
AggregationTemporality.CUMULATIVE,
Collections.singletonList(
ImmutableDoublePointData.create(
1633947011000000000L,
1633950672000000000L,
Attributes.of(TYPE, "mcds"),
5))));
private static final MetricData NON_MONOTONIC_CUMULATIVE_DOUBLE_SUM =
ImmutableMetricData.createDoubleSum(
Resource.create(Attributes.of(stringKey("kr"), "vr")),
Expand Down Expand Up @@ -338,6 +358,7 @@ void prometheus004() {
assertThat(
serialize004(
MONOTONIC_CUMULATIVE_DOUBLE_SUM,
MONOTONIC_CUMULATIVE_DOUBLE_SUM_WITH_SUFFIX_TOTAL,
NON_MONOTONIC_CUMULATIVE_DOUBLE_SUM,
DELTA_DOUBLE_SUM, // Deltas are dropped
MONOTONIC_CUMULATIVE_LONG_SUM,
Expand All @@ -361,6 +382,9 @@ void prometheus004() {
+ "# TYPE monotonic_cumulative_double_sum_total counter\n"
+ "# HELP monotonic_cumulative_double_sum_total description\n"
+ "monotonic_cumulative_double_sum_total{otel_scope_name=\"full\",otel_scope_version=\"version\",type=\"mcds\"} 5.0 1633950672000\n"
+ "# TYPE monotonic_cumulative_double_sum_suffix_total counter\n"
+ "# HELP monotonic_cumulative_double_sum_suffix_total description\n"
+ "monotonic_cumulative_double_sum_suffix_total{otel_scope_name=\"full\",otel_scope_version=\"version\",type=\"mcds\"} 5.0 1633950672000\n"
+ "# TYPE non_monotonic_cumulative_double_sum gauge\n"
+ "# HELP non_monotonic_cumulative_double_sum description\n"
+ "non_monotonic_cumulative_double_sum{otel_scope_name=\"full\",otel_scope_version=\"version\",type=\"nmcds\"} 5.0 1633950672000\n"
Expand Down Expand Up @@ -405,6 +429,7 @@ void openMetrics() {
assertThat(
serializeOpenMetrics(
MONOTONIC_CUMULATIVE_DOUBLE_SUM,
MONOTONIC_CUMULATIVE_DOUBLE_SUM_WITH_SUFFIX_TOTAL,
NON_MONOTONIC_CUMULATIVE_DOUBLE_SUM,
DELTA_DOUBLE_SUM, // Deltas are dropped
MONOTONIC_CUMULATIVE_LONG_SUM,
Expand All @@ -428,6 +453,9 @@ void openMetrics() {
+ "# TYPE monotonic_cumulative_double_sum counter\n"
+ "# HELP monotonic_cumulative_double_sum description\n"
+ "monotonic_cumulative_double_sum_total{otel_scope_name=\"full\",otel_scope_version=\"version\",type=\"mcds\"} 5.0 1633950672.000\n"
+ "# TYPE monotonic_cumulative_double_sum_suffix_total counter\n"
+ "# HELP monotonic_cumulative_double_sum_suffix_total description\n"
+ "monotonic_cumulative_double_sum_suffix_total{otel_scope_name=\"full\",otel_scope_version=\"version\",type=\"mcds\"} 5.0 1633950672.000\n"
+ "# TYPE non_monotonic_cumulative_double_sum gauge\n"
+ "# HELP non_monotonic_cumulative_double_sum description\n"
+ "non_monotonic_cumulative_double_sum{otel_scope_name=\"full\",otel_scope_version=\"version\",type=\"nmcds\"} 5.0 1633950672.000\n"
Expand Down