<p>I am setting up HPA on custom metrics - basically on no. of threads of a deployment.</p>
<p>I have created a PrometheusRule to get average of threads (5 min. based). On the container, I am doing cont. load to increase the threads and average value is also going high.</p>
<p>I started with 2 replicas and when current value is crossing the target value, am not seeing my deployment scaling out.</p>
<p>As you can see, have set target as 44 and current value is 51.55 for more than 10 min but still no scale up.
<a href="https://i.stack.imgur.com/Uo6No.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uo6No.png" alt="enter image description here" /></a></p>
<p><strong>Version Info</strong></p>
<ul>
<li>Kubernetes (AKS) : 1.19.11</li>
<li>Prometheus : 2.22.1</li>
<li>Setup done via prometheus-operator (0.7)</li>
<li>Autoscaling api version : autoscaling/v2beta2</li>
</ul>
<p><strong>Prometheus Rule</strong></p>
<pre><code>apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: rdp-rest
  namespace: default   
  labels:
    app.kubernetes.io/name: node-exporter
    app.kubernetes.io/version: 1.0.1
    prometheus: k8s
    role: alert-rules
    run: rdp-rest
    app: rdp-rest
spec:
  groups:
  - name: hpa-rdp-rest
    interval: 10s
    rules:
    - expr: 'avg_over_time(container_threads{container=&quot;rdp-rest&quot;}[5m])'
      record: hpa_custom_metrics_container_threads_rdp_rest
      labels:
        service: rdp-rest
</code></pre>
<p><strong>Manifests</strong> - <a href="https://github.com/prometheus-operator/kube-prometheus/tree/release-0.7/manifests" rel="nofollow noreferrer">https://github.com/prometheus-operator/kube-prometheus/tree/release-0.7/manifests</a></p>
<p><strong>Update (6th July)</strong> - HPA with custom metrics is working fine for any other technology like nodejs/ngnix, etc. but not working for netty api</p>
<p>Any thoughts?</p>

<p>Finally after a week, found the root cause.</p>
<p>So the issue was with the label. I had 2 deployments with same label. So what internal hpa is doing is it's getting stats for all the pods with that label and then doing scale up/down. As soon as I corrected the labels, hpa worked as expected.</p>
<p>But the same on prometheus UI shows stats for ONLY one type of pods.
Looks like some internal bug or something. Not getting when we provide name why it's going and fetching stats based on label.</p>
<p>Point to remember : Always double check your labels.</p>
