| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package 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 |
|
| 37 |
type Config map[pipeline.ID]*PipelineConfig |
| 38 |
|
| 39 |
func (cfg Config) Validate() error { |
| 40 |
|
| 41 |
if !AllowNoPipelines.IsEnabled() && len(cfg) == 0 { |
| 42 |
return errMissingServicePipelines |
| 43 |
} |
| 44 |
|
| 45 |
if !serviceProfileSupportGate.IsEnabled() { |
| 46 |
|
| 47 |
|
| 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 |
|
| 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 |
|
| 71 |
if len(cfg.Receivers) == 0 { |
| 72 |
return errMissingServicePipelineReceivers |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
if len(cfg.Exporters) == 0 { |
| 77 |
return errMissingServicePipelineExporters |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
procSet := make(map[component.ID]struct{}, len(cfg.Processors)) |
| 82 |
for _, ref := range cfg.Processors { |
| 83 |
|
| 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 |
} |