Cherry-pick #26056 to 7.x: Add k8s cluster identifier #26346
Merged
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.
Cherry-pick of PR #26056 to 7.x branch. Original message:
What does this PR do?
This PR add cluster identifier fields (defined in ECS) as part of k8s metadata in:
Note: [MetaGenerators' refactoring ] The identifiers are stored under
orchestrator.cluster.url/name
and because of this the metadata generators are refactored a little bit so as to cover the addition of such fields that are out ofkubernetes.*
namespace. The change is transparent andkubernetes.*
metadata are still reported in the same way. The refactoring is about making it easier to handle in the future ECS fields populated by k8s metadata generators. The logic is covered in interfaces' docs.The transparency of the refactoring is ensured by Event's testing in tests below:
The fields are populated following the flow bellow:
kubeadm-config
configMap (if available). Only for clusters setup withkubeadm
.Why is it important?
To add cluster identifier ECS fields as part of k8s metadata.
Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Author's Checklist
How to test this PR locally
A. Verify that events from state_* metricsets are enriched properly
Enable kubernetes module with the following datasets:
Note: In the example above I run
kube-state-metrics
on local cluster using kind and I expose it to my host machine usingkubectl -n kube-system port-forward svc/kube-state-metrics 8081:8080
. In this case I need to defineadd_metadata
astrue
and also provide the properkube_config
so as to reach the k8s API. You can trykubectl config view -o jsonpath='{"Cluster name\tServer\n"}{range .clusters[*]}{.name}{"\t"}{.cluster.server}{"\n"}{end}'
to verify the values.2. Ensure that
orchestrator.cluster.name
,orchestrator.cluster.name
,kubernetes.namespace
andkubernetes.node.name
are being populated properly.3. Perform same test while running with inCluster mode, running metricbeat as Pod in the cluster (Note that the k8s cluster should be create with
kubeadm
since values for cluster info are retrieved fromkubeadm-config
configmap, you can trykubectl -n kube-system get configmap kubeadm-config -o yaml
to verify it)B. Verify that events from add_kuberentes_metadata are enriched properly
orchestrator.cluster.name
,orchestrator.cluster.name
,kubernetes.namespace
andkubernetes.node.name
are being populated properly.C. Verify that events from autodiscover provider are enriched properly
orchestrator.cluster.name
,orchestrator.cluster.name
,kubernetes.namespace
andkubernetes.node.name
are being populated properly.D. Perform one of the above scenarios with Metricbeat running as Pod on GKE.
Related issues