From 799314fc4c17271ea6a976d41b8ac6d2132d8a42 Mon Sep 17 00:00:00 2001 From: Swen Kooij Date: Wed, 2 Feb 2022 10:22:26 +0200 Subject: [PATCH] Include vhost for RabbitMQ when retrieving queue info with useRegex The vhost is included when you don't use `useRegex: true`. It makes sense to have consistent behaviour between the two modes. Fixes #2498 --- pkg/scalers/rabbitmq_scaler.go | 2 +- pkg/scalers/rabbitmq_scaler_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/scalers/rabbitmq_scaler.go b/pkg/scalers/rabbitmq_scaler.go index 8eee88ee62a..07971f82c74 100644 --- a/pkg/scalers/rabbitmq_scaler.go +++ b/pkg/scalers/rabbitmq_scaler.go @@ -426,7 +426,7 @@ func (s *rabbitMQScaler) getQueueInfoViaHTTP() (*queueInfo, error) { parsedURL.Path = "" var getQueueInfoManagementURI string if s.metadata.useRegex { - getQueueInfoManagementURI = fmt.Sprintf("%s/api/queues?page=1&use_regex=true&pagination=false&name=%s&page_size=%d", parsedURL.String(), url.QueryEscape(s.metadata.queueName), s.metadata.pageSize) + getQueueInfoManagementURI = fmt.Sprintf("%s/api/queues%s?page=1&use_regex=true&pagination=false&name=%s&page_size=%d", parsedURL.String(), vhost, url.QueryEscape(s.metadata.queueName), s.metadata.pageSize) } else { getQueueInfoManagementURI = fmt.Sprintf("%s/api/queues%s/%s", parsedURL.String(), vhost, url.QueryEscape(s.metadata.queueName)) } diff --git a/pkg/scalers/rabbitmq_scaler_test.go b/pkg/scalers/rabbitmq_scaler_test.go index d41dc3feef6..ea8b6ba60fc 100644 --- a/pkg/scalers/rabbitmq_scaler_test.go +++ b/pkg/scalers/rabbitmq_scaler_test.go @@ -328,7 +328,7 @@ var testRegexQueueInfoTestData = []getQueueInfoTestData{ func TestGetQueueInfoWithRegex(t *testing.T) { for _, testData := range testRegexQueueInfoTestData { var apiStub = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - expectedPath := "/api/queues?page=1&use_regex=true&pagination=false&name=%5Eevaluate_trials%24&page_size=100" + expectedPath := fmt.Sprintf("/api/queues%s?page=1&use_regex=true&pagination=false&name=%5Eevaluate_trials%24&page_size=100", testData.vhostPath) if r.RequestURI != expectedPath { t.Error("Expect request path to =", expectedPath, "but it is", r.RequestURI) } @@ -399,7 +399,7 @@ var testRegexPageSizeTestData = []getRegexPageSizeTestData{ func TestGetPageSizeWithRegex(t *testing.T) { for _, testData := range testRegexPageSizeTestData { var apiStub = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - expectedPath := fmt.Sprintf("/api/queues?page=1&use_regex=true&pagination=false&name=%%5Eevaluate_trials%%24&page_size=%d", testData.pageSize) + expectedPath := fmt.Sprintf("/api/queues%s?page=1&use_regex=true&pagination=false&name=%%5Eevaluate_trials%%24&page_size=%d", testData.vhostPath, testData.pageSize) if r.RequestURI != expectedPath { t.Error("Expect request path to =", expectedPath, "but it is", r.RequestURI) } @@ -521,7 +521,7 @@ var testRegexQueueInfoNavigationTestData = []getQueueInfoNavigationTestData{ func TestRegexQueueMissingError(t *testing.T) { for _, testData := range testRegexQueueInfoNavigationTestData { var apiStub = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - expectedPath := "/api/queues?page=1&use_regex=true&pagination=false&name=evaluate_trials&page_size=100" + expectedPath := fmt.Sprintf("/api/queues%s?page=1&use_regex=true&pagination=false&name=evaluate_trials&page_size=100", testData.vhostPath) if r.RequestURI != expectedPath { t.Error("Expect request path to =", expectedPath, "but it is", r.RequestURI) }