diff --git a/CHANGELOG.md b/CHANGELOG.md index 7165322d60f..4372aea58f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ Here is an overview of all new **experimental** features: - **General**: Fix CVE-2023-39325 in golang.org/x/net ([#5122](https://github.com/kedacore/keda/issues/5122)) - **General**: Prevented stuck status due to timeouts during scalers generation ([#5083](https://github.com/kedacore/keda/issues/5083)) - **Azure Pipelines**: No more HTTP 400 errors produced by poolName with spaces ([#5107](https://github.com/kedacore/keda/issues/5107)) +- **GCP pubsub scaler**: Missing use of default value of `value` added ([#5093](https://github.com/kedacore/keda/issues/5093)) - **ScaledJobs**: Copy ScaledJob annotations to child Jobs ([#4594](https://github.com/kedacore/keda/issues/4594)) ### Deprecations diff --git a/pkg/scalers/gcp_pubsub_scaler.go b/pkg/scalers/gcp_pubsub_scaler.go index 5a3c2cd9da5..6aa56adf559 100644 --- a/pkg/scalers/gcp_pubsub_scaler.go +++ b/pkg/scalers/gcp_pubsub_scaler.go @@ -65,7 +65,7 @@ func NewPubSubScaler(config *ScalerConfig) (Scaler, error) { func parsePubSubMetadata(config *ScalerConfig, logger logr.Logger) (*pubsubMetadata, error) { // set subscription size to the default mode - meta := pubsubMetadata{mode: pubSubModeSubscriptionSize} + meta := pubsubMetadata{mode: pubSubModeSubscriptionSize, value: pubSubDefaultValue} mode, modePresent := config.TriggerMetadata["mode"] value, valuePresent := config.TriggerMetadata["value"] @@ -83,7 +83,6 @@ func parsePubSubMetadata(config *ScalerConfig, logger logr.Logger) (*pubsubMetad } else { if modePresent { meta.mode = mode - meta.value = pubSubDefaultValue } if valuePresent { diff --git a/pkg/scalers/gcp_pubsub_scaler_test.go b/pkg/scalers/gcp_pubsub_scaler_test.go index 2b4d724a49f..19ddbf7abfc 100644 --- a/pkg/scalers/gcp_pubsub_scaler_test.go +++ b/pkg/scalers/gcp_pubsub_scaler_test.go @@ -58,6 +58,10 @@ var testPubSubMetadata = []parsePubSubMetadataTestData{ {nil, map[string]string{"subscriptionName": "projects/myproject/mysubscription", "subscriptionSize": "7", "credentialsFromEnv": "SAMPLE_CREDS"}, false}, // properly formed float value and activationTargetValue {nil, map[string]string{"subscriptionName": "mysubscription", "value": "7.1", "credentialsFromEnv": "SAMPLE_CREDS", "activationValue": "2.1"}, false}, + // All optional omitted + {nil, map[string]string{"subscriptionName": "mysubscription", "credentialsFromEnv": "SAMPLE_CREDS"}, false}, + // value omittted when mode present + {nil, map[string]string{"subscriptionName": "mysubscription", "mode": "SubscriptionSize", "credentialsFromEnv": "SAMPLE_CREDS"}, false}, } var gcpPubSubMetricIdentifiers = []gcpPubSubMetricIdentifier{ @@ -70,6 +74,11 @@ var gcpSubscriptionNameTests = []gcpPubSubSubscription{ {&testPubSubMetadata[12], 1, "projects/myproject/mysubscription", ""}, } +var gcpSubscriptionDefaults = []gcpPubSubSubscription{ + {&testPubSubMetadata[14], 0, "", ""}, + {&testPubSubMetadata[15], 0, "", ""}, +} + func TestPubSubParseMetadata(t *testing.T) { for _, testData := range testPubSubMetadata { _, err := parsePubSubMetadata(&ScalerConfig{AuthParams: testData.authParams, TriggerMetadata: testData.metadata, ResolvedEnv: testPubSubResolvedEnv}, logr.Discard()) @@ -82,6 +91,21 @@ func TestPubSubParseMetadata(t *testing.T) { } } +func TestPubSubMetadataDefaultValues(t *testing.T) { + for _, testData := range gcpSubscriptionDefaults { + metaData, err := parsePubSubMetadata(&ScalerConfig{AuthParams: testData.metadataTestData.authParams, TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testPubSubResolvedEnv}, logr.Discard()) + if err != nil { + t.Error("Expected success but got error", err) + } + if pubSubModeSubscriptionSize != metaData.mode { + t.Errorf(`Expected mode "%s" but got "%s"`, pubSubModeSubscriptionSize, metaData.mode) + } + if pubSubDefaultValue != metaData.value { + t.Errorf(`Expected value "%d" but got "%f"`, pubSubDefaultValue, metaData.value) + } + } +} + func TestGcpPubSubGetMetricSpecForScaling(t *testing.T) { for _, testData := range gcpPubSubMetricIdentifiers { meta, err := parsePubSubMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testPubSubResolvedEnv, ScalerIndex: testData.scalerIndex}, logr.Discard())