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

[Kubernetes Provider] Allow wildcards or regex when specifying "include_labels" and "include_annotations" #3346

Closed
gizas opened this issue Sep 4, 2023 · 6 comments · Fixed by elastic/ingest-docs#834
Assignees
Labels
enhancement New feature or request Team:Cloudnative-Monitoring Label for the Cloud Native Monitoring team

Comments

@gizas
Copy link
Contributor

gizas commented Sep 4, 2023

Describe the enhancement:

Currently the Kubernetes Provider includes the following config options: include_annotations, include_labels(and also exclude_labels) and allows users to optionally add to the provider config the list of annotations and labels present accordingly.

Those config options does not support wild cards or regex expressions to dynamically configure the wanted list of annotations or labels. This enhancement request focuses to this functionality.

Describe a specific use case for the enhancement or feature:

Lets assume the following pod specification:

apiVersion: v1
kind: Pod
metadata:
  name: demo
  labels:
    demo-1: production
    demo-2: nginx

The user would require to configure "include_labels": ["demo-1", "demo-2"] to match all labels
So the enhancement will allow "include_labels": "demo-*" to match all demo-1 and demo-2 labels of the example pod.

What is the definition of done?

Relevant Links:

@gizas gizas added Team:Cloudnative-Monitoring Label for the Cloud Native Monitoring team enhancement New feature or request labels Sep 4, 2023
@gizas
Copy link
Contributor Author

gizas commented Sep 14, 2023

Added initial effort elastic/elastic-agent-autodiscover@main...regexannotations

We will need to try testing this first effort

@gizas
Copy link
Contributor Author

gizas commented Sep 19, 2023

The PR for elastic-agent-autodiscovery library introduces the functionality.

  • We will need to merge the above PR and then run some manual tests with and updated elastic agent image.
  • Main question for @elastic/obs-cloudnative-monitoring team is whether we want to support regex expression for excluding labels (For now I have added the regex support also to exclude_labels)?
  • Documentation updates to be provided as DoD of this story

@ChrsMark
Copy link
Member

  • Main question for @elastic/obs-cloudnative-monitoring team is whether we want to support regex expression for excluding libraries?

What kind of libraries? 🤔

@gizas
Copy link
Contributor Author

gizas commented Sep 19, 2023

What kind of libraries? 🤔

:) Meant to write labels !!! Rephrased it

@gizas gizas self-assigned this Sep 19, 2023
gizas added a commit to elastic/elastic-agent-autodiscover that referenced this issue Oct 6, 2023
…todiscovery library (#60)

This PR introduces the main functionality in order to support the regex expression for kubernetes provider as described here: elastic/elastic-agent#3346
@gizas
Copy link
Contributor Author

gizas commented Oct 19, 2023

I have run the manual tests end-to-end and I can verify that by adding in state_pod

add_resource_metadata:
  namespace:
    use_regex_inlcude: true
    include_labels: ["kubernetes"]

And As you can see below we match only kubernetes* labels

Screenshot 2023-10-18 at 11 28 11 AM

But we hit the bug: #3636

So we need to fix this bug before retesting this feature further

@gizas
Copy link
Contributor Author

gizas commented Jan 15, 2024

The above #3636 has been fixed in elastic/beats#37458, all agent versions with elastic-agent-autodiscovery library >= v0.6.6

I have resumed the tests for the regex support. The functionality is there

k8-labels-regex

Draft Documentation RP: elastic/ingest-docs#814

Still I see an issue with mix regex in both namespace and node:

Config:

      add_resource_metadata:
        namespace:
          use_regex_include: true
          include_labels:
            - pas
        node:
          use_regex_include: true
          include_labels:
            - kubernetes

Output:

combinationofregex
Only namespace is honoured. I will keep searching for this

Everything tested correctly in version>= 8.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Team:Cloudnative-Monitoring Label for the Cloud Native Monitoring team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants