forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
78 lines (64 loc) · 2.8 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
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package routingconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector"
import (
"errors"
"go.opentelemetry.io/collector/component"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
)
var (
errEmptyRoute = errors.New("invalid route: no statement provided")
errNoPipelines = errors.New("invalid route: no pipelines defined")
errUnexpectedConsumer = errors.New("expected consumer to be a connector router")
errNoTableItems = errors.New("invalid routing table: the routing table is empty")
)
// Config defines configuration for the Routing processor.
type Config struct {
// DefaultPipelines contains the list of pipelines to use when a more specific record can't be
// found in the routing table.
// Optional.
DefaultPipelines []component.ID `mapstructure:"default_pipelines"`
// ErrorMode determines how the processor reacts to errors that occur while processing an OTTL
// condition.
// Valid values are `ignore` and `propagate`.
// `ignore` means the processor ignores errors returned by conditions and continues on to the
// next condition. This is the recommended mode. If `ignored` is used and a statement's
// condition has an error then the payload will be routed to the default exporter. `propagate`
// means the processor returns the error up the pipeline. This will result in the payload being
// dropped from the collector.
// The default value is `propagate`.
ErrorMode ottl.ErrorMode `mapstructure:"error_mode"`
// Table contains the routing table for this processor.
// Required.
Table []RoutingTableItem `mapstructure:"table"`
}
// Validate checks if the processor configuration is valid.
func (c *Config) Validate() error {
// validate that there's at least one item in the table
if len(c.Table) == 0 {
return errNoTableItems
}
// validate that every route has a value for the routing attribute and has
// at least one pipeline
for _, item := range c.Table {
if len(item.Statement) == 0 {
return errEmptyRoute
}
if len(item.Pipelines) == 0 {
return errNoPipelines
}
}
return nil
}
// RoutingTableItem specifies how data should be routed to the different pipelines
type RoutingTableItem struct {
// Statement is a OTTL statement used for making a routing decision.
// Required when 'Value' isn't provided.
Statement string `mapstructure:"statement"`
// Pipelines contains the list of pipelines to use when the value from the FromAttribute field
// matches this table item. When no pipelines are specified, the ones specified under
// DefaultPipelines are used, if any.
// The routing processor will fail upon the first failure from these pipelines.
// Optional.
Pipelines []component.ID `mapstructure:"pipelines"`
}