<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic DQL for filtering kubernetes pods by annotations in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/DQL-for-filtering-kubernetes-pods-by-annotations/m-p/250779#M1053</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use DQL to filter workloads in my EKS environment by certain pod annotations.&lt;/P&gt;&lt;P&gt;So far I have this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fetch dt.entity.cloud_application_instance, from: -30m | fields id, pod.id = id, pod.name = entity.name, pod.containers = record(running = runningContainersCount, desired = desiredContainersCount),pod.condition = currentCondition, pod.labels = cloudApplicationLabels, pod.annotations = kubernetesAnnotations,pod.age = record(start = resourceCreationTimestamp, end = if(isNull(resourceDeletionTimestamp), now(), else:resourceDeletionTimestamp)), pod.resourceDeletionTimestamp = resourceDeletionTimestamp, pod.phase = cloudApplicationInstancePhase, cluster.id = clustered_by[dt.entity.kubernetes_cluster], node.id = runs_on[dt.entity.kubernetes_node],namespace.id = belongs_to[dt.entity.cloud_application_namespace], workload.id = instance_of[dt.entity.cloud_application], namespace.name = namespaceName, workload.name = workloadName| fieldsAdd pod.state = if((isNotNull(pod.resourceDeletionTimestamp) AND (pod.phase == "RUNNING")), "TERMINATING", else:pod.phase)&lt;BR /&gt;// Filters: [cluster,namespace]&lt;BR /&gt;| filter in(id, classicEntitySelector("type(CLOUD_APPLICATION_INSTANCE),toRelationship.isClusterOfCai(type(KUBERNETES_CLUSTER),entityName.equals(operations))"))&lt;BR /&gt;| filter in(id, classicEntitySelector("type(CLOUD_APPLICATION_INSTANCE),toRelationship.isNamespaceOfCai(type(CLOUD_APPLICATION_NAMESPACE),entityName.equals(client-services))"))&lt;BR /&gt;| filter in(id, classicEntitySelector("type(CLOUD_APPLICATION_INSTANCE),toRelationship.isClusterOfCai(type(KUBERNETES_CLUSTER),appEnabled(true))"))&lt;BR /&gt;| limit 200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to do next is further filter whether or not each pod has certain annotations on it.&amp;nbsp; For example lets' say the annotation is "&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;instrumentation.opentelemetry.io/inject-java&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;monitoring/universal-instrumentation", but in reality , I just want to find any pods that have annotations starting with "&lt;SPAN class=""&gt;instrumentation.opentelemetry.io".&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;How can add that type of filter to my existing DQL?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jul 2024 13:32:14 GMT</pubDate>
    <dc:creator>roberto_camp1</dc:creator>
    <dc:date>2024-07-16T13:32:14Z</dc:date>
    <item>
      <title>DQL for filtering kubernetes pods by annotations</title>
      <link>https://community.dynatrace.com/t5/DQL/DQL-for-filtering-kubernetes-pods-by-annotations/m-p/250779#M1053</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use DQL to filter workloads in my EKS environment by certain pod annotations.&lt;/P&gt;&lt;P&gt;So far I have this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fetch dt.entity.cloud_application_instance, from: -30m | fields id, pod.id = id, pod.name = entity.name, pod.containers = record(running = runningContainersCount, desired = desiredContainersCount),pod.condition = currentCondition, pod.labels = cloudApplicationLabels, pod.annotations = kubernetesAnnotations,pod.age = record(start = resourceCreationTimestamp, end = if(isNull(resourceDeletionTimestamp), now(), else:resourceDeletionTimestamp)), pod.resourceDeletionTimestamp = resourceDeletionTimestamp, pod.phase = cloudApplicationInstancePhase, cluster.id = clustered_by[dt.entity.kubernetes_cluster], node.id = runs_on[dt.entity.kubernetes_node],namespace.id = belongs_to[dt.entity.cloud_application_namespace], workload.id = instance_of[dt.entity.cloud_application], namespace.name = namespaceName, workload.name = workloadName| fieldsAdd pod.state = if((isNotNull(pod.resourceDeletionTimestamp) AND (pod.phase == "RUNNING")), "TERMINATING", else:pod.phase)&lt;BR /&gt;// Filters: [cluster,namespace]&lt;BR /&gt;| filter in(id, classicEntitySelector("type(CLOUD_APPLICATION_INSTANCE),toRelationship.isClusterOfCai(type(KUBERNETES_CLUSTER),entityName.equals(operations))"))&lt;BR /&gt;| filter in(id, classicEntitySelector("type(CLOUD_APPLICATION_INSTANCE),toRelationship.isNamespaceOfCai(type(CLOUD_APPLICATION_NAMESPACE),entityName.equals(client-services))"))&lt;BR /&gt;| filter in(id, classicEntitySelector("type(CLOUD_APPLICATION_INSTANCE),toRelationship.isClusterOfCai(type(KUBERNETES_CLUSTER),appEnabled(true))"))&lt;BR /&gt;| limit 200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to do next is further filter whether or not each pod has certain annotations on it.&amp;nbsp; For example lets' say the annotation is "&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;instrumentation.opentelemetry.io/inject-java&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;monitoring/universal-instrumentation", but in reality , I just want to find any pods that have annotations starting with "&lt;SPAN class=""&gt;instrumentation.opentelemetry.io".&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;How can add that type of filter to my existing DQL?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2024 13:32:14 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/DQL-for-filtering-kubernetes-pods-by-annotations/m-p/250779#M1053</guid>
      <dc:creator>roberto_camp1</dc:creator>
      <dc:date>2024-07-16T13:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: DQL for filtering kubernetes pods by annotations</title>
      <link>https://community.dynatrace.com/t5/DQL/DQL-for-filtering-kubernetes-pods-by-annotations/m-p/250796#M1055</link>
      <description>&lt;P&gt;Actually checking specific annotation is easier than pattern. To do this use such filter and pod.annotations fileds already extracted by the query:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| filter isNotNull(pod.annotations[`instrumentation.opentelemetry.io/inject-javamonitoring/universal-instrumentation`])&lt;/LI-CODE&gt;&lt;P&gt;backticks need to be used, because this annotation contains /&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Checking patterns is not as straight forward, because annotations are complex record and we do not have means to analyze records in generic way. To do so, for now, we need to convert complex record into array of key-value pairs and use iterative expressions to look into it.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| fieldsAdd pod.annotations.array=parse(toString(pod.annotations), """'{' ARRAY{SPACE? '"' [^"]+:key '"' ':' JSON_VALUE:value ','?}*:a """)
