Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] [processor/k8sattributes] Add a extract::metadata warning #23146

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions processor/k8sattributesprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,20 @@ func createKubernetesProcessor(
options ...option,
) (*kubernetesprocessor, error) {
kp := &kubernetesprocessor{logger: params.Logger}
pCfg := cfg.(*Config)

err := errWrongKeyConfig(cfg)
err := errWrongKeyConfig(pCfg)
if err != nil {
return nil, err
}

allOptions := append(createProcessorOpts(cfg), options...)
if len(pCfg.Extract.Metadata) == 0 {
kp.logger.Warn("Default metadata extraction rules will be changed in future releases, " +
"please specify the extraction rules explicitly in the `processors::k8sattributes::extract::metadata` field. " +
"See https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/23136 for more details.")
}

allOptions := append(createProcessorOpts(pCfg), options...)

for _, opt := range allOptions {
if err := opt(kp); err != nil {
Expand All @@ -166,40 +173,36 @@ func createKubernetesProcessor(
return kp, nil
}

func createProcessorOpts(cfg component.Config) []option {
oCfg := cfg.(*Config)
func createProcessorOpts(cfg *Config) []option {
var opts []option
if oCfg.Passthrough {
if cfg.Passthrough {
opts = append(opts, withPassthrough())
}

// extraction rules
opts = append(opts, withExtractMetadata(oCfg.Extract.Metadata...))
opts = append(opts, withExtractLabels(oCfg.Extract.Labels...))
opts = append(opts, withExtractAnnotations(oCfg.Extract.Annotations...))
opts = append(opts, withExtractMetadata(cfg.Extract.Metadata...))
opts = append(opts, withExtractLabels(cfg.Extract.Labels...))
opts = append(opts, withExtractAnnotations(cfg.Extract.Annotations...))

// filters
opts = append(opts, withFilterNode(oCfg.Filter.Node, oCfg.Filter.NodeFromEnvVar))
opts = append(opts, withFilterNamespace(oCfg.Filter.Namespace))
opts = append(opts, withFilterLabels(oCfg.Filter.Labels...))
opts = append(opts, withFilterFields(oCfg.Filter.Fields...))
opts = append(opts, withAPIConfig(oCfg.APIConfig))
opts = append(opts, withFilterNode(cfg.Filter.Node, cfg.Filter.NodeFromEnvVar))
opts = append(opts, withFilterNamespace(cfg.Filter.Namespace))
opts = append(opts, withFilterLabels(cfg.Filter.Labels...))
opts = append(opts, withFilterFields(cfg.Filter.Fields...))
opts = append(opts, withAPIConfig(cfg.APIConfig))

opts = append(opts, withExtractPodAssociations(oCfg.Association...))
opts = append(opts, withExtractPodAssociations(cfg.Association...))

opts = append(opts, withExcludes(oCfg.Exclude))
opts = append(opts, withExcludes(cfg.Exclude))

return opts
}

func errWrongKeyConfig(cfg component.Config) error {
oCfg := cfg.(*Config)

for _, r := range append(oCfg.Extract.Labels, oCfg.Extract.Annotations...) {
func errWrongKeyConfig(cfg *Config) error {
for _, r := range append(cfg.Extract.Labels, cfg.Extract.Annotations...) {
if r.Key != "" && r.KeyRegex != "" {
return fmt.Errorf("Out of Key or KeyRegex only one option is expected to be configured at a time, currently Key:%s and KeyRegex:%s", r.Key, r.KeyRegex)
}
}

return nil
}