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

Adding generic_logs template for hints autodiscovery #2981

Merged
merged 6 commits into from
Jul 6, 2023
Merged

Conversation

gizas
Copy link
Contributor

@gizas gizas commented Jul 3, 2023

NOT TO MERGE UNTIL #2986 is merged

  • Enhancement

What does this PR do?

This PR adds the generic_logs template that needs to be used in an Elastic Agent Standalone scenario in order to support by default the container log processing.

This PR is the continuation of #2386 (comment) in order to add the missing template needed to support the default behaviour of collection of logs

Why is it important?

It is important in order to allow log collection for k8s pods for the hints aytodiscovery scenario
Relevant documentation PR is added here: https://github.com/elastic/ingest-docs/pull/304/files

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

How to test this PR locally

  1. Install a local kubernetes cluster with kind
  2. Create your stack elastic-package stack up -d -vvv --version=8.8.1
  3. Download and install the elastic-agent-standalone manifest with the changes described in the documentation PR

Enabling hints in the kubernetes standalone manifest:

providers.kubernetes:
  node: ${NODE_NAME}
  scope: node
  hints:
    enabled: true
    default_container_logs: false 

Example to manually mount the needed generic_logs template under the inputs.d folder of Elastic Agent

volumeMounts:
- name: external-inputs
  mountPath: /etc/elastic-agent/inputs.d/generic_logs.yml
...
volumes:
- name: external-inputs
  hostPath:
    path: /var/log/test/generic_logs.yml
  1. Install agent manifest
  2. Install nginx manifest
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: "generic_logs.container_logs"
        co.elastic.hints/stream: "stderr"
    spec:
      containers:
      - image: nginx
        name: nginx
  1. Inspect the rendered configuration inside Elastic Agent
/usr/share/elastic-agent# /elastic-agent inspect -v --variables --variables-wait 2s
  1. Exec to nginx code and produce stdout and stderror outputs:
kubectl exec -ti nginx-654557c679-rzrtt -- bash
root@nginx-654557c679-rzrtt:/# echo "stdout message" >> /proc/1/fd/1
root@nginx-654557c679-rzrtt:/# echo "stderror message" >> /proc/1/fd/2
  1. Login to kibana and observe the stderror stream
    Screenshot 2023-07-03 at 5 07 54 PM

@gizas gizas requested a review from a team as a code owner July 3, 2023 14:08
@gizas gizas requested review from ChrsMark and constanca-m July 3, 2023 14:08
@mergify mergify bot assigned gizas Jul 3, 2023
@mergify
Copy link
Contributor

mergify bot commented Jul 3, 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.

@mergify mergify bot added the backport-skip label Jul 3, 2023
@elasticmachine
Copy link
Contributor

elasticmachine commented Jul 3, 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-07-05T12:27:42.142+0000

  • Duration: 26 min 30 sec

Test stats 🧪

Test Results
Failed 0
Passed 5951
Skipped 23
Total 5974

💚 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!)

@elasticmachine
Copy link
Contributor

elasticmachine commented Jul 3, 2023

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 98.684% (75/76) 👍
Files 68.582% (179/261) 👍
Classes 67.146% (327/487) 👍
Methods 54.136% (1034/1910) 👍
Lines 40.293% (11861/29437) 👎 -0.061
Conditionals 100.0% (0/0) 💚

@ChrsMark
Copy link
Member

ChrsMark commented Jul 3, 2023

This generic_logs.container_logs in co.elastic.hints/package: "generic_logs.container_logs" bugs me tbh.
What do you think about skipping the generic_logs. prefix completely? This means we would need ofc to change the implementation at https://github.com/ChrsMark/elastic-agent/blob/cdd839de32c75b40b1ac142e371cf6bb6da0e9a6/internal/pkg/composable/providers/kubernetes/pod.go#L403.

gizas and others added 2 commits July 5, 2023 09:54
…er_logs.yml

Co-authored-by: Chris Mark <chrismarkou92@gmail.com>
…er_logs.yml

Co-authored-by: Chris Mark <chrismarkou92@gmail.com>
@gizas gizas merged commit 8399924 into main Jul 6, 2023
@gizas gizas deleted the generic_logs_hints branch July 6, 2023 08:11
AndersonQ pushed a commit to AndersonQ/elastic-agent that referenced this pull request Jul 10, 2023
* Adding generic_logs template for hints autodiscovery
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.

3 participants