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 deployment name in pod's meta #23610

Merged
merged 5 commits into from
Jan 27, 2021
Merged

Conversation

ChrsMark
Copy link
Member

@ChrsMark ChrsMark commented Jan 21, 2021

What does this PR do?

This PR adds kubernetes.deployment.name in Pods' metadata. Right now we only add kubernetes.replicaset.name when a Pod is handled by a Deployment since a Deployment controls the Pod through a ReplicaSet and the ReplicaSet is considered as the direct owner of the Pod in k8s API. In this we need an extra step check to retrieve the owner of the ReplicaSet if possible.

NOTE: Since with this addition Beats will try to get replicaset objects from k8s API the following addition in the clusterrole is required:

- apiGroups: ["apps"]
  resources:
    - replicasets
  verbs: ["get", "list", "watch"]

See: #23716

Why is it important?

So as to correlate Pods with Deployments controlling them.

How to test this PR locally

  1. Deploy a sample Deployment on k8s: kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml
  2. Deploy Metricbeat (instructions) on k8s and verify that events shiped by pod and state_pod metricset include kubernetes.deployment.name when kubernetes.replicaset.name exists. As an example see screenshots below.

Extra: Verify that add_kubernetes_metadata adds kubernetes.deployment.name when kubernetes.replicaset.name exists, using the following configuration with Filebeat on k8s:

