From cd111bd68b87580d6798e7c93692ac5de4a03c21 Mon Sep 17 00:00:00 2001 From: Arthur Silva Sens Date: Fri, 3 Jan 2025 15:16:10 -0300 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Arve Knudsen Signed-off-by: Arthur Silva Sens --- .../remote/otlptranslator/prometheus/metric_name_builder.go | 2 +- .../otlptranslator/prometheus/metric_name_builder_test.go | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/storage/remote/otlptranslator/prometheus/metric_name_builder.go b/storage/remote/otlptranslator/prometheus/metric_name_builder.go index e77ddc0d1a..7c8024e896 100644 --- a/storage/remote/otlptranslator/prometheus/metric_name_builder.go +++ b/storage/remote/otlptranslator/prometheus/metric_name_builder.go @@ -237,7 +237,7 @@ func removeItem(slice []string, value string) []string { // It doesn't do any character transformation, it only prefixes the metric name with the namespace, if any, // and adds metric type suffixes, e.g. "_total" for counters and unit suffixes. // -// Differently from BuildCompliantMetricName, it doesn't pre-check the presence of unit and type suffixes. +// Differently from BuildCompliantMetricName, it doesn't check for the presence of unit and type suffixes. // If "addMetricSuffixes" is true, it will add them anyway. // // Please use BuildCompliantMetricName for a metric name that follows Prometheus naming conventions. diff --git a/storage/remote/otlptranslator/prometheus/metric_name_builder_test.go b/storage/remote/otlptranslator/prometheus/metric_name_builder_test.go index 686a0ec163..a4336b6f38 100644 --- a/storage/remote/otlptranslator/prometheus/metric_name_builder_test.go +++ b/storage/remote/otlptranslator/prometheus/metric_name_builder_test.go @@ -174,9 +174,8 @@ func TestAddUnitTokens(t *testing.T) { {[]string{"token1", "per"}, "main", "per", []string{"token1", "per", "main"}}, {[]string{"token1", "main"}, "main", "per", []string{"token1", "main", "per"}}, {[]string{"token1"}, "main_", "per", []string{"token1", "main", "per"}}, - {[]string{"token1"}, "main_unit", "per_seconds_", []string{"token1", "main_unit", "per_seconds"}}, // trailing underscores are removed - {[]string{"token1"}, "main_unit", "per_", []string{"token1", "main_unit"}}, // 'per_' is removed enterily + {[]string{"token1"}, "main_unit", "per_", []string{"token1", "main_unit"}}, // 'per_' is removed entirely } for _, test := range tests { @@ -207,7 +206,6 @@ func TestBuildCompliantMetricNameWithSuffixes(t *testing.T) { // Slashes in units are converted. require.Equal(t, "system_io_foo_per_bar_total", BuildCompliantMetricName(createCounter("system.io", "foo/bar"), "", true)) require.Equal(t, "metric_with_foreign_characters_total", BuildCompliantMetricName(createCounter("metric_with_字符_foreign_characters", ""), "", true)) - // Removes non aplhanumerical characters from units, but leaves colons. require.Equal(t, "temperature_:C", BuildCompliantMetricName(createGauge("temperature", "%*()°:C"), "", true)) }