-
Notifications
You must be signed in to change notification settings - Fork 478
/
factory.go
129 lines (108 loc) · 4.56 KB
/
factory.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package automaticloggingprocessor
import (
"context"
"fmt"
"time"
"github.com/grafana/agent/pkg/logs"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor/processorhelper"
)
// TypeStr is the unique identifier for the Automatic Logging processor.
const TypeStr = "automatic_logging"
// Config holds the configuration for the Automatic Logging processor.
type Config struct {
config.ProcessorSettings `mapstructure:",squash"`
LoggingConfig *AutomaticLoggingConfig `mapstructure:"automatic_logging"`
}
// AutomaticLoggingConfig holds config information for automatic logging
type AutomaticLoggingConfig struct {
Backend string `mapstructure:"backend" yaml:"backend,omitempty"`
LogsName string `mapstructure:"logs_instance_name" yaml:"logs_instance_name,omitempty"`
Spans bool `mapstructure:"spans" yaml:"spans,omitempty"`
Roots bool `mapstructure:"roots" yaml:"roots,omitempty"`
Processes bool `mapstructure:"processes" yaml:"processes,omitempty"`
SpanAttributes []string `mapstructure:"span_attributes" yaml:"span_attributes,omitempty"`
ProcessAttributes []string `mapstructure:"process_attributes" yaml:"process_attributes,omitempty"`
Overrides OverrideConfig `mapstructure:"overrides" yaml:"overrides,omitempty"`
Timeout time.Duration `mapstructure:"timeout" yaml:"timeout,omitempty"`
Labels []string `mapstructure:"labels" yaml:"labels,omitempty"`
// Deprecated fields:
LokiName string `mapstructure:"loki_name" yaml:"loki_name,omitempty"` // Superseded by LogsName
}
// Validate ensures that the AutomaticLoggingConfig is valid.
func (c *AutomaticLoggingConfig) Validate(logsConfig *logs.Config) error {
if c.Backend == BackendLoki {
c.Backend = BackendLogs
}
if c.LogsName != "" && c.LokiName != "" {
return fmt.Errorf("must configure at most one of logs_instance_name and loki_name. loki_name is deprecated in favor of logs_instance_name")
}
// Migrate deprecated config to new one
if c.LogsName == "" && c.LokiName != "" {
c.LogsName, c.LokiName = c.LokiName, ""
}
if c.Overrides.LogsTag != "" && c.Overrides.LokiTag != "" {
return fmt.Errorf("must configure at most one of overrides.logs_instance_tag and overrides.loki_tag. loki_tag is deprecated in favor of logs_instance_tag")
}
// Migrate deprecated config to new one
if c.Overrides.LogsTag == "" && c.Overrides.LokiTag != "" {
c.Overrides.LogsTag, c.Overrides.LokiTag = c.Overrides.LokiTag, ""
}
// Ensure the logging instance exists when using it as a backend.
if c.Backend == BackendLogs {
var found bool
for _, inst := range logsConfig.Configs {
if inst.Name == c.LogsName {
found = true
break
}
}
if !found {
return fmt.Errorf("specified logs config %s not found in agent config", c.LogsName)
}
}
return nil
}
// OverrideConfig contains overrides for various strings
type OverrideConfig struct {
LogsTag string `mapstructure:"logs_instance_tag" yaml:"logs_instance_tag,omitempty"`
ServiceKey string `mapstructure:"service_key" yaml:"service_key,omitempty"`
SpanNameKey string `mapstructure:"span_name_key" yaml:"span_name_key,omitempty"`
StatusKey string `mapstructure:"status_key" yaml:"status_key,omitempty"`
DurationKey string `mapstructure:"duration_key" yaml:"duration_key,omitempty"`
TraceIDKey string `mapstructure:"trace_id_key" yaml:"trace_id_key,omitempty"`
// Deprecated fields:
LokiTag string `mapstructure:"loki_tag" yaml:"loki_tag,omitempty"` // Superseded by LogsTag
}
const (
// BackendLogs is the backend config for sending logs to a Loki pipeline
BackendLogs = "logs_instance"
// BackendLoki is an alias to BackendLogs. DEPRECATED.
BackendLoki = "loki"
// BackendStdout is the backend config value for sending logs to stdout
BackendStdout = "stdout"
)
// NewFactory returns a new factory for the Attributes processor.
func NewFactory() component.ProcessorFactory {
return processorhelper.NewFactory(
TypeStr,
createDefaultConfig,
processorhelper.WithTraces(createTraceProcessor),
)
}
func createDefaultConfig() config.Processor {
return &Config{
ProcessorSettings: config.NewProcessorSettings(config.NewIDWithName(TypeStr, TypeStr)),
}
}
func createTraceProcessor(
_ context.Context,
cp component.ProcessorCreateSettings,
cfg config.Processor,
nextConsumer consumer.Traces,
) (component.TracesProcessor, error) {
oCfg := cfg.(*Config)
return newTraceProcessor(nextConsumer, oCfg.LoggingConfig)
}