Skip to content

Commit f669d31

Browse files
anuqjack-berg
andauthored
Stop converting unit "1" to "ratio" in Prometheus exporter (#8252)
Co-authored-by: Jack Berg <34418638+jack-berg@users.noreply.github.com>
1 parent 00f950a commit f669d31

3 files changed

Lines changed: 15 additions & 16 deletions

File tree

exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/PrometheusUnitsHelper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class PrometheusUnitsHelper {
5353
initUnit("Cel", "celsius");
5454
initUnit("Hz", "hertz");
5555
initUnit("%", "percent");
56-
initUnit("1", "ratio");
5756
}
5857

5958
private PrometheusUnitsHelper() {}
@@ -70,12 +69,12 @@ private static void initUnit(String otelName, String pluralName, String singular
7069

7170
@Nullable
7271
static Unit convertUnit(String otelUnit) {
73-
if (otelUnit.isEmpty()) {
72+
if (otelUnit.isEmpty() || otelUnit.equals("1")) {
7473
return null;
7574
}
7675
if (otelUnit.contains("{")) {
7776
otelUnit = otelUnit.replaceAll("\\{[^}]*}", "").trim();
78-
if (otelUnit.isEmpty() || otelUnit.equals("/")) {
77+
if (otelUnit.isEmpty() || otelUnit.equals("/") || otelUnit.equals("1")) {
7978
return null;
8079
}
8180
}

exporters/prometheus/src/test/java/io/opentelemetry/exporter/prometheus/Otel2PrometheusConverterTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,24 @@ void metricMetadata(
100100

101101
private static Stream<Arguments> metricMetadataArgs() {
102102
return Stream.of(
103-
// the unity unit "1" is translated to "ratio"
103+
// the unity unit "1" is unitless - no suffix added
104104
Arguments.of(
105105
createSampleMetricData("sample", "1", MetricDataType.LONG_GAUGE),
106-
"sample_ratio gauge",
107-
"sample_ratio description",
108-
"sample_ratio"),
106+
"sample gauge",
107+
"sample description",
108+
"sample"),
109109
// unit is appended to metric name
110110
Arguments.of(
111111
createSampleMetricData("sample", "unit", MetricDataType.LONG_GAUGE),
112112
"sample_unit gauge",
113113
"sample_unit description",
114114
"sample_unit"),
115-
// units in curly braces are dropped
115+
// units in curly braces are dropped, "1" is unitless
116116
Arguments.of(
117117
createSampleMetricData("sample", "1{dropped}", MetricDataType.LONG_GAUGE),
118-
"sample_ratio gauge",
119-
"sample_ratio description",
120-
"sample_ratio"),
118+
"sample gauge",
119+
"sample description",
120+
"sample"),
121121
// monotonic sums always include _total suffix
122122
Arguments.of(
123123
createSampleMetricData("sample", "unit", MetricDataType.LONG_SUM),
@@ -126,9 +126,9 @@ private static Stream<Arguments> metricMetadataArgs() {
126126
"sample_unit_total"),
127127
Arguments.of(
128128
createSampleMetricData("sample", "1", MetricDataType.LONG_SUM),
129-
"sample_ratio_total counter",
130-
"sample_ratio_total description",
131-
"sample_ratio_total"),
129+
"sample_total counter",
130+
"sample_total description",
131+
"sample_total"),
132132
// units expressed as numbers other than 1 are retained
133133
Arguments.of(
134134
createSampleMetricData("sample", "2", MetricDataType.LONG_SUM),

exporters/prometheus/src/test/java/io/opentelemetry/exporter/prometheus/PrometheusUnitsHelperTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ private static Stream<Arguments> providePrometheusOTelUnitEquivalentPairs() {
6969
Arguments.of("Cel", "celsius"),
7070
// Unit not found - Case sensitive
7171
Arguments.of("S", "S"),
72-
// Special case - 1
73-
Arguments.of("1", "ratio"),
72+
// Special case - 1 is unitless
73+
Arguments.of("1", null),
7474
// Special Case - Drop metric units in {}
7575
Arguments.of("{packets}", null),
7676
// Special Case - Dropped metric units only in {}

0 commit comments

Comments
 (0)