Skip to content
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 @@ -53,7 +53,6 @@ class PrometheusUnitsHelper {
initUnit("Cel", "celsius");
initUnit("Hz", "hertz");
initUnit("%", "percent");
initUnit("1", "ratio");
}

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

@Nullable
static Unit convertUnit(String otelUnit) {
if (otelUnit.isEmpty()) {
if (otelUnit.isEmpty() || otelUnit.equals("1")) {
return null;
}
if (otelUnit.contains("{")) {
otelUnit = otelUnit.replaceAll("\\{[^}]*}", "").trim();
if (otelUnit.isEmpty() || otelUnit.equals("/")) {
if (otelUnit.isEmpty() || otelUnit.equals("/") || otelUnit.equals("1")) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,24 @@ void metricMetadata(

private static Stream<Arguments> metricMetadataArgs() {
return Stream.of(
// the unity unit "1" is translated to "ratio"
// the unity unit "1" is unitless - no suffix added
Arguments.of(
createSampleMetricData("sample", "1", MetricDataType.LONG_GAUGE),
"sample_ratio gauge",
"sample_ratio description",
"sample_ratio"),
"sample gauge",
"sample description",
"sample"),
// unit is appended to metric name
Arguments.of(
createSampleMetricData("sample", "unit", MetricDataType.LONG_GAUGE),
"sample_unit gauge",
"sample_unit description",
"sample_unit"),
// units in curly braces are dropped
// units in curly braces are dropped, "1" is unitless
Arguments.of(
createSampleMetricData("sample", "1{dropped}", MetricDataType.LONG_GAUGE),
"sample_ratio gauge",
"sample_ratio description",
"sample_ratio"),
"sample gauge",
"sample description",
"sample"),
// monotonic sums always include _total suffix
Arguments.of(
createSampleMetricData("sample", "unit", MetricDataType.LONG_SUM),
Expand All @@ -126,9 +126,9 @@ private static Stream<Arguments> metricMetadataArgs() {
"sample_unit_total"),
Arguments.of(
createSampleMetricData("sample", "1", MetricDataType.LONG_SUM),
"sample_ratio_total counter",
"sample_ratio_total description",
"sample_ratio_total"),
"sample_total counter",
"sample_total description",
"sample_total"),
// units expressed as numbers other than 1 are retained
Arguments.of(
createSampleMetricData("sample", "2", MetricDataType.LONG_SUM),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ private static Stream<Arguments> providePrometheusOTelUnitEquivalentPairs() {
Arguments.of("Cel", "celsius"),
// Unit not found - Case sensitive
Arguments.of("S", "S"),
// Special case - 1
Arguments.of("1", "ratio"),
// Special case - 1 is unitless
Arguments.of("1", null),
// Special Case - Drop metric units in {}
Arguments.of("{packets}", null),
// Special Case - Dropped metric units only in {}
Expand Down
Loading