diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f61d750aed..0e348b8496f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ - **General:** Properly handle `restoreToOriginalReplicaCount` if `ScaleTarget` is missing ([#2872](https://github.com/kedacore/keda/issues/2872)) - **General:** Synchronize HPA annotations from ScaledObject ([#2659](https://github.com/kedacore/keda/pull/2659)) - **General:** Updated HTTPClient to be proxy-aware, if available, from environment variables. ([#2577](https://github.com/kedacore/keda/issues/2577)) +- **ActiveMQ Scaler:** Add CorsHeader information to ActiveMQ Scaler ([#2884](https://github.com/kedacore/keda/issues/2884)) - **Azure Application Insights Scaler:** Provide support for non-public clouds ([#2735](https://github.com/kedacore/keda/issues/2735)) - **Azure Blob Storage Scaler:** Add optional parameters for counting blobs recursively ([#1789](https://github.com/kedacore/keda/issues/1789)) - **Azure Event Hub Scaler:** Improve logging when blob container not found ([#2363](https://github.com/kedacore/keda/issues/2363)) diff --git a/pkg/scalers/activemq_scaler.go b/pkg/scalers/activemq_scaler.go index 31a68012f21..94913e9cae9 100644 --- a/pkg/scalers/activemq_scaler.go +++ b/pkg/scalers/activemq_scaler.go @@ -36,6 +36,7 @@ type activeMQMetadata struct { password string restAPITemplate string targetQueueSize int64 + corsHeader string metricName string scalerIndex int } @@ -123,6 +124,12 @@ func parseActiveMQMetadata(config *ScalerConfig) (*activeMQMetadata, error) { } } + if val, ok := config.TriggerMetadata["corsHeader"]; ok && val != "" { + meta.corsHeader = config.TriggerMetadata["corsHeader"] + } else { + meta.corsHeader = fmt.Sprintf(defaultCorsHeader, meta.managementEndpoint) + } + if meta.username == "" { return nil, fmt.Errorf("username cannot be empty") } @@ -225,6 +232,7 @@ func (s *activeMQScaler) getQueueMessageCount(ctx context.Context) (int64, error // Add HTTP Auth and Headers req.SetBasicAuth(s.metadata.username, s.metadata.password) req.Header.Set("Content-Type", "application/json") + req.Header.Set("Origin", s.metadata.corsHeader) resp, err := client.Do(req) if err != nil { diff --git a/pkg/scalers/activemq_scaler_test.go b/pkg/scalers/activemq_scaler_test.go index 46cbabbddee..9ede3b5c409 100644 --- a/pkg/scalers/activemq_scaler_test.go +++ b/pkg/scalers/activemq_scaler_test.go @@ -202,6 +202,30 @@ var testActiveMQMetadata = []parseActiveMQMetadataTestData{ }, } +func TestActiveMQDefaultCorsHeader(t *testing.T) { + metadata := map[string]string{"managementEndpoint": "localhost:8161", "destinationName": "queue1", "brokerName": "broker-activemq", "username": "myUserName", "password": "myPassword"} + meta, err := parseActiveMQMetadata(&ScalerConfig{TriggerMetadata: metadata, AuthParams: nil}) + + if err != nil { + t.Error("Expected success but got error", err) + } + if !(meta.corsHeader == "http://localhost:8161") { + t.Errorf("Expected http://localhost:8161 but got %s", meta.corsHeader) + } +} + +func TestActiveMQCorsHeader(t *testing.T) { + metadata := map[string]string{"managementEndpoint": "localhost:8161", "destinationName": "queue1", "brokerName": "broker-activemq", "username": "myUserName", "password": "myPassword", "corsHeader": "test"} + meta, err := parseActiveMQMetadata(&ScalerConfig{TriggerMetadata: metadata, AuthParams: nil}) + + if err != nil { + t.Error("Expected success but got error", err) + } + if !(meta.corsHeader == "test") { + t.Errorf("Expected test but got %s", meta.corsHeader) + } +} + func TestParseActiveMQMetadata(t *testing.T) { for _, testData := range testActiveMQMetadata { t.Run(testData.name, func(t *testing.T) {