-
Notifications
You must be signed in to change notification settings - Fork 485
/
formatter.go
37 lines (32 loc) · 972 Bytes
/
formatter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package kafkatarget
// This code is copied from Promtail. The kafkatarget package is used to
// configure and run the targets that can read kafka entries and forward them
// to other loki components.
import (
"strings"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/relabel"
)
func format(lbs labels.Labels, cfg []*relabel.Config) model.LabelSet {
if len(lbs) == 0 {
return nil
}
processed, _ := relabel.Process(lbs, cfg...)
labelOut := model.LabelSet(LabelsToMetric(processed))
for k := range labelOut {
if strings.HasPrefix(string(k), "__") {
delete(labelOut, k)
}
}
return labelOut
}
// LabelsToMetric converts a Labels to Metric
// Don't do this on any performance sensitive paths.
func LabelsToMetric(ls labels.Labels) model.Metric {
m := make(model.Metric, len(ls))
for _, l := range ls {
m[model.LabelName(l.Name)] = model.LabelValue(l.Value)
}
return m
}