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

Add support for processors in hints based k8s autodiscover #3107

Merged
merged 19 commits into from
Sep 1, 2023

Conversation

gizas
Copy link
Contributor

@gizas gizas commented Jul 20, 2023

  • Enhancement

What does this PR do?

This PR adds the support of processors autodiscovery based on hints annotations that are provided from kubernetes pods

Why is it important?

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

Author's Checklist

How to test this PR locally

  1. Install a local kubernetes cluster
  2. Build Elastic stack: elastic-package stack up -d -vvv --version=8.9.0-SNAPSHOT
  3. Connect network of kind and ELK: docker network connect elastic-package-stack_default kind-control-plane
  4. Download Pr code
  5. Build agent image with DEV=true EXTERNAL=true SNAPSHOT=true PLATFORMS=linux/arm64 PACKAGES=docker mage -v package
  6. Create docker image to load to your kind cluster
cd build/package/elastic-agent/elastic-agent-linux-arm64.docker/docker-build
docker build --platform linux/amd64 -t custom-agent-image .
  1. kind load docker-image custom-agent-image:latest --name kind
  2. Load the needed container.yml template in inputs.d folder of agent (Mount the /etc/elastic-agent/inputs.d/container_logs.yml template of https://github.com/elastic/elastic-agent/blob/main/deploy/kubernetes/elastic-agent-standalone/templates.d/container_logs.yml)
docker cp container_logs.yml  kind-control-plane:/var/log/test
  1. Install elastic-agent-standalone
    Sample provided:
    elastic-agent.txt

  2. Install ngin-x pod:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx
  namespace: default
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
      annotations:
        co.elastic.hints/package: "container_logs"
        co.elastic.hints/processors.1.add_fields.target: "project"
        co.elastic.hints/processors.1.add_fields.fields.name: "myproject"
        co.elastic.hints/processors.rename.fields.0.from: "a.g"
        co.elastic.hints/processors.rename.fields.1.to: "e.d"
        co.elastic.hints/processors.rename.fail_on_error: 'false'  
    spec:
      containers:
      - image: nginx
        name: nginx

Then if agent is up and running connect to Elastic-Agent and run inspect command. You should be able to see the new processors added

❯ kubectl exec -ti -n kube-system elastic-agent-7fnbl -- bash
root@kind-control-plane:/usr/share/elastic-agent# elastic-agent inspect -v --variables --variables-wait 2s

[output truncated ...]
- add_fields:
      fields:
        name: myproject
      target: project
  - rename:
      fail_on_error: "false"
      fields:
        "0":
          from: a.g
        "1":
          to: e.d

Related issues

Screenshots

Map populated correctly based on hints/processors provided

Screenshot 2023-07-20 at 2 39 54 PM

@gizas gizas requested a review from a team as a code owner July 20, 2023 15:33
@gizas gizas requested review from michalpristas, blakerouse, a team, ChrsMark and constanca-m and removed request for a team July 20, 2023 15:33
@mergify
Copy link
Contributor

mergify bot commented Jul 20, 2023

This pull request does not have a backport label. Could you fix it @gizas? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@elasticmachine
Copy link
Contributor

elasticmachine commented Jul 20, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-09-01T09:33:11.322+0000

  • Duration: 26 min 1 sec

Test stats 🧪

Test Results
Failed 0
Passed 6237
Skipped 55
Total 6292

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages.

  • run integration tests : Run the Elastic Agent Integration tests.

  • run end-to-end tests : Generate the packages and run the E2E Tests.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

Copy link
Member

@ChrsMark ChrsMark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks quite good!

I have left a minor comment about the code organisation.
Please add some unit tests and remember to update the respective dev+user docs.

internal/pkg/composable/providers/kubernetes/pod.go Outdated Show resolved Hide resolved
internal/pkg/composable/providers/kubernetes/pod.go Outdated Show resolved Hide resolved
@elasticmachine
Copy link
Contributor

elasticmachine commented Jul 31, 2023

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 98.765% (80/81) 👍
Files 67.368% (192/285) 👍
Classes 66.105% (353/534) 👍
Methods 53.04% (1108/2089) 👍 0.022
Lines 38.635% (12653/32750) 👍 0.016
Conditionals 100.0% (0/0) 💚

Copy link
Member

@ChrsMark ChrsMark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @gizas , thanks for addressing the comments.
I left some minor comments but it's getting there.

@ChrsMark ChrsMark changed the title Processorhints enhancement Add support for processors in hints based k8s autodiscover Aug 16, 2023
Copy link
Member

@ChrsMark ChrsMark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 lgtm, great to see this landed! 🚀 🚀 🚀


hintData := GetHintsMapping(mapping, logger, "co.elastic", "asdfghjkl")

assert.Equal(t, expected_hints, hintData.composableMapping)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽

internal/pkg/composable/providers/kubernetes/pod.go Outdated Show resolved Hide resolved
@gizas
Copy link
Contributor Author

gizas commented Aug 17, 2023

@elastic/elastic-agent-control-plane I need one review from yourside as well in order to merge. Can you please have a look?

@ChrsMark
Copy link
Member

I guess we should also update the code ownership here as well @cmacknz , right?

@michalpristas
Copy link
Contributor

michalpristas commented Aug 22, 2023

flakyness in a way how maps are used/compared. keys are not sorted.

@gizas
Copy link
Contributor Author

gizas commented Aug 22, 2023

flakyness in a way how maps are used/compared. keys are not sorted.

Fixing this with 21d095b

@gizas
Copy link
Contributor Author

gizas commented Aug 23, 2023

/test

@gizas
Copy link
Contributor Author

gizas commented Aug 24, 2023

/test

@gizas
Copy link
Contributor Author

gizas commented Sep 1, 2023

/test

@pierrehilbert
Copy link
Contributor

Unrelated failures. I force merge.

@pierrehilbert pierrehilbert merged commit 9bf74e4 into main Sep 1, 2023
@pierrehilbert pierrehilbert deleted the processorhints_enhancement branch September 1, 2023 12:02
@gizas gizas mentioned this pull request Sep 14, 2023
7 tasks
cmacknz pushed a commit to cmacknz/elastic-agent that referenced this pull request Sep 25, 2023
)

* adding processors block

* Updating code with last eg that retrievs processors

* Updating code with processors with reference form utils

* fixing initialisation of variable

* Update internal/pkg/composable/providers/kubernetes/pod.go

Co-authored-by: Chris Mark <[email protected]>

* Update internal/pkg/composable/providers/kubernetes/pod.go

Co-authored-by: Chris Mark <[email protected]>

* adding unit test and fixing struct

* fixing initialisation of struct

* adding function updateprocessors also to default_containers

* adding fragment file

* Update changelog/fragments/1691060806-Processor-support-for-hints-autodiscover.yaml

Co-authored-by: Chris Mark <[email protected]>

* Updating variable names and fixing test to call public GetHintsMapping

* Update internal/pkg/composable/providers/kubernetes/pod.go

Co-authored-by: Chris Mark <[email protected]>

* Updating tests

* Updating tests

* Updating tests to avoid sorting of mappings

---------

Co-authored-by: Chris Mark <[email protected]>
@bartoszcisek
Copy link

Would this be released in 8.10.3? Is there an ETA for 8.10.3?

@gizas
Copy link
Contributor Author

gizas commented Oct 3, 2023

Would this be released in 8.10.3? Is there an ETA for 8.10.3?

If there is no delay, next week will be the release of both 8.10.3 and 8.11.0. Either way I will notify you in which version this is in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants