diff --git a/pkg/scalers/azure_blob_scaler.go b/pkg/scalers/azure_blob_scaler.go index f8b0dfb23ae..cf0a1bf9e2a 100644 --- a/pkg/scalers/azure_blob_scaler.go +++ b/pkg/scalers/azure_blob_scaler.go @@ -48,14 +48,14 @@ type azureBlobScaler struct { } type azureBlobMetadata struct { - targetBlobCount int - blobContainerName string - blobDelimiter string - blobPrefix string - connection string - accountName string - metricName string - endpointSuffix string + targetBlobCount int + blobContainerName string + blobDelimiter string + blobPrefix string + connection string + accountName string + externalMetricName string + endpointSuffix string } var azureBlobLog = logf.Log.WithName("azure_blob_scaler") @@ -117,15 +117,18 @@ func parseAzureBlobMetadata(config *ScalerConfig) (*azureBlobMetadata, kedav1alp } if val, ok := config.TriggerMetadata["metricName"]; ok { - meta.metricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-blob", val)) + meta.externalMetricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-blob", val)) } else { if meta.blobPrefix != "" { - meta.metricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s", "azure-blob", meta.blobContainerName, meta.blobPrefix)) + meta.externalMetricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s", "azure-blob", meta.blobContainerName, meta.blobPrefix)) } else { - meta.metricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-blob", meta.blobContainerName)) + meta.externalMetricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-blob", meta.blobContainerName)) } } + // Update externalMetricName with the index + meta.externalMetricName = GenerateMetricNameWithIndex(config, meta.externalMetricName) + // If the Use AAD Pod Identity is not present, or set to "none" // then check for connection string switch config.PodIdentity { @@ -185,7 +188,7 @@ func (s *azureBlobScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec { targetBlobCount := resource.NewQuantity(int64(s.metadata.targetBlobCount), resource.DecimalSI) externalMetric := &v2beta2.ExternalMetricSource{ Metric: v2beta2.MetricIdentifier{ - Name: s.metadata.metricName, + Name: s.metadata.externalMetricName, }, Target: v2beta2.MetricTarget{ Type: v2beta2.AverageValueMetricType, diff --git a/pkg/scalers/azure_blob_scaler_test.go b/pkg/scalers/azure_blob_scaler_test.go index a3585f073f4..4164a925846 100644 --- a/pkg/scalers/azure_blob_scaler_test.go +++ b/pkg/scalers/azure_blob_scaler_test.go @@ -37,6 +37,7 @@ type parseAzBlobMetadataTestData struct { type azBlobMetricIdentifier struct { metadataTestData *parseAzBlobMetadataTestData + scalerIndex int name string } @@ -72,9 +73,9 @@ var testAzBlobMetadata = []parseAzBlobMetadataTestData{ } var azBlobMetricIdentifiers = []azBlobMetricIdentifier{ - {&testAzBlobMetadata[1], "azure-blob-sample-blobsubpath-"}, - {&testAzBlobMetadata[2], "azure-blob-customname"}, - {&testAzBlobMetadata[5], "azure-blob-sample_container"}, + {&testAzBlobMetadata[1], 0, "s0-azure-blob-sample-blobsubpath-"}, + {&testAzBlobMetadata[2], 1, "s1-azure-blob-customname"}, + {&testAzBlobMetadata[5], 2, "s2-azure-blob-sample_container"}, } func TestAzBlobParseMetadata(t *testing.T) { @@ -94,7 +95,7 @@ func TestAzBlobParseMetadata(t *testing.T) { func TestAzBlobGetMetricSpecForScaling(t *testing.T) { for _, testData := range azBlobMetricIdentifiers { - meta, podIdentity, err := parseAzureBlobMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, PodIdentity: testData.metadataTestData.podIdentity}) + meta, podIdentity, err := parseAzureBlobMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, PodIdentity: testData.metadataTestData.podIdentity, Index: testData.scalerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/azure_eventhub_scaler.go b/pkg/scalers/azure_eventhub_scaler.go index c281477c1fb..a6470f3a24e 100644 --- a/pkg/scalers/azure_eventhub_scaler.go +++ b/pkg/scalers/azure_eventhub_scaler.go @@ -56,8 +56,9 @@ type azureEventHubScaler struct { } type eventHubMetadata struct { - eventHubInfo azure.EventHubInfo - threshold int64 + eventHubInfo azure.EventHubInfo + threshold int64 + externalMetricName string } // NewAzureEventHubScaler creates a new scaler for eventHub @@ -152,6 +153,11 @@ func parseAzureEventHubMetadata(config *ScalerConfig) (*eventHubMetadata, error) } } + meta.externalMetricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s", "azure-eventhub", meta.eventHubInfo.EventHubConnection, meta.eventHubInfo.EventHubConsumerGroup)) + + // Update externalMetricName with the index + meta.externalMetricName = GenerateMetricNameWithIndex(config, meta.externalMetricName) + return &meta, nil } @@ -252,7 +258,7 @@ func (scaler *azureEventHubScaler) GetMetricSpecForScaling() []v2beta2.MetricSpe targetMetricVal := resource.NewQuantity(scaler.metadata.threshold, resource.DecimalSI) externalMetric := &v2beta2.ExternalMetricSource{ Metric: v2beta2.MetricIdentifier{ - Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s", "azure-eventhub", scaler.metadata.eventHubInfo.EventHubConnection, scaler.metadata.eventHubInfo.EventHubConsumerGroup)), + Name: scaler.metadata.externalMetricName, }, Target: v2beta2.MetricTarget{ Type: v2beta2.AverageValueMetricType, diff --git a/pkg/scalers/azure_eventhub_scaler_test.go b/pkg/scalers/azure_eventhub_scaler_test.go index 0aa55d90bbd..5bdcfc28057 100644 --- a/pkg/scalers/azure_eventhub_scaler_test.go +++ b/pkg/scalers/azure_eventhub_scaler_test.go @@ -31,6 +31,7 @@ type parseEventHubMetadataTestData struct { type eventHubMetricIdentifier struct { metadataTestData *parseEventHubMetadataTestData + scalerIndex int name string } @@ -65,7 +66,8 @@ var parseEventHubMetadataDatasetWithPodIdentity = []parseEventHubMetadataTestDat } var eventHubMetricIdentifiers = []eventHubMetricIdentifier{ - {&parseEventHubMetadataDataset[1], "azure-eventhub-none-testEventHubConsumerGroup"}, + {&parseEventHubMetadataDataset[1], 0, "s0-azure-eventhub-none-testEventHubConsumerGroup"}, + {&parseEventHubMetadataDataset[1], 1, "s1-azure-eventhub-none-testEventHubConsumerGroup"}, } var testEventHubScaler = azureEventHubScaler{ @@ -435,7 +437,7 @@ func DeleteContainerInStorage(ctx context.Context, endpoint *url.URL, credential func TestEventHubGetMetricSpecForScaling(t *testing.T) { for _, testData := range eventHubMetricIdentifiers { - meta, err := parseAzureEventHubMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: sampleEventHubResolvedEnv, AuthParams: map[string]string{}}) + meta, err := parseAzureEventHubMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: sampleEventHubResolvedEnv, AuthParams: map[string]string{}, Index: testData.scalerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/azure_log_analytics_scaler.go b/pkg/scalers/azure_log_analytics_scaler.go index f122006bc90..12a4081f1d8 100644 --- a/pkg/scalers/azure_log_analytics_scaler.go +++ b/pkg/scalers/azure_log_analytics_scaler.go @@ -57,14 +57,14 @@ type azureLogAnalyticsScaler struct { } type azureLogAnalyticsMetadata struct { - tenantID string - clientID string - clientSecret string - workspaceID string - podIdentity string - query string - threshold int64 - metricName string // Custom metric name for trigger + tenantID string + clientID string + clientSecret string + workspaceID string + podIdentity string + query string + threshold int64 + externalMetricName string // Custom metric name for trigger } type sessionCache struct { @@ -180,11 +180,14 @@ func parseAzureLogAnalyticsMetadata(config *ScalerConfig) (*azureLogAnalyticsMet // Resolve metricName if val, ok := config.TriggerMetadata["metricName"]; ok { - meta.metricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-log-analytics", val)) + meta.externalMetricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-log-analytics", val)) } else { - meta.metricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-log-analytics", meta.workspaceID)) + meta.externalMetricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-log-analytics", meta.workspaceID)) } + // Update externalMetricName with the index + meta.externalMetricName = GenerateMetricNameWithIndex(config, meta.externalMetricName) + return &meta, nil } @@ -222,7 +225,7 @@ func (s *azureLogAnalyticsScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec externalMetric := &v2beta2.ExternalMetricSource{ Metric: v2beta2.MetricIdentifier{ - Name: s.metadata.metricName, + Name: s.metadata.externalMetricName, }, Target: v2beta2.MetricTarget{ Type: v2beta2.AverageValueMetricType, diff --git a/pkg/scalers/azure_log_analytics_scaler_test.go b/pkg/scalers/azure_log_analytics_scaler_test.go index 864b9de19cc..568a8c7d865 100644 --- a/pkg/scalers/azure_log_analytics_scaler_test.go +++ b/pkg/scalers/azure_log_analytics_scaler_test.go @@ -37,6 +37,7 @@ type parseLogAnalyticsMetadataTestData struct { type LogAnalyticsMetricIdentifier struct { metadataTestData *parseLogAnalyticsMetadataTestData + scalerIndex int name string } @@ -90,7 +91,8 @@ var testLogAnalyticsMetadata = []parseLogAnalyticsMetadataTestData{ } var LogAnalyticsMetricIdentifiers = []LogAnalyticsMetricIdentifier{ - {&testLogAnalyticsMetadata[7], "azure-log-analytics-074dd9f8-c368-4220-9400-acb6e80fc325"}, + {&testLogAnalyticsMetadata[7], 0, "s0-azure-log-analytics-074dd9f8-c368-4220-9400-acb6e80fc325"}, + {&testLogAnalyticsMetadata[7], 1, "s1-azure-log-analytics-074dd9f8-c368-4220-9400-acb6e80fc325"}, } var testLogAnalyticsMetadataWithEmptyAuthParams = []parseLogAnalyticsMetadataTestData{ @@ -159,7 +161,7 @@ func TestLogAnalyticsParseMetadata(t *testing.T) { func TestLogAnalyticsGetMetricSpecForScaling(t *testing.T) { for _, testData := range LogAnalyticsMetricIdentifiers { - meta, err := parseAzureLogAnalyticsMetadata(&ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: nil, PodIdentity: ""}) + meta, err := parseAzureLogAnalyticsMetadata(&ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: nil, PodIdentity: "", Index: testData.scalerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -181,25 +183,26 @@ func TestLogAnalyticsGetMetricSpecForScaling(t *testing.T) { } type parseMetadataMetricNameTestData struct { - metadata map[string]string - metricName string + metadata map[string]string + scalerIndex int + metricName string } var testParseMetadataMetricName = []parseMetadataMetricNameTestData{ // WorkspaceID - {map[string]string{"tenantIdFromEnv": "d248da64-0e1e-4f79-b8c6-72ab7aa055eb", "clientIdFromEnv": "41826dd4-9e0a-4357-a5bd-a88ad771ea7d", "clientSecretFromEnv": "U6DtAX5r6RPZxd~l12Ri3X8J9urt5Q-xs", "workspaceIdFromEnv": "074dd9f8-c368-4220-9400-acb6e80fc325", "query": query, "threshold": "1900000000"}, "azure-log-analytics-074dd9f8-c368-4220-9400-acb6e80fc325"}, + {map[string]string{"tenantIdFromEnv": "d248da64-0e1e-4f79-b8c6-72ab7aa055eb", "clientIdFromEnv": "41826dd4-9e0a-4357-a5bd-a88ad771ea7d", "clientSecretFromEnv": "U6DtAX5r6RPZxd~l12Ri3X8J9urt5Q-xs", "workspaceIdFromEnv": "074dd9f8-c368-4220-9400-acb6e80fc325", "query": query, "threshold": "1900000000"}, 0, "s0-azure-log-analytics-074dd9f8-c368-4220-9400-acb6e80fc325"}, // Custom Name - {map[string]string{"metricName": "testName", "tenantIdFromEnv": "d248da64-0e1e-4f79-b8c6-72ab7aa055eb", "clientIdFromEnv": "41826dd4-9e0a-4357-a5bd-a88ad771ea7d", "clientSecretFromEnv": "U6DtAX5r6RPZxd~l12Ri3X8J9urt5Q-xs", "workspaceIdFromEnv": "074dd9f8-c368-4220-9400-acb6e80fc325", "query": query, "threshold": "1900000000"}, "azure-log-analytics-testName"}, + {map[string]string{"metricName": "testName", "tenantIdFromEnv": "d248da64-0e1e-4f79-b8c6-72ab7aa055eb", "clientIdFromEnv": "41826dd4-9e0a-4357-a5bd-a88ad771ea7d", "clientSecretFromEnv": "U6DtAX5r6RPZxd~l12Ri3X8J9urt5Q-xs", "workspaceIdFromEnv": "074dd9f8-c368-4220-9400-acb6e80fc325", "query": query, "threshold": "1900000000"}, 1, "s1-azure-log-analytics-testName"}, } func TestLogAnalyticsParseMetadataMetricName(t *testing.T) { for _, testData := range testParseMetadataMetricName { - meta, err := parseAzureLogAnalyticsMetadata(&ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: nil, PodIdentity: ""}) + meta, err := parseAzureLogAnalyticsMetadata(&ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: nil, PodIdentity: "", Index: testData.scalerIndex}) if err != nil { t.Error("Expected success but got error", err) } - if meta.metricName != testData.metricName { - t.Errorf("Expected %s but got %s", testData.metricName, meta.metricName) + if meta.externalMetricName != testData.metricName { + t.Errorf("Expected %s but got %s", testData.metricName, meta.externalMetricName) } } } diff --git a/pkg/scalers/azure_monitor_scaler.go b/pkg/scalers/azure_monitor_scaler.go index 3ec37e06059..9c80ea0f44d 100644 --- a/pkg/scalers/azure_monitor_scaler.go +++ b/pkg/scalers/azure_monitor_scaler.go @@ -45,8 +45,9 @@ type azureMonitorScaler struct { } type azureMonitorMetadata struct { - azureMonitorInfo azure.MonitorInfo - targetValue int + azureMonitorInfo azure.MonitorInfo + targetValue int + externalMetricName string } var azureMonitorLog = logf.Log.WithName("azure_monitor_scaler") @@ -145,6 +146,11 @@ func parseAzureMonitorMetadata(config *ScalerConfig) (*azureMonitorMetadata, err meta.azureMonitorInfo.ClientID = clientID meta.azureMonitorInfo.ClientPassword = clientPassword + meta.externalMetricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s-%s", "azure-monitor", meta.azureMonitorInfo.ResourceURI, meta.azureMonitorInfo.ResourceGroupName, meta.azureMonitorInfo.Name)) + + // Update externalMetricName with the index + meta.externalMetricName = GenerateMetricNameWithIndex(config, meta.externalMetricName) + return &meta, nil } @@ -191,7 +197,7 @@ func (s *azureMonitorScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec { targetMetricVal := resource.NewQuantity(int64(s.metadata.targetValue), resource.DecimalSI) externalMetric := &v2beta2.ExternalMetricSource{ Metric: v2beta2.MetricIdentifier{ - Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s-%s", "azure-monitor", s.metadata.azureMonitorInfo.ResourceURI, s.metadata.azureMonitorInfo.ResourceGroupName, s.metadata.azureMonitorInfo.Name)), + Name: s.metadata.externalMetricName, }, Target: v2beta2.MetricTarget{ Type: v2beta2.AverageValueMetricType, diff --git a/pkg/scalers/azure_monitor_scaler_test.go b/pkg/scalers/azure_monitor_scaler_test.go index 155dbbdc374..8a5963045f1 100644 --- a/pkg/scalers/azure_monitor_scaler_test.go +++ b/pkg/scalers/azure_monitor_scaler_test.go @@ -32,6 +32,7 @@ type parseAzMonitorMetadataTestData struct { type azMonitorMetricIdentifier struct { metadataTestData *parseAzMonitorMetadataTestData + scalerIndex int name string } @@ -80,7 +81,8 @@ var testParseAzMonitorMetadata = []parseAzMonitorMetadataTestData{ } var azMonitorMetricIdentifiers = []azMonitorMetricIdentifier{ - {&testParseAzMonitorMetadata[1], "azure-monitor-test-resource-uri-test-metric"}, + {&testParseAzMonitorMetadata[1], 0, "s0-azure-monitor-test-resource-uri-test-metric"}, + {&testParseAzMonitorMetadata[1], 1, "s1-azure-monitor-test-resource-uri-test-metric"}, } func TestAzMonitorParseMetadata(t *testing.T) { @@ -97,7 +99,7 @@ func TestAzMonitorParseMetadata(t *testing.T) { func TestAzMonitorGetMetricSpecForScaling(t *testing.T) { for _, testData := range azMonitorMetricIdentifiers { - meta, err := parseAzureMonitorMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, PodIdentity: testData.metadataTestData.podIdentity}) + meta, err := parseAzureMonitorMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, PodIdentity: testData.metadataTestData.podIdentity, Index: testData.scalerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/azure_pipelines_scaler.go b/pkg/scalers/azure_pipelines_scaler.go index 70d2ba62e8c..a0c98a76eca 100644 --- a/pkg/scalers/azure_pipelines_scaler.go +++ b/pkg/scalers/azure_pipelines_scaler.go @@ -33,6 +33,7 @@ type azurePipelinesMetadata struct { personalAccessToken string poolID string targetPipelinesQueueLength int + externalMetricName string } var azurePipelinesLog = logf.Log.WithName("azure_pipelines_scaler") @@ -95,6 +96,11 @@ func parseAzurePipelinesMetadata(config *ScalerConfig) (*azurePipelinesMetadata, return nil, fmt.Errorf("no poolID given") } + meta.externalMetricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s", "azure-pipelines-queue", meta.organizationName, meta.poolID)) + + // Update externalMetricName with the index + meta.externalMetricName = GenerateMetricNameWithIndex(config, meta.externalMetricName) + return &meta, nil } @@ -166,7 +172,7 @@ func (s *azurePipelinesScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec { targetPipelinesQueueLengthQty := resource.NewQuantity(int64(s.metadata.targetPipelinesQueueLength), resource.DecimalSI) externalMetric := &v2beta2.ExternalMetricSource{ Metric: v2beta2.MetricIdentifier{ - Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s-%s", "azure-pipelines-queue", s.metadata.organizationName, s.metadata.poolID)), + Name: s.metadata.externalMetricName, }, Target: v2beta2.MetricTarget{ Type: v2beta2.AverageValueMetricType, diff --git a/pkg/scalers/azure_pipelines_scaler_test.go b/pkg/scalers/azure_pipelines_scaler_test.go index 8a5d1cbb4a0..adf17053634 100644 --- a/pkg/scalers/azure_pipelines_scaler_test.go +++ b/pkg/scalers/azure_pipelines_scaler_test.go @@ -14,6 +14,7 @@ type parseAzurePipelinesMetadataTestData struct { type azurePipelinesMetricIdentifier struct { metadataTestData *parseAzurePipelinesMetadataTestData + scalerIndex int name string } @@ -38,7 +39,8 @@ var testAzurePipelinesMetadata = []parseAzurePipelinesMetadataTestData{ } var azurePipelinesMetricIdentifiers = []azurePipelinesMetricIdentifier{ - {&testAzurePipelinesMetadata[1], "azure-pipelines-queue-sample-1"}, + {&testAzurePipelinesMetadata[1], 0, "s0-azure-pipelines-queue-sample-1"}, + {&testAzurePipelinesMetadata[1], 1, "s1-azure-pipelines-queue-sample-1"}, } func TestParseAzurePipelinesMetadata(t *testing.T) { @@ -55,7 +57,7 @@ func TestParseAzurePipelinesMetadata(t *testing.T) { func TestAzurePipelinesGetMetricSpecForScaling(t *testing.T) { for _, testData := range azurePipelinesMetricIdentifiers { - meta, err := parseAzurePipelinesMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams}) + meta, err := parseAzurePipelinesMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, Index: testData.scalerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/azure_queue_scaler.go b/pkg/scalers/azure_queue_scaler.go index fc1da110ed4..627fca1bdee 100644 --- a/pkg/scalers/azure_queue_scaler.go +++ b/pkg/scalers/azure_queue_scaler.go @@ -48,11 +48,12 @@ type azureQueueScaler struct { } type azureQueueMetadata struct { - targetQueueLength int - queueName string - connection string - accountName string - endpointSuffix string + targetQueueLength int + queueName string + connection string + accountName string + endpointSuffix string + externalMetricName string } var azureQueueLog = logf.Log.WithName("azure_queue_scaler") @@ -132,6 +133,11 @@ func parseAzureQueueMetadata(config *ScalerConfig) (*azureQueueMetadata, kedav1a return nil, "", fmt.Errorf("pod identity %s not supported for azure storage queues", config.PodIdentity) } + meta.externalMetricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-queue", meta.queueName)) + + // Update externalMetricName with the index + meta.externalMetricName = GenerateMetricNameWithIndex(config, meta.externalMetricName) + return &meta, config.PodIdentity, nil } @@ -163,7 +169,7 @@ func (s *azureQueueScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec { targetQueueLengthQty := resource.NewQuantity(int64(s.metadata.targetQueueLength), resource.DecimalSI) externalMetric := &v2beta2.ExternalMetricSource{ Metric: v2beta2.MetricIdentifier{ - Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-queue", s.metadata.queueName)), + Name: s.metadata.externalMetricName, }, Target: v2beta2.MetricTarget{ Type: v2beta2.AverageValueMetricType, diff --git a/pkg/scalers/azure_queue_scaler_test.go b/pkg/scalers/azure_queue_scaler_test.go index 6ba7189d79c..8539cdff100 100644 --- a/pkg/scalers/azure_queue_scaler_test.go +++ b/pkg/scalers/azure_queue_scaler_test.go @@ -37,6 +37,7 @@ type parseAzQueueMetadataTestData struct { type azQueueMetricIdentifier struct { metadataTestData *parseAzQueueMetadataTestData + scalerIndex int name string } @@ -76,8 +77,8 @@ var testAzQueueMetadata = []parseAzQueueMetadataTestData{ } var azQueueMetricIdentifiers = []azQueueMetricIdentifier{ - {&testAzQueueMetadata[1], "azure-queue-sample"}, - {&testAzQueueMetadata[4], "azure-queue-sample_queue"}, + {&testAzQueueMetadata[1], 0, "s0-azure-queue-sample"}, + {&testAzQueueMetadata[4], 1, "s1-azure-queue-sample_queue"}, } func TestAzQueueParseMetadata(t *testing.T) { @@ -97,7 +98,7 @@ func TestAzQueueParseMetadata(t *testing.T) { func TestAzQueueGetMetricSpecForScaling(t *testing.T) { for _, testData := range azQueueMetricIdentifiers { - meta, podIdentity, err := parseAzureQueueMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, PodIdentity: testData.metadataTestData.podIdentity}) + meta, podIdentity, err := parseAzureQueueMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, PodIdentity: testData.metadataTestData.podIdentity, Index: testData.scalerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) }