Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/pkg/logql/log/util.go

38 lines
701 B

package log
import (
"strings"
)
func uniqueString(s []string) []string {
unique := make(map[string]bool, len(s))
us := make([]string, 0, len(s))
for _, elem := range s {
if len(elem) != 0 {
if !unique[elem] {
us = append(us, elem)
unique[elem] = true
}
}
}
return us
}
func sanitizeLabelKey(key string, isPrefix bool) string {
if len(key) == 0 {
return key
}
key = strings.TrimSpace(key)
if len(key) == 0 {
return key
}
if isPrefix && key[0] >= '0' && key[0] <= '9' {
key = "_" + key
}
return strings.Map(func(r rune) rune {
if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || r == '_' || (r >= '0' && r <= '9') {
return r
}
return '_'
}, key)
}