forked from benthosdev/benthos
/
config.go
66 lines (55 loc) · 1.92 KB
/
config.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
package tracer
import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
yaml "gopkg.in/yaml.v3"
"github.com/dafanshu/benthos/v4/internal/docs"
)
func init() {
// TODO: I'm so confused, these APIs are a nightmare.
otel.SetTextMapPropagator(propagation.TraceContext{})
}
// Config is the all encompassing configuration struct for all tracer types.
type Config struct {
Type string `json:"type" yaml:"type"`
Jaeger JaegerConfig `json:"jaeger" yaml:"jaeger"`
CloudTrace CloudTraceConfig `json:"gcp_cloudtrace" yaml:"gcp_cloudtrace"`
None struct{} `json:"none" yaml:"none"`
Plugin any `json:"plugin,omitempty" yaml:"plugin,omitempty"`
}
// NewConfig returns a configuration struct fully populated with default values.
func NewConfig() Config {
return Config{
Type: "none",
Jaeger: NewJaegerConfig(),
CloudTrace: NewCloudTraceConfig(),
None: struct{}{},
Plugin: nil,
}
}
//------------------------------------------------------------------------------
// UnmarshalYAML ensures that when parsing configs that are in a map or slice
// the default values are still applied.
func (conf *Config) UnmarshalYAML(value *yaml.Node) error {
type confAlias Config
aliased := confAlias(NewConfig())
err := value.Decode(&aliased)
if err != nil {
return docs.NewLintError(value.Line, docs.LintFailedRead, err.Error())
}
var spec docs.ComponentSpec
if aliased.Type, spec, err = docs.GetInferenceCandidateFromYAML(docs.DeprecatedProvider, docs.TypeTracer, value); err != nil {
return docs.NewLintError(value.Line, docs.LintComponentNotFound, err.Error())
}
if spec.Plugin {
pluginNode, err := docs.GetPluginConfigYAML(aliased.Type, value)
if err != nil {
return docs.NewLintError(value.Line, docs.LintFailedRead, err.Error())
}
aliased.Plugin = &pluginNode
} else {
aliased.Plugin = nil
}
*conf = Config(aliased)
return nil
}