<p>I'm trying to create an alert using promql/prometheus but having trouble generating the proper time series. In K8s, my objective is to display any code/version mismatch for a particular app sitting in multiple clusters. By using count, any app with a value greater than 1 would tell me that there are &gt; 1 version deployed. Currently my query will generate the following:</p>
<p><code>count(kube_deployment_labels{label_app=~&quot;.*&quot;}) by (label_version, label_app)</code></p>
<pre><code>| label_app |  label_version  |  Value #A |
-------------------------------------------
| app_1     |   0.0.111       |     2     |
| app_1     |   0.0.222       |     1     |
| app_2     |   0.0.111       |     2     |
| app_2     |   0.0.222       |     1     |
| app_3     |   0.0.111       |     3     |
</code></pre>
<p>The values on the 4th column represent the # of said code (<em>label_version</em>) deployed in each cluster; for example, <strong>app_1</strong> &amp; <strong>app_2</strong> has version <strong>0.0.111</strong> deployed in two clusters &amp; <strong>0.0.222</strong> deployed in one cluster, but <strong>app_3</strong> has the same version deployed in all three clusters.</p>
<p>My end goal is to only count distinct <em>label_version</em> and have the time series populate in this way:</p>
<pre><code>| label_app |  Value #A  |
 -------------------------
| app_1     |      2     |
| app_2     |      2     |
| app_3     |      1     |
</code></pre>
<p>Executing <code>(count(group by(label_version)kube_deployment_labels{label_app=~&quot;.*&quot;})) </code> gives me the correct <em>Value</em> but I'd like to list out all the apps associated to the <em>Value</em> as well. I've tried a variety of grouping but was unsuccessful.</p>
<p>Any help would be appreciated! Thanks in advance.</p>

KC14
<p>You can apply one more <code>count by</code> over your previous result.</p>
<pre><code>count(
 count(
  kube_deployment_labels{label_app=~&quot;.*&quot;}
 ) by (label_version, label_app)
) by (label_app)
</code></pre>
<p>will return number of <code>label_version</code>s associated with each <code>label_app</code>.</p>
<p>Somewhat similar query can be seen in this <a href="https://prometheus.demo.do.prometheus.io/graph?g0.expr=go_info&amp;g0.tab=1&amp;g0.stacked=0&amp;g0.range_input=1h&amp;g1.expr=count(alertmanager_alerts_received_total)%20by%20(status%2Cversion)&amp;g1.tab=1&amp;g1.stacked=0&amp;g1.range_input=1h&amp;g2.expr=count(%0A%20%20count(%0A%20%20%20%20alertmanager_alerts_received_total%0A%20%20)%20by%20(status%2Cversion)%0A)by(status)&amp;g2.tab=1&amp;g2.stacked=0&amp;g2.range_input=1h" rel="nofollow noreferrer">demo</a>.</p>
