| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package pipelines |
| 5 |
|
| 6 |
import ( |
| 7 |
"errors" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/stretchr/testify/require" |
| 11 |
|
| 12 |
"go.opentelemetry.io/collector/component" |
| 13 |
"go.opentelemetry.io/collector/confmap/xconfmap" |
| 14 |
"go.opentelemetry.io/collector/featuregate" |
| 15 |
"go.opentelemetry.io/collector/pipeline" |
| 16 |
"go.opentelemetry.io/collector/pipeline/xpipeline" |
| 17 |
) |
| 18 |
|
| 19 |
func TestConfigValidate(t *testing.T) { |
| 20 |
testCases := []struct { |
| 21 |
name string |
| 22 |
cfgFn func(*testing.T) Config |
| 23 |
expected error |
| 24 |
}{ |
| 25 |
{ |
| 26 |
name: "valid", |
| 27 |
cfgFn: generateConfig, |
| 28 |
expected: nil, |
| 29 |
}, |
| 30 |
{ |
| 31 |
name: "duplicate-processor-reference", |
| 32 |
cfgFn: func(*testing.T) Config { |
| 33 |
cfg := generateConfig(t) |
| 34 |
pipe := cfg[pipeline.NewID(pipeline.SignalTraces)] |
| 35 |
pipe.Processors = append(pipe.Processors, pipe.Processors...) |
| 36 |
return cfg |
| 37 |
}, |
| 38 |
expected: errors.New(`references processor "nop" multiple times`), |
| 39 |
}, |
| 40 |
{ |
| 41 |
name: "missing-pipeline-receivers", |
| 42 |
cfgFn: func(*testing.T) Config { |
| 43 |
cfg := generateConfig(t) |
| 44 |
cfg[pipeline.NewID(pipeline.SignalTraces)].Receivers = nil |
| 45 |
return cfg |
| 46 |
}, |
| 47 |
expected: errMissingServicePipelineReceivers, |
| 48 |
}, |
| 49 |
{ |
| 50 |
name: "missing-pipeline-exporters", |
| 51 |
cfgFn: func(*testing.T) Config { |
| 52 |
cfg := generateConfig(t) |
| 53 |
cfg[pipeline.NewID(pipeline.SignalTraces)].Exporters = nil |
| 54 |
return cfg |
| 55 |
}, |
| 56 |
expected: errMissingServicePipelineExporters, |
| 57 |
}, |
| 58 |
{ |
| 59 |
name: "missing-pipelines", |
| 60 |
cfgFn: func(*testing.T) Config { |
| 61 |
return nil |
| 62 |
}, |
| 63 |
expected: errMissingServicePipelines, |
| 64 |
}, |
| 65 |
{ |
| 66 |
name: "disabled-featuregate-profiles", |
| 67 |
cfgFn: func(*testing.T) Config { |
| 68 |
cfg := generateConfig(t) |
| 69 |
cfg[pipeline.NewID(xpipeline.SignalProfiles)] = &PipelineConfig{ |
| 70 |
Receivers: []component.ID{component.MustNewID("nop")}, |
| 71 |
Processors: []component.ID{component.MustNewID("nop")}, |
| 72 |
Exporters: []component.ID{component.MustNewID("nop")}, |
| 73 |
} |
| 74 |
return cfg |
| 75 |
}, |
| 76 |
expected: errors.New(`profiling signal support is at alpha level, gated under the "service.profilesSupport" feature gate`), |
| 77 |
}, |
| 78 |
{ |
| 79 |
name: "enabled-featuregate-profiles", |
| 80 |
cfgFn: func(t *testing.T) Config { |
| 81 |
require.NoError(t, featuregate.GlobalRegistry().Set(serviceProfileSupportGateID, true)) |
| 82 |
|
| 83 |
cfg := generateConfig(t) |
| 84 |
cfg[pipeline.NewID(xpipeline.SignalProfiles)] = &PipelineConfig{ |
| 85 |
Receivers: []component.ID{component.MustNewID("nop")}, |
| 86 |
Processors: []component.ID{component.MustNewID("nop")}, |
| 87 |
Exporters: []component.ID{component.MustNewID("nop")}, |
| 88 |
} |
| 89 |
return cfg |
| 90 |
}, |
| 91 |
expected: nil, |
| 92 |
}, |
| 93 |
} |
| 94 |
|
| 95 |
for _, tt := range testCases { |
| 96 |
t.Run(tt.name, func(t *testing.T) { |
| 97 |
cfg := tt.cfgFn(t) |
| 98 |
if tt.expected != nil { |
| 99 |
require.ErrorContains(t, xconfmap.Validate(cfg), tt.expected.Error()) |
| 100 |
} else { |
| 101 |
require.NoError(t, xconfmap.Validate(cfg)) |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
require.NoError(t, featuregate.GlobalRegistry().Set(serviceProfileSupportGateID, false)) |
| 106 |
}) |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
func TestNoPipelinesFeatureGate(t *testing.T) { |
| 111 |
cfg := Config{} |
| 112 |
|
| 113 |
require.Error(t, xconfmap.Validate(cfg)) |
| 114 |
|
| 115 |
gate := AllowNoPipelines |
| 116 |
require.NoError(t, featuregate.GlobalRegistry().Set(gate.ID(), true)) |
| 117 |
defer func() { |
| 118 |
require.NoError(t, featuregate.GlobalRegistry().Set(gate.ID(), false)) |
| 119 |
}() |
| 120 |
|
| 121 |
require.NoError(t, xconfmap.Validate(cfg)) |
| 122 |
} |
| 123 |
|
| 124 |
func generateConfig(t *testing.T) Config { |
| 125 |
t.Helper() |
| 126 |
|
| 127 |
return map[pipeline.ID]*PipelineConfig{ |
| 128 |
pipeline.NewID(pipeline.SignalTraces): { |
| 129 |
Receivers: []component.ID{component.MustNewID("nop")}, |
| 130 |
Processors: []component.ID{component.MustNewID("nop")}, |
| 131 |
Exporters: []component.ID{component.MustNewID("nop")}, |
| 132 |
}, |
| 133 |
} |
| 134 |
} |