From 831e70e824f08c4e411f3497ef8ba022d340500c Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Tue, 26 Sep 2023 09:39:31 +0800 Subject: [PATCH 1/4] [processor/k8sattributes] allow metadata extractions to be null Signed-off-by: Ziqi Zhao --- .../k8sattribute-processor-null-metadata.yaml | 27 +++++++++++++++++++ processor/k8sattributesprocessor/options.go | 3 +++ 2 files changed, 30 insertions(+) create mode 100755 .chloggen/k8sattribute-processor-null-metadata.yaml diff --git a/.chloggen/k8sattribute-processor-null-metadata.yaml b/.chloggen/k8sattribute-processor-null-metadata.yaml new file mode 100755 index 000000000000..e443bf9731f7 --- /dev/null +++ b/.chloggen/k8sattribute-processor-null-metadata.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: processor/k8sattributes + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: allow metadata extractions to be null + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [14452] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/processor/k8sattributesprocessor/options.go b/processor/k8sattributesprocessor/options.go index 59f0cddfe35c..6acb6230c374 100644 --- a/processor/k8sattributesprocessor/options.go +++ b/processor/k8sattributesprocessor/options.go @@ -125,6 +125,9 @@ func enabledAttributes() (attributes []string) { // If no fields explicitly provided, the defaults are pulled from metadata.yaml. func withExtractMetadata(fields ...string) option { return func(p *kubernetesprocessor) error { + if fields == nil { + return nil + } if len(fields) == 0 { fields = enabledAttributes() } From b723a725ef41496a91f4ae82a8335053ccdee767 Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Tue, 26 Sep 2023 13:19:37 +0800 Subject: [PATCH 2/4] fix for comments Signed-off-by: Ziqi Zhao --- processor/k8sattributesprocessor/factory.go | 3 +++ processor/k8sattributesprocessor/options.go | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/processor/k8sattributesprocessor/factory.go b/processor/k8sattributesprocessor/factory.go index 9309d437c879..2786851c7c8c 100644 --- a/processor/k8sattributesprocessor/factory.go +++ b/processor/k8sattributesprocessor/factory.go @@ -35,6 +35,9 @@ func createDefaultConfig() component.Config { return &Config{ APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeServiceAccount}, Exclude: defaultExcludes, + Extract: ExtractConfig{ + Metadata: enabledAttributes(), + }, } } diff --git a/processor/k8sattributesprocessor/options.go b/processor/k8sattributesprocessor/options.go index 6acb6230c374..0a9b00a4512e 100644 --- a/processor/k8sattributesprocessor/options.go +++ b/processor/k8sattributesprocessor/options.go @@ -125,12 +125,6 @@ func enabledAttributes() (attributes []string) { // If no fields explicitly provided, the defaults are pulled from metadata.yaml. func withExtractMetadata(fields ...string) option { return func(p *kubernetesprocessor) error { - if fields == nil { - return nil - } - if len(fields) == 0 { - fields = enabledAttributes() - } for _, field := range fields { switch field { case conventions.AttributeK8SNamespaceName: From 6ec878a5a96d81b03583324a4398cae7f06e9d6d Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Tue, 26 Sep 2023 13:42:50 +0800 Subject: [PATCH 3/4] fix failed test Signed-off-by: Ziqi Zhao --- processor/k8sattributesprocessor/config_test.go | 4 ++++ processor/k8sattributesprocessor/options_test.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/processor/k8sattributesprocessor/config_test.go b/processor/k8sattributesprocessor/config_test.go index 71b6a3a8c852..9ec78ede8856 100644 --- a/processor/k8sattributesprocessor/config_test.go +++ b/processor/k8sattributesprocessor/config_test.go @@ -29,6 +29,9 @@ func TestLoadConfig(t *testing.T) { expected: &Config{ APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeServiceAccount}, Exclude: ExcludeConfig{Pods: []ExcludePodConfig{{Name: "jaeger-agent"}, {Name: "jaeger-collector"}}}, + Extract: ExtractConfig{ + Metadata: enabledAttributes(), + }, }, }, { @@ -114,6 +117,7 @@ func TestLoadConfig(t *testing.T) { Labels: []FieldExtractConfig{ {KeyRegex: "opentel.*", From: kube.MetadataFromPod}, }, + Metadata: enabledAttributes(), }, Exclude: ExcludeConfig{ Pods: []ExcludePodConfig{ diff --git a/processor/k8sattributesprocessor/options_test.go b/processor/k8sattributesprocessor/options_test.go index 2003f27ce2a8..40460bb738e9 100644 --- a/processor/k8sattributesprocessor/options_test.go +++ b/processor/k8sattributesprocessor/options_test.go @@ -284,7 +284,7 @@ func TestWithExtractLabels(t *testing.T) { func TestWithExtractMetadata(t *testing.T) { p := &kubernetesprocessor{} - assert.NoError(t, withExtractMetadata()(p)) + assert.NoError(t, withExtractMetadata(enabledAttributes()...)(p)) assert.True(t, p.rules.Namespace) assert.True(t, p.rules.PodName) assert.True(t, p.rules.PodUID) From 48d8b59aee92c84922c11f82064f659f8efb838c Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Tue, 26 Sep 2023 13:50:05 +0800 Subject: [PATCH 4/4] Update .chloggen/k8sattribute-processor-null-metadata.yaml Co-authored-by: Dmitrii Anoshin --- .chloggen/k8sattribute-processor-null-metadata.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/k8sattribute-processor-null-metadata.yaml b/.chloggen/k8sattribute-processor-null-metadata.yaml index e443bf9731f7..06b51f5f9fb3 100755 --- a/.chloggen/k8sattribute-processor-null-metadata.yaml +++ b/.chloggen/k8sattribute-processor-null-metadata.yaml @@ -7,7 +7,7 @@ change_type: enhancement component: processor/k8sattributes # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: allow metadata extractions to be null +note: allow metadata extractions to be set to empty list # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. issues: [14452]