Skip to content

Commit

Permalink
fix(k8sprocessor): reading exclude config
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Dec 16, 2021
1 parent 1ea113a commit a27f74f
Showing 4 changed files with 48 additions and 34 deletions.
48 changes: 30 additions & 18 deletions pkg/processor/k8sprocessor/config_test.go
Original file line number Diff line number Diff line change
@@ -32,34 +32,47 @@ func TestLoadConfig(t *testing.T) {
require.NoError(t, err)
factory := NewFactory()
factories.Processors[config.Type(typeStr)] = factory
require.NoError(t, err)

require.NoError(t, factory.CreateDefaultConfig().Validate())

cfg, err := configtest.LoadConfig(
path.Join(".", "testdata", "config.yaml"),
factories)

require.Nil(t, err)
factories,
)
require.NoError(t, err)
require.NotNil(t, cfg)
require.NoError(t, cfg.Validate())

p0 := cfg.Processors[config.NewComponentID(typeStr)]
assert.Equal(t, p0,
assert.EqualValues(t,
&Config{
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeServiceAccount},
Exclude: ExcludeConfig{Pods: []ExcludePodConfig{
{Name: "jaeger-agent"},
{Name: "jaeger-collector"},
{Name: "otel-collector"},
{Name: "otel-agent"},
{Name: "collection-sumologic-otelcol"},
}},
Exclude: ExcludeConfig{
Pods: nil,
// NOTE: this will not work as expected because k8sprocessor uses
// options pattern passing only the "changed as we go" config, so
// setting a default would override the passed around config and then
// the config would get overwritten second time with options.
// Becasuse of that we don't set exclude by default but we rely on
// options to set it, i.e. via WithExcludes (which would also set
// the default values if nothing was set.)
//
// []ExcludePodConfig{
// {Name: "jaeger-agent"},
// {Name: "jaeger-collector"},
// {Name: "otel-collector"},
// {Name: "otel-agent"},
// {Name: "collection-sumologic-otelcol"},
// },
},
Extract: ExtractConfig{Delimiter: ", "},
})
},
p0,
)

p1 := cfg.Processors[config.NewComponentIDWithName(typeStr, "2")]
assert.Equal(t, p1,
assert.EqualValues(t,
&Config{
ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName(typeStr, "2")),
APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeKubeConfig},
@@ -130,10 +143,9 @@ func TestLoadConfig(t *testing.T) {
Pods: []ExcludePodConfig{
{Name: "jaeger-agent"},
{Name: "jaeger-collector"},
{Name: "otel-collector"},
{Name: "otel-agent"},
{Name: "collection-sumologic-otelcol"},
},
},
})
},
p1,
)
}
10 changes: 0 additions & 10 deletions pkg/processor/k8sprocessor/factory.go
Original file line number Diff line number Diff line change
@@ -33,15 +33,6 @@ const (

var kubeClientProvider = kube.ClientProvider(nil)
var processorCapabilities = consumer.Capabilities{MutatesData: true}
var defaultExcludes = ExcludeConfig{
Pods: []ExcludePodConfig{
{Name: "jaeger-agent"},
{Name: "jaeger-collector"},
{Name: "otel-collector"},
{Name: "otel-agent"},
{Name: "collection-sumologic-otelcol"},
},
}

// NewFactory returns a new factory for the k8s processor.
func NewFactory() component.ProcessorFactory {
@@ -61,7 +52,6 @@ func createDefaultConfig() config.Processor {
Extract: ExtractConfig{
Delimiter: DefaultDelimiter,
},
Exclude: defaultExcludes,
}
}

22 changes: 17 additions & 5 deletions pkg/processor/k8sprocessor/options.go
Original file line number Diff line number Diff line change
@@ -366,21 +366,33 @@ func WithDelimiter(delimiter string) Option {
}
}

var defaultExcludes = ExcludeConfig{
Pods: []ExcludePodConfig{
{Name: "jaeger-agent"},
{Name: "jaeger-collector"},
{Name: "otel-collector"},
{Name: "otel-agent"},
{Name: "collection-sumologic-otelcol"},
},
}

// WithExcludes allows specifying pods to exclude
func WithExcludes(podExclude ExcludeConfig) Option {
func WithExcludes(excludeConfig ExcludeConfig) Option {
return func(p *kubernetesprocessor) error {
ignoredNames := kube.Excludes{}
names := podExclude.Pods
excludes := kube.Excludes{}
names := excludeConfig.Pods

if len(names) == 0 {
names = defaultExcludes.Pods
}

for _, name := range names {
ignoredNames.Pods = append(ignoredNames.Pods, kube.ExcludePods{
excludes.Pods = append(excludes.Pods, kube.ExcludePods{
Name: regexp.MustCompile(name.Name)},
)
}
p.podIgnore = ignoredNames

p.podIgnore = excludes
return nil
}
}
2 changes: 1 addition & 1 deletion pkg/processor/k8sprocessor/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -84,5 +84,5 @@ service:
pipelines:
traces:
receivers: [nop]
processors: [k8s_tagger]
processors: [k8s_tagger, k8s_tagger/2]
exporters: [nop]

0 comments on commit a27f74f

Please sign in to comment.