Debian Codegraph @

service/pipelines/config.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package pipelines // import "go.opentelemetry.io/collector/service/pipelines"
5
6 import (
7 "errors"
8 "fmt"
9
10 "go.opentelemetry.io/collector/component"
11 "go.opentelemetry.io/collector/featuregate"
12 "go.opentelemetry.io/collector/pipeline"
13 "go.opentelemetry.io/collector/pipeline/xpipeline"
14 )
15
16 var (
17 errMissingServicePipelines = errors.New("service must have at least one pipeline")
18 errMissingServicePipelineReceivers = errors.New("must have at least one receiver")
19 errMissingServicePipelineExporters = errors.New("must have at least one exporter")
20
21 serviceProfileSupportGateID = "service.profilesSupport"
22 serviceProfileSupportGate = featuregate.GlobalRegistry().MustRegister(
23 serviceProfileSupportGateID,
24 featuregate.StageAlpha,
25 featuregate.WithRegisterFromVersion("v0.112.0"),
26 featuregate.WithRegisterDescription("Controls whether profiles support can be enabled"),
27 )
28 AllowNoPipelines = featuregate.GlobalRegistry().MustRegister(
29 "service.AllowNoPipelines",
30 featuregate.StageAlpha,
31 featuregate.WithRegisterFromVersion("v0.122.0"),
32 featuregate.WithRegisterDescription("Allow starting the Collector without starting any pipelines."),
33 )
34 )
35
36 // Config defines the configurable settings for service telemetry.
37 type Config map[pipeline.ID]*PipelineConfig
38
39 func (cfg Config) Validate() error {
40 // Must have at least one pipeline unless explicitly disabled.
41 if !AllowNoPipelines.IsEnabled() && len(cfg) == 0 {
42 return errMissingServicePipelines
43 }
44
45 if !serviceProfileSupportGate.IsEnabled() {
46 // Check that all pipelines have at least one receiver and one exporter, and they reference
47 // only configured components.
48 for pipelineID := range cfg {
49 if pipelineID.Signal() == xpipeline.SignalProfiles {
50 return fmt.Errorf(
51 "pipeline %q: profiling signal support is at alpha level, gated under the %q feature gate",
52 pipelineID.String(),
53 serviceProfileSupportGateID,
54 )
55 }
56 }
57 }
58
59 return nil
60 }
61
62 // PipelineConfig defines the configuration of a Pipeline.
63 type PipelineConfig struct {
64 Receivers []component.ID `mapstructure:"receivers"`
65 Processors []component.ID `mapstructure:"processors"`
66 Exporters []component.ID `mapstructure:"exporters"`
67 }
68
69 func (cfg *PipelineConfig) Validate() error {
70 // Validate pipeline has at least one receiver.
71 if len(cfg.Receivers) == 0 {
72 return errMissingServicePipelineReceivers
73 }
74
75 // Validate pipeline has at least one exporter.
76 if len(cfg.Exporters) == 0 {
77 return errMissingServicePipelineExporters
78 }
79
80 // Validate no processors are duplicated within a pipeline.
81 procSet := make(map[component.ID]struct{}, len(cfg.Processors))
82 for _, ref := range cfg.Processors {
83 // Ensure no processors are duplicated within the pipeline
84 if _, exists := procSet[ref]; exists {
85 return fmt.Errorf("references processor %q multiple times", ref)
86 }
87 procSet[ref] = struct{}{}
88 }
89
90 return nil
91 }