Apply suggestions from code review

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
This commit is contained in:
Arthur Silva Sens 2025-01-03 15:16:10 -03:00 committed by GitHub
parent bca87fc287
commit cd111bd68b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 4 deletions

View file

@ -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.

View file

@ -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))
}