[8.17](backport #41903) Add regex pattern matching to add_kubernetes_metadata processor #42087
+115
−17
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.
Proposed commit message
Add the ability to extract the matching key from fields using a regex pattern to the add_kubernetes_metadata processor. I've added a new field -
regex_pattern
to the existingfields
matcher. If the field isn't present, the matcher continues to work the same way it used to. The regex pattern has to contain a named capture group:key
, and the first leftmost match for this group is the extracted key value. Other than this, the semantics are identical to the existing ones for thefields
matcher.Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.How to test this PR locally
This was originally intended to fix https://github.com/elastic/ingest-dev/issues/3428, where we want to match on a part of
system.process.cgroup.id
. I've verified this by building an agent container image with this change enabled, and making the following changes to the default agent manifest:With the Helm Chart, you can use the following values:
Related issues
Use cases
It's now possible to extract parts of fields for matching with kubernetes metadata. A use case which this is intended to make possible is adding kubernetes metadata to system process metrics. These metrics will contain the cgroup id under the field
system.process.cgroup.id
if cgroups are enabled, but the container id as reported by Kubernetes is only part of this value. In order to match it against the latter, we need the ability to only use a part of it.Screenshots
Example document
This is an automatic backport of pull request #41903 done by [Mergify](https://mergify.com).