Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/loki/source/internal/kafkatarget/formatter.go
4096 views
1
package kafkatarget
2
3
// This code is copied from Promtail. The kafkatarget package is used to
4
// configure and run the targets that can read kafka entries and forward them
5
// to other loki components.
6
7
import (
8
"strings"
9
10
"github.com/prometheus/common/model"
11
"github.com/prometheus/prometheus/model/labels"
12
"github.com/prometheus/prometheus/model/relabel"
13
)
14
15
func format(lbs labels.Labels, cfg []*relabel.Config) model.LabelSet {
16
if len(lbs) == 0 {
17
return nil
18
}
19
processed, _ := relabel.Process(lbs, cfg...)
20
labelOut := model.LabelSet(LabelsToMetric(processed))
21
for k := range labelOut {
22
if strings.HasPrefix(string(k), "__") {
23
delete(labelOut, k)
24
}
25
}
26
return labelOut
27
}
28
29
// LabelsToMetric converts a Labels to Metric
30
// Don't do this on any performance sensitive paths.
31
func LabelsToMetric(ls labels.Labels) model.Metric {
32
m := make(model.Metric, len(ls))
33
for _, l := range ls {
34
m[model.LabelName(l.Name)] = model.LabelValue(l.Value)
35
}
36
return m
37
}
38
39