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

Include_labels option in add_resource_metadata not working as expected #3636

Closed
gizas opened this issue Oct 19, 2023 · 6 comments
Closed

Include_labels option in add_resource_metadata not working as expected #3636

gizas opened this issue Oct 19, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@gizas
Copy link
Contributor

gizas commented Oct 19, 2023

Description:
According to documentation users can configure include_labels option to specify and filter the labels being ingested.

The include_labels option can be configured under namespace and node resources, implying that users can configure seperately the labels they want per kind of resource

See eg.

add_resource_metadata:
        namespace:
          include_labels: ["namespacelabel1"]
          #labels.dedot: true
          #annotations.dedot: true
        node:
          include_labels: ["nodelabel2"]
         ....

But the configuration of include_labels under namespace leads to node labels being lost.
All versions of 8.10.2 and above have been verified that showcase above functionality.

Details:

  • Version of Elastic Agent: 8.10.2
  • Version of elastic-agent-autodiscover: v0.6.2[https://github.com/elastic/elastic-agent/blob/1320210da633a0e00da6f5301fcc39c6de29bca8/go.mod#L16]

Steps to reproduce:

  1. Install Elastic Stack 8.10.2
  2. Install a Kubernetes Integration Policy with Kube-state-metrics datastreams enabled
  3. Add a label to your namespace:
kubectl label namespace kube-system katsoulis=pasole

kubectl  describe namespace kube-system
Name:         kube-system
Labels:       katsoulis=pasole
              kubernetes-1=pasole
              kubernetes.io/metadata.name=kube-system
  1. With the default configuration you will notice that all namespace and node labels are being collected
    all_labels

  2. Edit the advanced options of state_pod dataset inside your Kubernetes Integration Policy
    add_resource

  3. You will notice that include_labels condition applies to both nodes and namespace metadata, resulting to node labels being lost
    filter

@gizas gizas added the bug Something isn't working label Oct 19, 2023
@gizas
Copy link
Contributor Author

gizas commented Oct 19, 2023

cc @bturquet for prioritisation

@tetianakravchenko
Copy link
Contributor

tetianakravchenko commented Nov 29, 2023

some findings:
I've tested it with simple metricbeat configuration - only 1 metricset (pod), such as:

    - module: kubernetes
      add_metadata: true
      add_resource_metadata:
        namespace:
          include_labels: ["labelName"]
      metricsets:
        - pod
....

Already after the config unpacking - UnpackConfig the configuration is wrong - Node part contains the include_labels (Namespace as well):
Screenshot 2023-11-23 at 17 27 15

If add the same label to the node kubectl label node test-control-plane labelName=labelValue - kubernetes.node.labels.labelName will be added.

UnpackConfig calls the Unpack on the rawConfig - which is correct, then is called Unpack from the go-ucfg lib

This issue exists starting from the 17.17.7 (the version it was backported to - relevant PR). Seems that elastic/beats#29133 was not working as expected at least for the k8s module, will check it also for the add_kubernetes_metadata processor and the kubernetes provider

@tetianakravchenko
Copy link
Contributor

tetianakravchenko commented Dec 4, 2023

configuration add_resource_metadata

  1. k8s module - from the time it was introduced this was never working as expected.
  2. add_kubernetes_metadata processor.
    tested filebeat with:
processors:
        - add_kubernetes_metadata:
            add_resource_metadata:
              namespace:
                include_labels: ["labelName"]
            host: ${NODE_NAME}
            matchers:
            - logs_path:
                logs_path: "/var/log/containers/"

In https://github.com/elastic/beats/pull/29133/files was removed ..., in https://github.com/elastic/beats/pull/29329/files AddResourceMetadata was added to the default config.

So before the changes above, configuration contained only the values defined in the customer config, default values are not defined:
Screenshot 2023-12-04 at 22 01 37

I've also tested the version 7.17.6 - defining add_resource_metadata leads to the full overwrite of the default value (hence the node labels are missing). so what is the expected behavior - merge or replace?

After the changes above - default values are initialized
Screenshot 2023-12-04 at 22 56 51

and merged during the unpacking in https://github.com/elastic/go-ucfg/blob/main/reify.go#L434

Seems there is some issue during the merging.
I think the right approach would be to check the merge issue, or other option - use the replace merge strategie.

Update: replace merge strategie does not lead to the replacement: include_labels will be duplicated in both node and namespace

  1. autodiscover - TODO

@tetianakravchenko
Copy link
Contributor

tetianakravchenko commented Dec 19, 2023

related PRs:

add_resource_metadata processor does not work for metricbeat

  • delete add_kubernetes_metadata processor from documentation - it never worked as expected(?), recommended way - to use enricher

tetianakravchenko added a commit to elastic/elastic-agent-autodiscover that referenced this issue Dec 20, 2023
fix default metadata config: ensure that AddResourceMetadataConfig.Node
and AddResourceMetadataConfig.Namespace are different objects

Relates elastic/elastic-agent#3636

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
@tetianakravchenko
Copy link
Contributor

tetianakravchenko commented Dec 20, 2023

@gizas FYI: I've tested locally #3938:

  1. pod datastream add_resource_metadata config:
Screenshot 2023-12-20 at 17 04 59 Screenshot 2023-12-20 at 17 12 10
  1. state_pod datastream add_resource_metadata config:
Screenshot 2023-12-20 at 17 04 38 Screenshot 2023-12-20 at 17 11 43

@tetianakravchenko
Copy link
Contributor

tetianakravchenko commented Jan 16, 2024

Another issue:

  • provider.kubernetes for elastic-agenthas still the same issue

Update: no issues there, see comment #3346 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants