diff --git a/pkg/logql/metrics.go b/pkg/logql/metrics.go index 470ac3e231835..3adb9dabdab87 100644 --- a/pkg/logql/metrics.go +++ b/pkg/logql/metrics.go @@ -335,13 +335,13 @@ func tagsToKeyValues(queryTags string) []interface{} { if len(val) != 2 { continue } - vals = append(vals, val...) + vals = append(vals, strings.ToLower(val[0]), val[1]) } res := make([]interface{}, 0, len(vals)) for _, val := range vals { - res = append(res, strings.ToLower(val)) + res = append(res, val) } return res diff --git a/pkg/logql/metrics_test.go b/pkg/logql/metrics_test.go index 102206c925d0c..46add724dd77d 100644 --- a/pkg/logql/metrics_test.go +++ b/pkg/logql/metrics_test.go @@ -160,12 +160,14 @@ func Test_testToKeyValues(t *testing.T) { }, { name: "canonical-form-multiple-values", - in: "Source=logvolhist,Feature=beta", + in: "Source=logvolhist,Feature=beta,User=Jinx@grafana.com", exp: []interface{}{ "source", "logvolhist", "feature", "beta", + "user", + "Jinx@grafana.com", }, }, { diff --git a/pkg/util/httpreq/tags.go b/pkg/util/httpreq/tags.go index 93efd7505ef0a..1753042c65a51 100644 --- a/pkg/util/httpreq/tags.go +++ b/pkg/util/httpreq/tags.go @@ -16,7 +16,7 @@ type ctxKey string var ( QueryTagsHTTPHeader ctxKey = "X-Query-Tags" - safeQueryTags = regexp.MustCompile("[^a-zA-Z0-9-=, ]+") // only alpha-numeric, ' ', ',', '=' and `-` + safeQueryTags = regexp.MustCompile("[^a-zA-Z0-9-=.@, ]+") // only alpha-numeric, ' ', ',', '=', '@', '.' and `-` QueryQueueTimeHTTPHeader ctxKey = "X-Query-Queue-Time" ) @@ -26,7 +26,7 @@ func ExtractQueryTagsMiddleware() middleware.Interface { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { ctx := req.Context() tags := req.Header.Get(string(QueryTagsHTTPHeader)) - tags = safeQueryTags.ReplaceAllString(tags, "") + tags = safeQueryTags.ReplaceAllString(tags, "_") if tags != "" { ctx = context.WithValue(ctx, QueryTagsHTTPHeader, tags) diff --git a/pkg/util/httpreq/tags_test.go b/pkg/util/httpreq/tags_test.go index bf96142ca84f1..830e13c84af49 100644 --- a/pkg/util/httpreq/tags_test.go +++ b/pkg/util/httpreq/tags_test.go @@ -30,7 +30,12 @@ func TestQueryTags(t *testing.T) { { desc: "remove-invalid-chars", in: `Source=log+volhi\\st,Statate=be$ta`, - exp: `Source=logvolhist,Statate=beta`, + exp: `Source=log_volhi_st,Statate=be_ta`, + }, + { + desc: "test invalid char set", + in: `Source=abc.def@geh.com_test-test`, + exp: `Source=abc.def@geh.com_test-test`, }, } { t.Run(tc.desc, func(t *testing.T) {