| filter iAny( startsWith(pod.annotations.array[][key], "instrumentation.opentelemetry.io" ))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it helps&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2024 15:55:23 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/DQL-for-filtering-kubernetes-pods-by-annotations/m-p/250796#M1055</guid>
      <dc:creator>krzysztof_hoja</dc:creator>
      <dc:date>2024-07-16T15:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: DQL for filtering kubernetes pods by annotations</title>
      <link>https://community.dynatrace.com/t5/DQL/DQL-for-filtering-kubernetes-pods-by-annotations/m-p/250798#M1057</link>
      <description>&lt;P&gt;Thank you krzysztof_hoja&amp;nbsp;, yes it's a bit messy but the second example you give fits the solution perfectly.&amp;nbsp; Thanks so much for a quick response!&lt;/P&gt;&lt;DIV class=""&gt;&lt;A class="" href="https://community.dynatrace.com/t5/DQL/DQL-for-filtering-kubernetes-pods-by-annotations/td-p/250779#" target="_blank" rel="noopener"&gt;PREVIEW&lt;/A&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 16 Jul 2024 16:22:45 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/DQL-for-filtering-kubernetes-pods-by-annotations/m-p/250798#M1057</guid>
      <dc:creator>roberto_camp1</dc:creator>
      <dc:date>2024-07-16T16:22:45Z</dc:date>
    </item>
  </channel>
</rss>

