-
Notifications
You must be signed in to change notification settings - Fork 479
/
label_drop.go
46 lines (36 loc) · 1.17 KB
/
label_drop.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
38
39
40
41
42
43
44
45
46
package stages
// This package is ported over from grafana/loki/clients/pkg/logentry/stages.
// We aim to port the stages in steps, to avoid introducing huge amounts of
// new code without being able to slowly review, examine and test them.
import (
"errors"
"time"
"github.com/prometheus/common/model"
)
// ErrEmptyLabelDropStageConfig error returned if the config is empty.
var ErrEmptyLabelDropStageConfig = errors.New("labeldrop stage config cannot be empty")
// LabelDropConfig contains the slice of labels to be dropped.
type LabelDropConfig struct {
Values []string `river:"values,attr"`
}
func newLabelDropStage(config LabelDropConfig) (Stage, error) {
if len(config.Values) < 1 {
return nil, ErrEmptyLabelDropStageConfig
}
return toStage(&labelDropStage{
config: config,
}), nil
}
type labelDropStage struct {
config LabelDropConfig
}
// Process implements Stage.
func (l *labelDropStage) Process(labels model.LabelSet, extracted map[string]interface{}, t *time.Time, entry *string) {
for _, label := range l.config.Values {
delete(labels, model.LabelName(label))
}
}
// Name implements Stage.
func (l *labelDropStage) Name() string {
return StageTypeLabelDrop
}