Skip to content

Commit

Permalink
[processor/k8sattributes] allow metadata extractions to be empty list (
Browse files Browse the repository at this point in the history
…#27185)

**Description:** 
Allow metadata extractions to be empty list

After this is merged, user is allow to specify the metadata to be empty list
like following

```
    processors:
      k8sattributes:
        extract:
          annotations:
          - from: pod
            key: workload
            tag_name: k8s.annotations.workload
          labels:
          - from: pod
            key: app
            tag_name: k8s.labels.app
          metadata: []
```

**Link to tracking Issue:** fix #14452 

---------

Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Co-authored-by: Dmitrii Anoshin <anoshindx@gmail.com>
  • Loading branch information
fatsheep9146 and dmitryax authored Sep 26, 2023
1 parent 39d1e53 commit 0882eee
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .chloggen/k8sattribute-processor-null-metadata.yaml
Original file line number Diff line number Diff line change
@@ -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 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]

# (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: []
4 changes: 4 additions & 0 deletions processor/k8sattributesprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
},
},
{
Expand Down Expand Up @@ -114,6 +117,7 @@ func TestLoadConfig(t *testing.T) {
Labels: []FieldExtractConfig{
{KeyRegex: "opentel.*", From: kube.MetadataFromPod},
},
Metadata: enabledAttributes(),
},
Exclude: ExcludeConfig{
Pods: []ExcludePodConfig{
Expand Down
3 changes: 3 additions & 0 deletions processor/k8sattributesprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func createDefaultConfig() component.Config {
return &Config{
APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeServiceAccount},
Exclude: defaultExcludes,
Extract: ExtractConfig{
Metadata: enabledAttributes(),
},
}
}

Expand Down
3 changes: 0 additions & 3 deletions processor/k8sattributesprocessor/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +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 len(fields) == 0 {
fields = enabledAttributes()
}
for _, field := range fields {
switch field {
case conventions.AttributeK8SNamespaceName:
Expand Down
2 changes: 1 addition & 1 deletion processor/k8sattributesprocessor/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0882eee

Please sign in to comment.