-
Notifications
You must be signed in to change notification settings - Fork 457
[Kubernetes] Reroute container logs based on pod annotations #7118
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
Merged
zmoog
merged 25 commits into
elastic:main
from
zmoog:zmoog/reroute-k8s-containers-logs-based-on-labels
Sep 13, 2023
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
4637d62
Add ingest pipeline for rerouting
zmoog 5f7a3fa
Add pipeline failure handler
zmoog 0fe640c
Set service.name and service.version
zmoog b483709
Draft rerouting docs
zmoog d8ed5e2
Update packages/kubernetes/data_stream/container_logs/elasticsearch/i…
zmoog 80918ea
Use the Set processor more efficiently
zmoog 7fe8dea
Use ECS for service.name and service.version
zmoog 3559f9f
Switch to routing rules
zmoog dddb795
Add basic testing for service.name and service.version
zmoog 3bb1e49
Expand the rerouting docs
zmoog 3f9c79a
Mention container-logs routing in the README
zmoog 47cee10
Cleanup
zmoog b187956
Update test case adding a dataset label
zmoog 7be0729
Docs: add a namespace customization example
zmoog 4b52f34
Drop static fallbacks
zmoog f026f36
Update docs
zmoog daf53c2
Update changelog
zmoog d21d06c
Update packages/kubernetes/data_stream/container_logs/routing_rules.yml
zmoog 9eddeec
Update packages/kubernetes/_dev/build/docs/container-logs.md
zmoog 7385b12
Switch from labels to annotations
zmoog 6f01d4f
Replace some leftover labels with annotations
zmoog 825e7ac
Update packages/kubernetes/_dev/build/docs/container-logs.md
zmoog 81e13ac
Indent processors list to improve compatibility
zmoog b7d3de0
Update rendered docs
zmoog 4b2d776
Explain WHY we added processors for annotations
zmoog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/kubernetes/data_stream/container_logs/_dev/test/pipeline/test-common-config.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fields: | ||
data_stream: | ||
dataset: kubernetes.container_logs | ||
namespace: default | ||
kubernetes: | ||
annotations: | ||
elastic_co/dataset: kubernetes.container_logs.nginx | ||
elastic_co/namespace: nginx | ||
labels: | ||
app_kubernetes_io/version: "v0.1.0" | ||
app_kubernetes_io/name: "myservice" |
4 changes: 4 additions & 0 deletions
4
packages/kubernetes/data_stream/container_logs/_dev/test/pipeline/test-nginx.log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
2023/07/25 15:24:11 [notice] 1#1: start worker process 33 | ||
2023/07/25 15:24:11 [notice] 1#1: start worker process 34 | ||
2023/07/25 15:24:11 [notice] 1#1: start worker process 35 | ||
2023/07/25 15:24:11 [notice] 1#1: using the "epoll" event method |
92 changes: 92 additions & 0 deletions
92
...ges/kubernetes/data_stream/container_logs/_dev/test/pipeline/test-nginx.log-expected.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{ | ||
"expected": [ | ||
{ | ||
"data_stream": { | ||
"dataset": "kubernetes.container_logs.nginx", | ||
"namespace": "nginx", | ||
"type": "logs" | ||
}, | ||
"kubernetes": { | ||
"annotations": { | ||
"elastic_co/dataset": "kubernetes.container_logs.nginx", | ||
"elastic_co/namespace": "nginx" | ||
}, | ||
"labels": { | ||
"app_kubernetes_io/name": "myservice", | ||
"app_kubernetes_io/version": "v0.1.0" | ||
} | ||
}, | ||
"message": "2023/07/25 15:24:11 [notice] 1#1: start worker process 33", | ||
"service": { | ||
"name": "myservice", | ||
"version": "v0.1.0" | ||
} | ||
}, | ||
{ | ||
"data_stream": { | ||
"dataset": "kubernetes.container_logs.nginx", | ||
"namespace": "nginx", | ||
"type": "logs" | ||
}, | ||
"kubernetes": { | ||
"annotations": { | ||
"elastic_co/dataset": "kubernetes.container_logs.nginx", | ||
"elastic_co/namespace": "nginx" | ||
}, | ||
"labels": { | ||
"app_kubernetes_io/name": "myservice", | ||
"app_kubernetes_io/version": "v0.1.0" | ||
} | ||
}, | ||
"message": "2023/07/25 15:24:11 [notice] 1#1: start worker process 34", | ||
"service": { | ||
"name": "myservice", | ||
"version": "v0.1.0" | ||
} | ||
}, | ||
{ | ||
"data_stream": { | ||
"dataset": "kubernetes.container_logs.nginx", | ||
"namespace": "nginx", | ||
"type": "logs" | ||
}, | ||
"kubernetes": { | ||
"annotations": { | ||
"elastic_co/dataset": "kubernetes.container_logs.nginx", | ||
"elastic_co/namespace": "nginx" | ||
}, | ||
"labels": { | ||
"app_kubernetes_io/name": "myservice", | ||
"app_kubernetes_io/version": "v0.1.0" | ||
} | ||
}, | ||
"message": "2023/07/25 15:24:11 [notice] 1#1: start worker process 35", | ||
"service": { | ||
"name": "myservice", | ||
"version": "v0.1.0" | ||
} | ||
}, | ||
{ | ||
"data_stream": { | ||
"dataset": "kubernetes.container_logs.nginx", | ||
"namespace": "nginx", | ||
"type": "logs" | ||
}, | ||
"kubernetes": { | ||
"annotations": { | ||
"elastic_co/dataset": "kubernetes.container_logs.nginx", | ||
"elastic_co/namespace": "nginx" | ||
}, | ||
"labels": { | ||
"app_kubernetes_io/name": "myservice", | ||
"app_kubernetes_io/version": "v0.1.0" | ||
} | ||
}, | ||
"message": "2023/07/25 15:24:11 [notice] 1#1: using the \"epoll\" event method", | ||
"service": { | ||
"name": "myservice", | ||
"version": "v0.1.0" | ||
} | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/kubernetes/data_stream/container_logs/elasticsearch/ingest_pipeline/default.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
description: Pipeline for Kubernetes container logs | ||
processors: | ||
zmoog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- set: | ||
field: service.name | ||
copy_from: kubernetes.labels.app_kubernetes_io/name | ||
ignore_empty_value: true | ||
- set: | ||
field: service.name | ||
copy_from: kubernetes.container.name | ||
override: false | ||
ignore_empty_value: true | ||
- set: | ||
field: service.version | ||
copy_from: kubernetes.labels.app_kubernetes_io/version | ||
ignore_empty_value: true | ||
on_failure: | ||
- set: | ||
field: event.kind | ||
value: pipeline_error | ||
- append: | ||
field: error.message | ||
value: '{{{ _ingest.on_failure_message }}}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/kubernetes/data_stream/container_logs/routing_rules.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Route container logs events to the correct dataset and namespace | ||
# based on pod annotations. | ||
- source_dataset: kubernetes.container_logs | ||
rules: | ||
- target_dataset: | ||
- "{{kubernetes.annotations.elastic_co/dataset}}" | ||
- "{{data_stream.dataset}}" | ||
namespace: | ||
- "{{kubernetes.annotations.elastic_co/namespace}}" | ||
- "{{data_stream.namespace}}" | ||
if: "ctx.kubernetes?.annotations != null" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.