<p>I am currently trying to set up an horizontal pod autoscaler for my application running inside Kubernetes. The HPA is relying on external metrics that are fetched from Prometheus by a Prometheus adapter (<a href="https://github.com/kubernetes-sigs/prometheus-adapter" rel="nofollow noreferrer">https://github.com/kubernetes-sigs/prometheus-adapter</a>).</p>
<p>The metrics are fetched by the adapter and made available to the Kubernetes metrics API successfully, but the metricLabels map is empty, making it impossible for the HPA to associate the correct metrics with the correct pod.</p>
<p>Eg. of a query to the metrics API</p>
<pre><code>kubectl get --raw &quot;/apis/external.metrics.k8s.io/v1beta1/namespaces/&lt;namespace&gt;/batchCommandsActive_totalCount/&quot;

{&quot;kind&quot;:&quot;ExternalMetricValueList&quot;,&quot;apiVersion&quot;:&quot;external.metrics.k8s.io/v1beta1&quot;,&quot;metadata&quot;:{},&quot;items&quot;:[{&quot;metricName&quot;:&quot;batchCommandsActive_totalCount&quot;,**&quot;metricLabels&quot;:{}**,&quot;timestamp&quot;:&quot;2023-02-10T11:38:48Z&quot;,&quot;value&quot;:&quot;0&quot;}]}
</code></pre>
<p>Those metrics should have three labels associated to them (hostname, localnode and path) in order for the correct pod to retrieve them.</p>
<p>Here is an extract of the Prometheus adapter configmap that defines the queries made to Prometheus by the Prometheus adapter</p>
<pre><code>    - seriesQuery: '{__name__=&quot;batchCommandsActive_totalCount&quot;,hostname!=&quot;&quot;,localnode!=&quot;&quot;,path!=&quot;&quot;}'
      metricsQuery: sum(&lt;&lt;.Series&gt;&gt;{&lt;&lt;.LabelMatchers&gt;&gt;}) by (name)
      resources:
        namespaced: false
</code></pre>
<p>Thanks for your help!</p>
<p>So far, no answer from StackOverflow or tutorial (eg. <a href="https://github.com/kubernetes-sigs/prometheus-adapter/blob/master/docs/walkthrough.md" rel="nofollow noreferrer">https://github.com/kubernetes-sigs/prometheus-adapter/blob/master/docs/walkthrough.md</a>) have helped with my problem.</p>

Agilulfe
<p>I've found the answer to my own question. Here it is for those of you who might have the same problem.</p>
<p>The metrics in Prometheus and the Kubernetes metrics API were using camel casing (eg. sessionTotal). Even though those naming were used in the HorizontalPodAutoscaler definition, HPA was lowercasing behind the scene the metrics name (sessionTotal -&gt; sessiontotal) resulting in 404 response by the metrics API.</p>
<p>Be therefore aware of this issue in case you use camel case for your metrics names</p>
