From 58a757cd01ffe126200b76a9ffc4951f01d51301 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 17 Jul 2024 12:18:38 +0200 Subject: [PATCH] lib: consistently use regexp.Regexp.ReplaceAllLiteralString instead of regexp.Regexp.ReplaceAllString in places where the replacement cannot contain matching group placeholders --- lib/promrelabel/relabel.go | 4 ++-- lib/promscrape/discoveryutils/utils.go | 2 +- lib/protoparser/datadogutils/datadogutils.go | 6 +++--- lib/querytracer/tracer_test.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/promrelabel/relabel.go b/lib/promrelabel/relabel.go index 38ab350c7..601a0297d 100644 --- a/lib/promrelabel/relabel.go +++ b/lib/promrelabel/relabel.go @@ -673,7 +673,7 @@ func SplitMetricNameToTokens(name string) []string { var nonAlphaNumChars = regexp.MustCompile(`[^a-zA-Z0-9]`) var labelNameSanitizer = bytesutil.NewFastStringTransformer(func(s string) string { - return unsupportedLabelNameChars.ReplaceAllString(s, "_") + return unsupportedLabelNameChars.ReplaceAllLiteralString(s, "_") }) var unsupportedLabelNameChars = regexp.MustCompile(`[^a-zA-Z0-9_]`) @@ -686,7 +686,7 @@ func SanitizeMetricName(value string) string { } var metricNameSanitizer = bytesutil.NewFastStringTransformer(func(s string) string { - return unsupportedMetricNameChars.ReplaceAllString(s, "_") + return unsupportedMetricNameChars.ReplaceAllLiteralString(s, "_") }) var unsupportedMetricNameChars = regexp.MustCompile(`[^a-zA-Z0-9_:]`) diff --git a/lib/promscrape/discoveryutils/utils.go b/lib/promscrape/discoveryutils/utils.go index 91a290056..08e867284 100644 --- a/lib/promscrape/discoveryutils/utils.go +++ b/lib/promscrape/discoveryutils/utils.go @@ -20,7 +20,7 @@ func SanitizeLabelName(name string) string { } var labelNamesSanitizer = bytesutil.NewFastStringTransformer(func(s string) string { - return invalidLabelCharRE.ReplaceAllString(s, "_") + return invalidLabelCharRE.ReplaceAllLiteralString(s, "_") }) var invalidLabelCharRE = regexp.MustCompile(`[^a-zA-Z0-9_]`) diff --git a/lib/protoparser/datadogutils/datadogutils.go b/lib/protoparser/datadogutils/datadogutils.go index 51cc79c07..d5c474727 100644 --- a/lib/protoparser/datadogutils/datadogutils.go +++ b/lib/protoparser/datadogutils/datadogutils.go @@ -44,9 +44,9 @@ func SanitizeName(name string) string { } var namesSanitizer = bytesutil.NewFastStringTransformer(func(s string) string { - s = unsupportedDatadogChars.ReplaceAllString(s, "_") - s = multiUnderscores.ReplaceAllString(s, "_") - s = underscoresWithDots.ReplaceAllString(s, ".") + s = unsupportedDatadogChars.ReplaceAllLiteralString(s, "_") + s = multiUnderscores.ReplaceAllLiteralString(s, "_") + s = underscoresWithDots.ReplaceAllLiteralString(s, ".") return s }) diff --git a/lib/querytracer/tracer_test.go b/lib/querytracer/tracer_test.go index d67336f91..b0e4c0973 100644 --- a/lib/querytracer/tracer_test.go +++ b/lib/querytracer/tracer_test.go @@ -221,7 +221,7 @@ func areEqualTracesSkipDuration(s1, s2 string) bool { } func zeroDurationsInTrace(s string) string { - return skipDurationRe.ReplaceAllString(s, " 0ms: ") + return skipDurationRe.ReplaceAllLiteralString(s, " 0ms: ") } var skipDurationRe = regexp.MustCompile(" [0-9.]+ms: ") @@ -233,7 +233,7 @@ func areEqualJSONTracesSkipDuration(s1, s2 string) bool { } func zeroJSONDurationsInTrace(s string) string { - return skipJSONDurationRe.ReplaceAllString(s, `"duration_msec":0`) + return skipJSONDurationRe.ReplaceAllLiteralString(s, `"duration_msec":0`) } var skipJSONDurationRe = regexp.MustCompile(`"duration_msec":[0-9.]+`)