Path: blob/main/component/loki/source/internal/kafkatarget/formatter.go
4096 views
package kafkatarget12// This code is copied from Promtail. The kafkatarget package is used to3// configure and run the targets that can read kafka entries and forward them4// to other loki components.56import (7"strings"89"github.com/prometheus/common/model"10"github.com/prometheus/prometheus/model/labels"11"github.com/prometheus/prometheus/model/relabel"12)1314func format(lbs labels.Labels, cfg []*relabel.Config) model.LabelSet {15if len(lbs) == 0 {16return nil17}18processed, _ := relabel.Process(lbs, cfg...)19labelOut := model.LabelSet(LabelsToMetric(processed))20for k := range labelOut {21if strings.HasPrefix(string(k), "__") {22delete(labelOut, k)23}24}25return labelOut26}2728// LabelsToMetric converts a Labels to Metric29// Don't do this on any performance sensitive paths.30func LabelsToMetric(ls labels.Labels) model.Metric {31m := make(model.Metric, len(ls))32for _, l := range ls {33m[model.LabelName(l.Name)] = model.LabelValue(l.Value)34}35return m36}373839