From 569dcbacd16ee4f7bceeb22db6b4acfebf6aed4a Mon Sep 17 00:00:00 2001 From: SWINDI Date: Sat, 8 Jun 2019 19:25:41 +0200 Subject: [PATCH 1/2] add vhost support --- README.md | 2 +- autoscale.sh | 4 ++-- deploy.yml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 95ce14f..dc739e8 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ This Pod runs in the `kube-system` namespace on k8s master nodes. - `RABBIT_USER`: Username used for authentication with the RabbitMQ API (check `deploy.yml`, defaults to `rabbit-pod-autoscaler` secret, `rabbit-user` key) - `RABBIT_PASS`: Password used for authentication with the RabbitMQ API (check `deploy.yml`, defaults to `rabbit-pod-autoscaler` secret, `rabbit-pass` key) - `AUTOSCALING`: Contains min/max pods, messages handled per pod, deployment info and queue name in the following pattern: - - single deployment to autoscale: `|||||` + - single deployment to autoscale: `||||||` - e.g. `3|10|5|development|example|example.queue` - `mesgPerPod` represents the amount of RabbitMQ messages a Pod can process within the `INTERVAL` (env var). As an example, if a Pod needs 6s to process a message from RabbitMQ, the `mesgPerPod` value will be `INTERVAL (30s) / process time (6s) = 5`. - multiple deployments to autoscale: check example `deploy.yml` diff --git a/autoscale.sh b/autoscale.sh index 619552a..69b711a 100644 --- a/autoscale.sh +++ b/autoscale.sh @@ -33,10 +33,10 @@ IFS=';' read -ra autoscalingArr <<< "$autoscalingNoWS" while true; do for autoscaler in "${autoscalingArr[@]}"; do - IFS='|' read minPods maxPods mesgPerPod namespace deployment queueName <<< "$autoscaler" + IFS='|' read minPods maxPods mesgPerPod namespace deployment vhostName queueName <<< "$autoscaler" queueMessagesJson=$(curl -s -S --retry 3 --retry-delay 3 -u $RABBIT_USER:$RABBIT_PASS \ - $RABBIT_HOST:15672/api/queues/%2f/$queueName) + $RABBIT_HOST:15672/api/queues/$vhostName/$queueName) if [[ $? -eq 0 ]]; then queueMessages=$(echo $queueMessagesJson | jq '.messages') diff --git a/deploy.yml b/deploy.yml index c225150..0627fc7 100644 --- a/deploy.yml +++ b/deploy.yml @@ -70,8 +70,8 @@ spec: key: rabbit-pass - name: AUTOSCALING value: > - 3|10|5|development|example|example.queue; - 3|5|3|development|example2|example2.queue + 3|10|5|development|example|vhost|example.queue; + 3|5|3|development|example2|vhost|example2.queue - name: LOGS value: HIGH - name: SLACK_HOOK From 9be3e1fe510cd54b8689b7c42a4bac24093fee7f Mon Sep 17 00:00:00 2001 From: SWINDI Date: Sat, 8 Jun 2019 19:36:55 +0200 Subject: [PATCH 2/2] add vhost support --- README.md | 4 ++-- autoscale.sh | 4 +++- deploy.yml | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dc739e8..afd6a7e 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ This Pod runs in the `kube-system` namespace on k8s master nodes. - `RABBIT_USER`: Username used for authentication with the RabbitMQ API (check `deploy.yml`, defaults to `rabbit-pod-autoscaler` secret, `rabbit-user` key) - `RABBIT_PASS`: Password used for authentication with the RabbitMQ API (check `deploy.yml`, defaults to `rabbit-pod-autoscaler` secret, `rabbit-pass` key) - `AUTOSCALING`: Contains min/max pods, messages handled per pod, deployment info and queue name in the following pattern: - - single deployment to autoscale: `||||||` - - e.g. `3|10|5|development|example|example.queue` + - single deployment to autoscale: `||||||` + - e.g. `3|10|5|development|example|example.queue|rabbitmq.vhost` - `mesgPerPod` represents the amount of RabbitMQ messages a Pod can process within the `INTERVAL` (env var). As an example, if a Pod needs 6s to process a message from RabbitMQ, the `mesgPerPod` value will be `INTERVAL (30s) / process time (6s) = 5`. - multiple deployments to autoscale: check example `deploy.yml` - `LOGS`: Logging and Slack notifications intensity. Errors are logged and notified on every option diff --git a/autoscale.sh b/autoscale.sh index 69b711a..c12d20d 100644 --- a/autoscale.sh +++ b/autoscale.sh @@ -33,7 +33,9 @@ IFS=';' read -ra autoscalingArr <<< "$autoscalingNoWS" while true; do for autoscaler in "${autoscalingArr[@]}"; do - IFS='|' read minPods maxPods mesgPerPod namespace deployment vhostName queueName <<< "$autoscaler" + IFS='|' read minPods maxPods mesgPerPod namespace deployment queueName vhostName <<< "$autoscaler" + + vhostName=${vhostName:-"%2f"} queueMessagesJson=$(curl -s -S --retry 3 --retry-delay 3 -u $RABBIT_USER:$RABBIT_PASS \ $RABBIT_HOST:15672/api/queues/$vhostName/$queueName) diff --git a/deploy.yml b/deploy.yml index 0627fc7..904d194 100644 --- a/deploy.yml +++ b/deploy.yml @@ -70,8 +70,8 @@ spec: key: rabbit-pass - name: AUTOSCALING value: > - 3|10|5|development|example|vhost|example.queue; - 3|5|3|development|example2|vhost|example2.queue + 3|10|5|development|example|example.queue|vhost; + 3|5|3|development|example2|example2.queue|vhost - name: LOGS value: HIGH - name: SLACK_HOOK