<p>I have this use case:</p>
<blockquote>
<p>When there is much load on a specific queue in RabbitMQ, i want to start more replicas. Let's say, my app can handle 5 messages ( = tasks) simultaneously and they all take 1 min to complete. When there are more than 10 &quot;ready&quot; messages in the rabbitmq Queue, i want the HPA to start a new replica. When there are 20 &quot;ready&quot; messages, start 2, at 30 &quot;ready&quot; messages start 3 etc.</p>
</blockquote>
<p>I used this helm chart for install prometheus-adapter:</p>
<p><a href="https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-adapter" rel="nofollow noreferrer">https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-adapter</a></p>
<p>And in my helm values yaml i added:</p>
<pre class="lang-yaml prettyprint-override"><code>rules:
  default: true

  custom:
    - seriesQuery: '{__name__=~&quot;rabbitmq_detailed_queue_messages_ready&quot;}'
      name:
        matches: &quot;^(.*)&quot;
        as: &quot;open_tasks&quot;
      resources:
        overrides:
          kubernetes_namespace: { resource: &quot;namespace&quot; }
          kubernetes_name: { resource: &quot;service&quot; }
      metricsQuery: sum(&lt;&lt;.Series&gt;&gt;{&lt;&lt;.LabelMatchers&gt;&gt;,queue=&quot;my-task-queue&quot;}) by (&lt;&lt;.GroupBy&gt;&gt;)
</code></pre>
<p>Now, this should be exposed, but it isn't:</p>
<pre class="lang-bash prettyprint-override"><code>$ kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1 | jq . | grep open_tasks

</code></pre>
<p>Now this is my main question. After that i could deploy an HPA for my app <code>task-processor</code> like this:</p>
<pre class="lang-yaml prettyprint-override"><code>kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2
metadata:
  name: task-processor-autoscaler
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: task-processor
  minReplicas: 1
  maxReplicas: 10
  metrics:
    - type: Object
      object:
        metric:
          name: open_tasks
        describedObject:
          apiVersion: &quot;/v1&quot;
          kind: Service
          name: open_tasks
        target:
          type: Value
          value: 10
</code></pre>
<p>Now my questions:</p>
<ol>
<li>Why is the metric not exposed in the raw query?</li>
<li>Is my yaml for the HPA correct? I have the feeling that i'm missing some essential stuff here, but i'm not able to get my head around that.</li>
</ol>

<p>Your use case is essentially autoscaling based on RabbitMQ queue length, which is a bit challenging due to the limitations of the native Kubernetes HPA controller, as it &quot;typically&quot; autoscale based on CPU and memory usage.</p>
<p><strong>Alternatively, you may consider utilizing <a href="https://keda.sh/docs/2.10/concepts" rel="nofollow noreferrer">KEDA</a></strong> (Kubernetes Event-Driven Autoscaling):</p>
<p>KEDA is a Kubernetes-based event-driven autoscaler. With KEDA, you can drive the scaling of any deployment based on the various criteria (depends on the scaler adapter). It supports <a href="https://keda.sh/docs/2.10/scalers/rabbitmq-queue" rel="nofollow noreferrer">RabbitMQ</a>, which makes it particularly suitable for your case.</p>
<p>Here's a sample <code>ScaledObject</code> for your case:</p>
<pre><code>apiVersion: keda.sh/v1alpha1
kind: ScaledObject
spec:
  scaleTargetRef:
    apiVersion: apps/v1 # Optional (default: apps/v1)
    kind: Deployment
    name: task-processor
  triggers:
  - type: rabbitmq
    metadata:
      queueName: 'my-task-queue'
      mode: QueueLength # Trigger on number of messages in the queue.
      value: '5'  # Target number of tasks per pod.
</code></pre>
