Skip to content

Commit

Permalink
Work on byteslice rather than chars
Browse files Browse the repository at this point in the history
Signed-off-by: alexgreenbank <[email protected]>
  • Loading branch information
alexgreenbank committed Dec 19, 2024
1 parent d65b3a5 commit 9d94276
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions pkg/distributor/influxpush/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 9d94276

Please sign in to comment.