Browse Source

bugfix: Fix otlp translator switching colons to undescores (#15251)

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
pull/15316/head
Arthur Silva Sens 3 weeks ago committed by GitHub
parent
commit
1a22b1d846
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      storage/remote/otlptranslator/prometheus/normalize_name.go
  2. 4
      storage/remote/otlptranslator/prometheus/normalize_name_test.go

2
storage/remote/otlptranslator/prometheus/normalize_name.go

@ -114,7 +114,7 @@ func normalizeName(metric pmetric.Metric, namespace string) string {
// Split metric name into "tokens" (remove all non-alphanumerics) // Split metric name into "tokens" (remove all non-alphanumerics)
nameTokens := strings.FieldsFunc( nameTokens := strings.FieldsFunc(
metric.Name(), metric.Name(),
func(r rune) bool { return !unicode.IsLetter(r) && !unicode.IsDigit(r) }, func(r rune) bool { return !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != ':' },
) )
// Split unit at the '/' if any // Split unit at the '/' if any

4
storage/remote/otlptranslator/prometheus/normalize_name_test.go

@ -184,8 +184,8 @@ func TestBuildCompliantNameWithNormalize(t *testing.T) {
require.Equal(t, "system_network_io_bytes_total", BuildCompliantName(createCounter("network.io", "By"), "system", true)) require.Equal(t, "system_network_io_bytes_total", BuildCompliantName(createCounter("network.io", "By"), "system", true))
require.Equal(t, "_3_14_digits", BuildCompliantName(createGauge("3.14 digits", ""), "", true)) require.Equal(t, "_3_14_digits", BuildCompliantName(createGauge("3.14 digits", ""), "", true))
require.Equal(t, "envoy_rule_engine_zlib_buf_error", BuildCompliantName(createGauge("envoy__rule_engine_zlib_buf_error", ""), "", true)) require.Equal(t, "envoy_rule_engine_zlib_buf_error", BuildCompliantName(createGauge("envoy__rule_engine_zlib_buf_error", ""), "", true))
require.Equal(t, "foo_bar", BuildCompliantName(createGauge(":foo::bar", ""), "", true)) require.Equal(t, ":foo::bar", BuildCompliantName(createGauge(":foo::bar", ""), "", true))
require.Equal(t, "foo_bar_total", BuildCompliantName(createCounter(":foo::bar", ""), "", true)) require.Equal(t, ":foo::bar_total", BuildCompliantName(createCounter(":foo::bar", ""), "", true))
// Gauges with unit 1 are considered ratios. // Gauges with unit 1 are considered ratios.
require.Equal(t, "foo_bar_ratio", BuildCompliantName(createGauge("foo.bar", "1"), "", true)) require.Equal(t, "foo_bar_ratio", BuildCompliantName(createGauge("foo.bar", "1"), "", true))
// Slashes in units are converted. // Slashes in units are converted.

Loading…
Cancel
Save