<?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 Is an optional filter using variable possible? in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/Is-an-optional-filter-using-variable-possible/m-p/245379#M876</link>
    <description>&lt;P&gt;Imagine I have logs coming from a Kubernetes cluster which I can retrieve successfully with this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch logs
| filter k8s.namespace.name == "some-namespace-here"
| filter matchesPhrase(content, "someValue")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can also run this app locally (or outside kubernetes), in which case, the DQL needs to be:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch logs
| filter matchesPhrase(content, "someValue")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rather than create two tiles, is is possible to dynamically achieve this? So that a single tile works in both environments?&lt;/P&gt;&lt;P&gt;I imagined creating a dashboard level variable: "Kubernetes Mode: on / off" and toggling that would (somehow) reconfigure the DQL.&lt;/P&gt;</description>
    <pubDate>Mon, 13 May 2024 05:05:36 GMT</pubDate>
    <dc:creator>hfdku</dc:creator>
    <dc:date>2024-05-13T05:05:36Z</dc:date>
    <item>
      <title>Is an optional filter using variable possible?</title>
      <link>https://community.dynatrace.com/t5/DQL/Is-an-optional-filter-using-variable-possible/m-p/245379#M876</link>
      <description>&lt;P&gt;Imagine I have logs coming from a Kubernetes cluster which I can retrieve successfully with this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch logs
| filter k8s.namespace.name == "some-namespace-here"
| filter matchesPhrase(content, "someValue")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can also run this app locally (or outside kubernetes), in which case, the DQL needs to be:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch logs
| filter matchesPhrase(content, "someValue")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rather than create two tiles, is is possible to dynamically achieve this? So that a single tile works in both environments?&lt;/P&gt;&lt;P&gt;I imagined creating a dashboard level variable: "Kubernetes Mode: on / off" and toggling that would (somehow) reconfigure the DQL.&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2024 05:05:36 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Is-an-optional-filter-using-variable-possible/m-p/245379#M876</guid>
      <dc:creator>hfdku</dc:creator>
      <dc:date>2024-05-13T05:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: Is an optional filter using variable possible?</title>
      <link>https://community.dynatrace.com/t5/DQL/Is-an-optional-filter-using-variable-possible/m-p/245383#M877</link>
      <description>&lt;P&gt;Let's define variable this way:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krzysztof_hoja_0-1715578372074.png" style="width: 572px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/19774i9803ACC1575E1B52/image-dimensions/572x276?v=v2" width="572" height="276" role="button" title="krzysztof_hoja_0-1715578372074.png" alt="krzysztof_hoja_0-1715578372074.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Then the condition can look like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| filter  ($KubernetesMode=="on" and k8s.namespace.name == "some-namespace-here")
  or ($KubernetesMode=="off" and isNull(k8s.namespace.name))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason I used isNull for "off" case is that without it the query would take all log lines: from Kubernetes as well as from local case.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also approach the problem in more dynamic way using variable based on DQL query defined this way:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krzysztof_hoja_1-1715579095752.png" style="width: 663px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/19775i4AA81FB82CCAA78C/image-dimensions/663x247?v=v2" width="663" height="247" role="button" title="krzysztof_hoja_1-1715579095752.png" alt="krzysztof_hoja_1-1715579095752.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch dt.entity.cloud_application_namespace
| fields entity.name
| dedup entity.name
| append [data record(entity.name="&amp;lt;local&amp;gt;")]&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Then the filter reacting to any namespace selected would look like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| filter  ($KubernetesMode!="&amp;lt;local&amp;gt;" and k8s.namespace.name == $KubernetesMode)
  or ($KubernetesMode=="&amp;lt;local&amp;gt;" and isNull(k8s.namespace.name))&lt;/LI-CODE&gt;&lt;P&gt;Now you can switch between different namespaces and log lined without namespace set (local)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kris&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2024 05:48:04 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Is-an-optional-filter-using-variable-possible/m-p/245383#M877</guid>
      <dc:creator>krzysztof_hoja</dc:creator>
      <dc:date>2024-05-13T05:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: Is an optional filter using variable possible?</title>
      <link>https://community.dynatrace.com/t5/DQL/Is-an-optional-filter-using-variable-possible/m-p/245384#M878</link>
      <description>&lt;P&gt;Thanks Krzysztof, I'll experiment with this tomorrow&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2024 06:30:57 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Is-an-optional-filter-using-variable-possible/m-p/245384#M878</guid>
      <dc:creator>hfdku</dc:creator>
      <dc:date>2024-05-13T06:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: Is an optional filter using variable possible?</title>
      <link>https://community.dynatrace.com/t5/DQL/Is-an-optional-filter-using-variable-possible/m-p/245656#M890</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hfdku_0-1715751419484.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/19866i2FD21912385960F8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hfdku_0-1715751419484.png" alt="hfdku_0-1715751419484.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Works perfectly, thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 05:37:14 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Is-an-optional-filter-using-variable-possible/m-p/245656#M890</guid>
      <dc:creator>hfdku</dc:creator>
      <dc:date>2024-05-15T05:37:14Z</dc:date>
    </item>
  </channel>
</rss>

