11 Nov 2021 11:38 AM - last edited on 18 Nov 2021 11:16 AM by MaciejNeumann
When creating Dynatrace autotags via the UI supported rules you might miss a few entities you'd like to tag. For example there is no easy way to tag a Kubernetes Cluster or a Container Instance.
You might need that though for API analysis or other usecases.
The solution I use to tag the complete stack (K8s cluster, hosts, processes, services, applications, synthetic monitors) for everything that runs/is provided by a specific kubernetes cluster is the following:
(entity Selectors and relationship mapping to the rescue).
A concrete example (I'm using YAML notation for the JSON formated auto-tag rule used by the DT API):
name: dev-stage
description:
entitySelectorBasedRules:
- enabled: true
entitySelector: type(KUBERNETES_CLUSTER),entityName(_dev)
valueFormat: ''
- enabled: true
entitySelector: type(HOST),toRelationships.isClusterOfHost(type(KUBERNETES_CLUSTER),tag(dev-stage))
valueFormat: ''
- enabled: true
entitySelector: type(CLOUD_APPLICATION_NAMESPACE),toRelationships.isClusterOfNamespace(type(KUBERNETES_CLUSTER),tag(dev-stage))
valueFormat: ''
- enabled: true
entitySelector: type(CLOUD_APPLICATION),toRelationships.isClusterOfCa(type(KUBERNETES_CLUSTER),tag(dev-stage))
valueFormat: ''
- enabled: true
entitySelector: type(PROCESS_GROUP),fromRelationships.isPgOfCa(type(CLOUD_APPLICATION),tag(dev-stage))
valueFormat: ''
- enabled: true
entitySelector: type(PROCESS_GROUP_INSTANCE),fromRelationships.isInstanceOf(type(PROCESS_GROUP),tag(dev-stage))
valueFormat: ''
- enabled: true
entitySelector: type(CONTAINER_GROUP_INSTANCE),fromRelationships.isCgiOfCluster(type(KUBERNETES_CLUSTER),tag(dev-stage))
valueFormat: ''
- enabled: true
entitySelector: type(SERVICE),fromRelationships.runsOn(type(PROCESS_GROUP),tag(dev-stage))
valueFormat: ''
- enabled: true
entitySelector: type(APPLICATION),fromRelationships.calls(type(SERVICE),tag(dev-stage))
valueFormat: ''
- enabled: true
entitySelector: type(SYNTHETIC_TEST),fromRelationships.monitors(type(APPLICATION),tag(dev-stage))
valueFormat: ''
rules: []
At first this seems counter intuitive as the first rule would ONLY tag the Kubernetes cluster and the other rules would not do anything (because of the entitySelector filter tag(dev-stage) - which is a reference to the tag we are just defining).
But once the first rule is applied to the K8s cluster all the other rules start to 'unfold': the HOSTs are tagged with the same tag, the CLOUD_APPLICATIONS.
Once the CLOUD_APPLICATIONS are tagged the depending PROCESS_GROUPS are also tagged and so on.
The CONTAINER_GROUP instances are tagged as well (you cannot directly select them in non-entity selector based rules).
This ruleset basically triggers a chain-reaction of applying the same tag across the different dependencies that Dynatrace detected on the fly. Which dependencies you want to consider for this is up to you (whatever you can find in the from/to relationships of an entity is possible).
Where would you like to use this:
Thought I share this tagging strategy 😉
kr,
Reinhard
12 Nov 2021 09:30 AM
Thank you, Reinhard! That's a really comprehensive tip article 🙂 I hope many other Dynatrace users will find it super useful
12 Nov 2021 11:53 AM
This is super useful and indeed Protip. I'd love to use this in our customer places. Thanks for sharing, Reinhard.
19 Apr 2022 01:44 PM
This is golden! Thanks for putting this together. Helped me a whole lot on learning how to do this tagging this morning.