github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/util/marshal/labels.go (about) 1 package marshal 2 3 import ( 4 "github.com/prometheus/prometheus/promql/parser" 5 6 "github.com/grafana/loki/pkg/loghttp" 7 ) 8 9 // NewLabelSet constructs a Labelset from a promql metric list as a string 10 func NewLabelSet(s string) (loghttp.LabelSet, error) { 11 labels, err := parser.ParseMetric(s) 12 if err != nil { 13 return nil, err 14 } 15 ret := make(map[string]string, len(labels)) 16 17 for _, l := range labels { 18 ret[l.Name] = l.Value 19 } 20 21 return ret, nil 22 }