diff --git a/pkg/logql/syntax/parser.go b/pkg/logql/syntax/parser.go index fe23946e24..19fb17c676 100644 --- a/pkg/logql/syntax/parser.go +++ b/pkg/logql/syntax/parser.go @@ -202,7 +202,18 @@ func ParseLabels(lbs string) (labels.Labels, error) { if err != nil { return nil, err } + // Sort labels to ensure functionally equivalent + // inputs map to the same output sort.Sort(ls) + // Use the label builder to trim empty label values. + // Empty label values are equivalent to absent labels + // in Prometheus, but they unfortunately alter the + // Hash values created. This can cause problems in Loki + // if we can't rely on a set of labels to have a deterministic + // hash value. + // Therefore we must normalize early in the write path. + // See https://github.com/grafana/loki/pull/7355 + // for more information return labels.NewBuilder(ls).Labels(nil), nil }