mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 06:17:27 -08:00
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:
parent
bca87fc287
commit
cd111bd68b
|
@ -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,
|
// 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.
|
// 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.
|
// If "addMetricSuffixes" is true, it will add them anyway.
|
||||||
//
|
//
|
||||||
// Please use BuildCompliantMetricName for a metric name that follows Prometheus naming conventions.
|
// Please use BuildCompliantMetricName for a metric name that follows Prometheus naming conventions.
|
||||||
|
|
|
@ -174,9 +174,8 @@ func TestAddUnitTokens(t *testing.T) {
|
||||||
{[]string{"token1", "per"}, "main", "per", []string{"token1", "per", "main"}},
|
{[]string{"token1", "per"}, "main", "per", []string{"token1", "per", "main"}},
|
||||||
{[]string{"token1", "main"}, "main", "per", []string{"token1", "main", "per"}},
|
{[]string{"token1", "main"}, "main", "per", []string{"token1", "main", "per"}},
|
||||||
{[]string{"token1"}, "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_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 {
|
for _, test := range tests {
|
||||||
|
@ -207,7 +206,6 @@ func TestBuildCompliantMetricNameWithSuffixes(t *testing.T) {
|
||||||
// Slashes in units are converted.
|
// Slashes in units are converted.
|
||||||
require.Equal(t, "system_io_foo_per_bar_total", BuildCompliantMetricName(createCounter("system.io", "foo/bar"), "", true))
|
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))
|
require.Equal(t, "metric_with_foreign_characters_total", BuildCompliantMetricName(createCounter("metric_with_字符_foreign_characters", ""), "", true))
|
||||||
|
|
||||||
// Removes non aplhanumerical characters from units, but leaves colons.
|
// Removes non aplhanumerical characters from units, but leaves colons.
|
||||||
require.Equal(t, "temperature_:C", BuildCompliantMetricName(createGauge("temperature", "%*()°:C"), "", true))
|
require.Equal(t, "temperature_:C", BuildCompliantMetricName(createGauge("temperature", "%*()°:C"), "", true))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue