-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
stage.go
101 lines (94 loc) · 2.49 KB
/
stage.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package stages
import (
"time"
"github.com/go-kit/kit/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
)
const (
StageTypeJSON = "json"
StageTypeRegex = "regex"
StageTypeMetric = "metrics"
StageTypeLabel = "labels"
StageTypeTimestamp = "timestamp"
StageTypeOutput = "output"
StageTypeDocker = "docker"
StageTypeCRI = "cri"
StageTypeMatch = "match"
StageTypeTemplate = "template"
StageTypePipeline = "pipeline"
)
// Stage takes an existing set of labels, timestamp and log entry and returns either a possibly mutated
// timestamp and log entry
type Stage interface {
Process(labels model.LabelSet, extracted map[string]interface{}, time *time.Time, entry *string)
Name() string
}
// StageFunc is modelled on http.HandlerFunc.
type StageFunc func(labels model.LabelSet, extracted map[string]interface{}, time *time.Time, entry *string)
// Process implements EntryHandler.
func (s StageFunc) Process(labels model.LabelSet, extracted map[string]interface{}, time *time.Time, entry *string) {
s(labels, extracted, time, entry)
}
// New creates a new stage for the given type and configuration.
func New(logger log.Logger, jobName *string, stageType string,
cfg interface{}, registerer prometheus.Registerer) (Stage, error) {
var s Stage
var err error
switch stageType {
case StageTypeDocker:
s, err = NewDocker(logger, registerer)
if err != nil {
return nil, err
}
case StageTypeCRI:
s, err = NewCRI(logger, registerer)
if err != nil {
return nil, err
}
case StageTypeJSON:
s, err = newJSONStage(logger, cfg)
if err != nil {
return nil, err
}
case StageTypeRegex:
s, err = newRegexStage(logger, cfg)
if err != nil {
return nil, err
}
case StageTypeMetric:
s, err = newMetricStage(logger, cfg, registerer)
if err != nil {
return nil, err
}
case StageTypeLabel:
s, err = newLabelStage(logger, cfg)
if err != nil {
return nil, err
}
case StageTypeTimestamp:
s, err = newTimestampStage(logger, cfg)
if err != nil {
return nil, err
}
case StageTypeOutput:
s, err = newOutputStage(logger, cfg)
if err != nil {
return nil, err
}
case StageTypeMatch:
s, err = newMatcherStage(logger, jobName, cfg, registerer)
if err != nil {
return nil, err
}
case StageTypeTemplate:
s, err = newTemplateStage(logger, cfg)
if err != nil {
return nil, err
}
default:
return nil, errors.Errorf("Unknown stage type: %s", stageType)
}
return s, nil
}