filebeat.inputs:
- type: container
  paths:
    - /var/log/containers/*.log
  processors:
    - add_kubernetes_metadata:
        host: ${NODE_NAME}
        matchers:
        - logs_path:
            logs_path: "/var/log/containers/"

Related issues

Screenshots

Screenshot 2021-01-21 at 11 29 37 AM
Screenshot 2021-01-21 at 11 06 15 AM

Signed-off-by: chrismark <chrismarkou92@gmail.com>
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jan 21, 2021
@ChrsMark ChrsMark changed the title Add deployment name ancestor of pod in meta Add deployment name in pod's meta Jan 21, 2021
@ChrsMark ChrsMark added the Team:Integrations Label for the Integrations team label Jan 21, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jan 21, 2021
@ChrsMark ChrsMark self-assigned this Jan 21, 2021
@ChrsMark ChrsMark added v7.12.0 needs_backport PR is waiting to be backported to other branches. containers Related to containers use case enhancement labels Jan 21, 2021
@elasticmachine
Copy link
Collaborator

elasticmachine commented Jan 21, 2021

💔 Build Failed

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

Expand to view the summary

Build stats

  • Build Cause: Pull request #23610 updated

    • Start Time: 2021-01-26T20:30:27.237+0000
  • Duration: 48 min 42 sec

  • Commit: 10ea526

Test stats 🧪

Test Results
Failed 0
Passed 44470
Skipped 4612
Total 49082

Steps errors 2

Expand to view the steps failures

Google Storage Download
  • Took 3 min 22 sec . View more details on here
  • Description: [2021-01-26T20:47:19.451Z] [Google Cloud Storage Plugin] Found 1 files to download from pattern: gs:
Checks if running on a Unix-like node
  • Took 0 min 0 sec . View more details on here

Log output

Expand to view the last 100 lines of log output

[2021-01-26T21:17:39.197Z] 16.03s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_098_o365
[2021-01-26T21:17:39.197Z] 16.02s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_221_snort
[2021-01-26T21:17:39.197Z] 14.35s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_102_o365
[2021-01-26T21:17:39.197Z] 10.03s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_130_panw
[2021-01-26T21:17:39.197Z] 9.88s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_009_cyberark
[2021-01-26T21:17:39.197Z] 9.82s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_143_ibmmq
[2021-01-26T21:17:39.197Z] 9.68s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_008_netscout
[2021-01-26T21:17:39.197Z] 9.61s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_141_ibmmq
[2021-01-26T21:17:39.197Z] 9.42s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_165_cisco
[2021-01-26T21:17:39.197Z] 9.40s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_132_panw
[2021-01-26T21:17:39.197Z] 9.40s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_153_cisco
[2021-01-26T21:17:39.197Z] 9.31s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_134_panw
[2021-01-26T21:17:39.197Z] 9.21s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_139_gcp
[2021-01-26T21:17:39.197Z] 9.03s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_007_tomcat
[2021-01-26T21:17:39.197Z] 8.95s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_249_juniper
[2021-01-26T21:17:39.197Z] 8.95s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_289_oracle
[2021-01-26T21:17:39.197Z] 8.88s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_227_squid
[2021-01-26T21:17:39.197Z] 8.81s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_226_squid
[2021-01-26T21:17:39.197Z] ======================= 305 passed in 1341.48s (0:22:21) =======================
[2021-01-26T21:17:39.197Z] >> python test: Integration Testing Complete
[2021-01-26T21:17:42.974Z] Client: Docker Engine - Community
[2021-01-26T21:17:42.974Z]  Version:           20.10.2
[2021-01-26T21:17:42.974Z]  API version:       1.41
[2021-01-26T21:17:42.974Z]  Go version:        go1.13.15
[2021-01-26T21:17:42.974Z]  Git commit:        2291f61
[2021-01-26T21:17:42.974Z]  Built:             Mon Dec 28 16:17:32 2020
[2021-01-26T21:17:42.974Z]  OS/Arch:           linux/amd64
[2021-01-26T21:17:42.974Z]  Context:           default
[2021-01-26T21:17:42.974Z]  Experimental:      true
[2021-01-26T21:17:42.974Z] 
[2021-01-26T21:17:42.974Z] Server: Docker Engine - Community
[2021-01-26T21:17:42.974Z]  Engine:
[2021-01-26T21:17:42.974Z]   Version:          20.10.2
[2021-01-26T21:17:42.974Z]   API version:      1.41 (minimum version 1.12)
[2021-01-26T21:17:42.974Z]   Go version:       go1.13.15
[2021-01-26T21:17:42.974Z]   Git commit:       8891c58
[2021-01-26T21:17:42.974Z]   Built:            Mon Dec 28 16:15:09 2020
[2021-01-26T21:17:42.974Z]   OS/Arch:          linux/amd64
[2021-01-26T21:17:42.974Z]   Experimental:     false
[2021-01-26T21:17:42.974Z]  containerd:
[2021-01-26T21:17:42.974Z]   Version:          1.4.3
[2021-01-26T21:17:42.974Z]   GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
[2021-01-26T21:17:42.974Z]  runc:
[2021-01-26T21:17:42.974Z]   Version:          1.0.0-rc92
[2021-01-26T21:17:42.974Z]   GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
[2021-01-26T21:17:42.974Z]  docker-init:
[2021-01-26T21:17:42.974Z]   Version:          0.19.0
[2021-01-26T21:17:42.974Z]   GitCommit:        de40ad0
[2021-01-26T21:17:42.974Z] Unable to find image 'alpine:3.4' locally
[2021-01-26T21:17:43.541Z] 3.4: Pulling from library/alpine
[2021-01-26T21:17:43.799Z] c1e54eec4b57: Pulling fs layer
[2021-01-26T21:17:44.057Z] c1e54eec4b57: Verifying Checksum
[2021-01-26T21:17:44.057Z] c1e54eec4b57: Download complete
[2021-01-26T21:17:44.317Z] c1e54eec4b57: Pull complete
[2021-01-26T21:17:44.317Z] Digest: sha256:b733d4a32c4da6a00a84df2ca32791bb03df95400243648d8c539e7b4cce329c
[2021-01-26T21:17:44.317Z] Status: Downloaded newer image for alpine:3.4
[2021-01-26T21:17:46.510Z] + python .ci/scripts/pre_archive_test.py
[2021-01-26T21:17:48.410Z] Copy ./x-pack/filebeat/build into build/x-pack/filebeat/build
[2021-01-26T21:17:48.422Z] Running in /var/lib/jenkins/workspace/Beats_beats_PR-23610/src/github.com/elastic/beats/build
[2021-01-26T21:17:48.753Z] + rm -rf ve
[2021-01-26T21:17:48.754Z] + find . -type d -name vendor -exec rm -r {} ;
[2021-01-26T21:17:48.768Z] Recording test results
[2021-01-26T21:17:54.769Z] [Checks API] No suitable checks publisher found.
[2021-01-26T21:17:55.336Z] Client: Docker Engine - Community
[2021-01-26T21:17:55.337Z]  Version:           20.10.2
[2021-01-26T21:17:55.337Z]  API version:       1.41
[2021-01-26T21:17:55.337Z]  Go version:        go1.13.15
[2021-01-26T21:17:55.337Z]  Git commit:        2291f61
[2021-01-26T21:17:55.337Z]  Built:             Mon Dec 28 16:17:32 2020
[2021-01-26T21:17:55.337Z]  OS/Arch:           linux/amd64
[2021-01-26T21:17:55.337Z]  Context:           default
[2021-01-26T21:17:55.337Z]  Experimental:      true
[2021-01-26T21:17:55.337Z] 
[2021-01-26T21:17:55.337Z] Server: Docker Engine - Community
[2021-01-26T21:17:55.337Z]  Engine:
[2021-01-26T21:17:55.337Z]   Version:          20.10.2
[2021-01-26T21:17:55.337Z]   API version:      1.41 (minimum version 1.12)
[2021-01-26T21:17:55.337Z]   Go version:       go1.13.15
[2021-01-26T21:17:55.337Z]   Git commit:       8891c58
[2021-01-26T21:17:55.337Z]   Built:            Mon Dec 28 16:15:09 2020
[2021-01-26T21:17:55.337Z]   OS/Arch:          linux/amd64
[2021-01-26T21:17:55.337Z]   Experimental:     false
[2021-01-26T21:17:55.337Z]  containerd:
[2021-01-26T21:17:55.337Z]   Version:          1.4.3
[2021-01-26T21:17:55.337Z]   GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
[2021-01-26T21:17:55.337Z]  runc:
[2021-01-26T21:17:55.337Z]   Version:          1.0.0-rc92
[2021-01-26T21:17:55.337Z]   GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
[2021-01-26T21:17:55.337Z]  docker-init:
[2021-01-26T21:17:55.337Z]   Version:          0.19.0
[2021-01-26T21:17:55.337Z]   GitCommit:        de40ad0
[2021-01-26T21:18:06.144Z] Stage "Packaging" skipped due to earlier failure(s)
[2021-01-26T21:18:06.223Z] Running in /var/lib/jenkins/workspace/Beats_beats_PR-23610/src/github.com/elastic/beats
[2021-01-26T21:18:08.050Z] Running on Jenkins in /var/lib/jenkins/workspace/Beats_beats_PR-23610
[2021-01-26T21:18:08.150Z] [INFO] getVaultSecret: Getting secrets
[2021-01-26T21:18:08.270Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2021-01-26T21:18:09.022Z] + chmod 755 generate-build-data.sh
[2021-01-26T21:18:09.023Z] + ./generate-build-data.sh https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-23610/ https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-23610/runs/7 FAILURE 2861519
[2021-01-26T21:18:09.273Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-23610/runs/7/steps/?limit=10000 -o steps-info.json
[2021-01-26T21:18:19.160Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-23610/runs/7/tests/?status=FAILED -o tests-errors.json

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 44470
Skipped 4612
Total 49082

Signed-off-by: chrismark <chrismarkou92@gmail.com>
Signed-off-by: chrismark <chrismarkou92@gmail.com>
@jsoriano jsoriano self-requested a review January 21, 2021 13:10
@ChrsMark ChrsMark added the test-plan Add this PR to be manual test plan label Jan 21, 2021
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

I am ok with following with this approach, but we have to take into account that add_kubernetes_metadata won't add the deployment name, we have to think if this is something we have to support, but we can do it as a separate issue.

Comment on lines 66 to 67
if rsName != nil {
rsName := rsName.(string)
Copy link
Member

Choose a reason for hiding this comment

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

Nit. Make it slightly safer in case rsName is not a string.

Suggested change
if rsName != nil {
rsName := rsName.(string)
if rsName, ok := rsName.(string); ok {

libbeat/common/kubernetes/metadata/pod.go Show resolved Hide resolved
},
}

_, err := client.AppsV1().ReplicaSets(namespace).Create(context.TODO(), rs, metav1.CreateOptions{})
Copy link
Member

Choose a reason for hiding this comment

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

Nit. In tests it is ok to use context.Background() 🙂

Suggested change
_, err := client.AppsV1().ReplicaSets(namespace).Create(context.TODO(), rs, metav1.CreateOptions{})
_, err := client.AppsV1().ReplicaSets(namespace).Create(context.Background(), rs, metav1.CreateOptions{})

libbeat/common/kubernetes/metadata/pod.go Show resolved Hide resolved
Signed-off-by: chrismark <chrismarkou92@gmail.com>
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Thanks!

@kuisathaverat
Copy link
Contributor

the CI failure is unrelated to the PR, were taking a look

@ChrsMark
Copy link
Member Author

Thanks for looking into this @kuisathaverat, I'm gonna merge this one.

@ChrsMark ChrsMark merged commit 2d7e7b4 into elastic:master Jan 27, 2021
ChrsMark added a commit to ChrsMark/beats that referenced this pull request Jan 27, 2021
@ChrsMark ChrsMark removed the needs_backport PR is waiting to be backported to other branches. label Jan 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
containers Related to containers use case enhancement Team:Integrations Label for the Integrations team test-plan Add this PR to be manual test plan test-plan-added This PR has been added to the test plan v7.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add metadata of deployment controlling pods
5 participants