Skip to content

Instantly share code, notes, and snippets.

@wirwolf
Last active September 7, 2022 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wirwolf/87a7482ac87cf7fd08eeb28051c87a27 to your computer and use it in GitHub Desktop.
Save wirwolf/87a7482ac87cf7fd08eeb28051c87a27 to your computer and use it in GitHub Desktop.
hpa
{{/* vim: set filetype=mustache: */}}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "workers.hpa_metric_name" -}}
{{- printf "%s-%s" .Release.Namespace .Release.Name | replace "+" "_" | replace "-" "_" | trunc 63 -}}
{{- end -}}
{{ if (eq $.Values.autoscaling.enabled true) }}
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: {{ $.Release.Name }}
namespace: {{ $.Release.Namespace }}
spec:
groups:
- name: {{ $.Release.Name }}-queue-size # Define the name of your rule
rules:
- record: {{ include "workers.hpa_metric_name" . }}_messages_waiting_in_queue_name # The name of the metrics you want
expr: rabbitmq_queue_messages{queue="{{ $.Values.autoscaling.rabbitmq.queue }}", vhost="{{ $.Values.autoscaling.rabbitmq.vhost }}", namespace="{{ $.Values.autoscaling.rabbitmq.namespace }}" } # Query to make to prometheus
labels:
namespace: {{ $.Release.Namespace }}
---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: {{ $.Release.Name }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ $.Release.Name }}
minReplicas: {{ $.Values.autoscaling.minReplicas }}
maxReplicas: {{ $.Values.autoscaling.maxReplicas }}
metrics:
- type: Object
object:
metric:
name: {{ include "workers.hpa_metric_name" . }}_messages_waiting_in_queue_name
describedObject:
apiVersion: v1
kind: Namespace
name: {{ $.Release.Namespace }}
target:
type: Value
value: {{ $.Values.autoscaling.rabbitmq.value }}
{{- end }}
autoscaling:
enabled: true
rabbitmq:
vhost: "/"
queue: "test"
namespace: "test"
value: 1
minReplicas: 1
maxReplicas: 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment