From 9d94276389f85d3c614251dde7783b7554013d00 Mon Sep 17 00:00:00 2001 From: alexgreenbank Date: Thu, 19 Dec 2024 15:39:08 +0000 Subject: [PATCH] Work on byteslice rather than chars Signed-off-by: alexgreenbank --- pkg/distributor/influxpush/parser.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/distributor/influxpush/parser.go b/pkg/distributor/influxpush/parser.go index 0f0a1c6efe..cffd83017f 100644 --- a/pkg/distributor/influxpush/parser.go +++ b/pkg/distributor/influxpush/parser.go @@ -150,18 +150,21 @@ func influxPointToTimeseries(pt models.Point, returnTs []mimirpb.PreallocTimeser // analog of invalidChars = regexp.MustCompile("[^a-zA-Z0-9_]") func replaceInvalidChars(in *string) { - for charIndex, char := range *in { - if !((char >= 'a' && char <= 'z') || // a-z - (char >= 'A' && char <= 'Z') || // A-Z - (char >= '0' && char <= '9') || // 0-9 - char == '_') { // _ - - *in = (*in)[:charIndex] + "_" + (*in)[charIndex+1:] + bSlice := []byte(*in) + for bIndex, b := range bSlice { + if !((b >= 'a' && b <= 'z') || // a-z + (b >= 'A' && b <= 'Z') || // A-Z + (b >= '0' && b <= '9') || // 0-9 + b == '_') { // _ + bSlice[bIndex] = '_' } } + // prefix with _ if first char is 0-9 - if len(*in) > 0 && int((*in)[0]) >= '0' && int((*in)[0]) <= '9' { - *in = "_" + *in + if len(bSlice) > 0 && bSlice[0] >= '0' && bSlice[0] <= '9' { + *in = "_" + string(bSlice) + } else { + *in = string(bSlice) } }