Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support path prefix in RabbitMQ scaler host URI #4589

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pkg/scalers/rabbitmq_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,15 @@ func getConnectionAndChannel(host string, meta *rabbitMQMetadata) (*amqp.Connect
return conn, channel, nil
}

// Get path prefix and vhost from RabbitMQ host Url path
func getPathPrefixAndVhostFromURLPath(urlPath string) (string, string) {
// Extract vhost and prefix from URL's path.
parts := strings.Split(urlPath, "/")
prefix := strings.Join(parts[0:len(parts)-1], "/")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you want path.Join() or filepath.Join()?

Ignore this finding from use-strings-join-path.

vhost := "/" + parts[len(parts)-1]
return prefix, vhost
}

// Close disposes of RabbitMQ connections
func (s *rabbitMQScaler) Close(context.Context) error {
if s.connection != nil {
Expand Down Expand Up @@ -488,8 +497,8 @@ func (s *rabbitMQScaler) getQueueInfoViaHTTP() (*queueInfo, error) {
return nil, err
}

// Extract vhost from URL's path.
vhost := parsedURL.Path
// Extract prefix and vhost from URL's path.
prefix, vhost := getPathPrefixAndVhostFromURLPath(parsedURL.Path)

if s.metadata.vhostName != "" {
vhost = "/" + url.QueryEscape(s.metadata.vhostName)
Expand All @@ -500,7 +509,7 @@ func (s *rabbitMQScaler) getQueueInfoViaHTTP() (*queueInfo, error) {
}

// Clear URL path to get the correct host.
parsedURL.Path = ""
parsedURL.Path = prefix

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