forked from jriguera/otel-helloworldprocessor
-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
60 lines (53 loc) · 1.84 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
package contextprocessor
import (
"fmt"
)
var (
errMissingActionConfig = fmt.Errorf("missing actions configuration")
errMissingActionConfigKey = fmt.Errorf("missing action key")
errMissingActionConfigSource = fmt.Errorf("missing action source, must be 'from_attribute' or 'value'")
errMissingActionDeleteParams = fmt.Errorf("action delete does not support 'from_attribute' and/or 'value'")
)
// Config represents the receiver config settings within the collector's config.yaml
type Config struct {
ActionsConfig []ActionConfig `mapstructure:"actions"`
}
// ActionValue is the enum to capture the four types of actions to perform on the context
type ActionType string
const (
// INSERT inserts the new header if it does not exist
INSERT ActionType = "insert"
// UPDATE updates the header value if it exists
UPDATE ActionType = "update"
// UPSERT inserts a header if it does not exist and updates the header if it exists
UPSERT ActionType = "upsert"
// DELETE deletes the header
DELETE ActionType = "delete"
)
type ActionConfig struct {
Key *string `mapstructure:"key"`
Action ActionType `mapstructure:"action"`
ValueDefault *string `mapstructure:"value"`
FromAttribute *string `mapstructure:"from_attribute"`
}
// Validate checks if the extension configuration is valid
func (cfg *Config) Validate() error {
if cfg.ActionsConfig == nil || len(cfg.ActionsConfig) == 0 {
return errMissingActionConfig
}
for _, action := range cfg.ActionsConfig {
if action.Key == nil || *action.Key == "" {
return errMissingActionConfigKey
}
if action.Action != DELETE {
if action.FromAttribute == nil && action.ValueDefault == nil {
return errMissingActionConfigSource
}
} else {
if action.FromAttribute != nil || action.ValueDefault != nil {
return errMissingActionDeleteParams
}
}
}
return nil
}