Skip to content

Commit

Permalink
Fix RabbitMQ Scaler, allow subpaths along with vhost in connection st…
Browse files Browse the repository at this point in the history
…ring (#4584)

* fix RabbitMQ Scaler, allow subpaths along with vhost in connection string (#4584)

Signed-off-by: Roman Bielyi <romanbielyi.amor@gmail.com>

* Fix CHANGELOG.md, remove redundant/wrong pieces that were made during rebase, this fix is aimed to resolve failed workflow's Static Check (validate-changelog) test

Signed-off-by: Roman Bielyi <romanbielyi.amor@gmail.com>

---------

Signed-off-by: Roman Bielyi <romanbielyi.amor@gmail.com>
  • Loading branch information
AmorBielyi committed Sep 5, 2023
1 parent acebbfb commit 0386b17
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 131 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio
- **Azure Pod Identity**: Introduce validation to prevent usage of empty identity ID for Azure identity providers ([#4528](https://github.com/kedacore/keda/issues/4528))

### Fixes
- **RabbitMQ Scaler**: Allow subpaths along with vhost in connection string ([#2634](https://github.com/kedacore/keda/issues/2634))
- **Selenium Grid Scaler**: Fix latest browser version use case scaling ([#4858](https://github.com/kedacore/keda/issues/4858))
- **Solace Scaler**: Fix a bug where `queueName` is not properly escaped during URL encode ([#4936](https://github.com/kedacore/keda/issues/4936))

Expand Down
34 changes: 21 additions & 13 deletions pkg/scalers/rabbitmq_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"net/url"
"path"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -545,26 +546,33 @@ func getJSON(ctx context.Context, s *rabbitMQScaler, url string) (queueInfo, err
return result, fmt.Errorf("error requesting rabbitMQ API status: %s, response: %s, from: %s", r.Status, body, url)
}

func (s *rabbitMQScaler) getQueueInfoViaHTTP(ctx context.Context) (*queueInfo, error) {
parsedURL, err := url.Parse(s.metadata.host)
func getVhostAndPathFromURL(rawPath, vhostName string) (resolvedVhostPath, resolvedPath string) {
pathParts := strings.Split(rawPath, "/")
resolvedVhostPath = "/" + pathParts[len(pathParts)-1]
resolvedPath = path.Join(pathParts[:len(pathParts)-1]...)

if err != nil {
return nil, err
if len(resolvedPath) > 0 {
resolvedPath = "/" + resolvedPath
}
if vhostName != "" {
resolvedVhostPath = "/" + url.QueryEscape(vhostName)
}
if resolvedVhostPath == "" || resolvedVhostPath == "/" || resolvedVhostPath == "//" {
resolvedVhostPath = rabbitRootVhostPath
}

// Extract vhost from URL's path.
vhost := parsedURL.Path
return
}

if s.metadata.vhostName != "" {
vhost = "/" + url.QueryEscape(s.metadata.vhostName)
}
func (s *rabbitMQScaler) getQueueInfoViaHTTP(ctx context.Context) (*queueInfo, error) {
parsedURL, err := url.Parse(s.metadata.host)

if vhost == "" || vhost == "/" || vhost == "//" {
vhost = rabbitRootVhostPath
if err != nil {
return nil, err
}

// Clear URL path to get the correct host.
parsedURL.Path = ""
vhost, subpaths := getVhostAndPathFromURL(parsedURL.Path, s.metadata.vhostName)
parsedURL.Path = subpaths

var getQueueInfoManagementURI string
if s.metadata.useRegex {
Expand Down
Loading

0 comments on commit 0386b17

Please sign in to comment.