From 6565347d8401a77cf49e895195329d0c8ab2b434 Mon Sep 17 00:00:00 2001 From: Matt Jeanes Date: Mon, 24 May 2021 11:35:30 +0100 Subject: [PATCH] Azure Blob Scaler - Fix multiple scalers with the same blobContainerName (#1816) * include blobPrefix in metricName and allow custom metricName for azure-blob scaler Signed-off-by: Matt Jeanes * Update changelog for PR 1816 Signed-off-by: Matt Jeanes --- CHANGELOG.md | 1 + pkg/scalers/azure_blob_scaler.go | 13 ++++++++++++- pkg/scalers/azure_blob_scaler_test.go | 7 +++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb3cbff2235..813af94ef57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ - Setting timeouts in the HTTP client used by the IBM MQ scaler ([#1758](https://github.com/kedacore/keda/pull/1758)) - Fix cleanup of removed triggers ([#1768](https://github.com/kedacore/keda/pull/1768)) - Eventhub Scaler: Add trigger parameter `checkpointStrategy` to support more language-specific checkpoints ([#1621](https://github.com/kedacore/keda/pull/1621)) +- Fix Azure Blob scaler when using multiple triggers with the same `blobContainerName` and added a optional `metricName` field ([#1816](https://github.com/kedacore/keda/pull/1816)) ### Breaking Changes diff --git a/pkg/scalers/azure_blob_scaler.go b/pkg/scalers/azure_blob_scaler.go index 449a45f1ad5..56bb1c2b2f2 100644 --- a/pkg/scalers/azure_blob_scaler.go +++ b/pkg/scalers/azure_blob_scaler.go @@ -39,6 +39,7 @@ type azureBlobMetadata struct { blobPrefix string connection string accountName string + metricName string } var azureBlobLog = logf.Log.WithName("azure_blob_scaler") @@ -92,6 +93,16 @@ func parseAzureBlobMetadata(config *ScalerConfig) (*azureBlobMetadata, kedav1alp config.PodIdentity = kedav1alpha1.PodIdentityProviderAzure } + if val, ok := config.TriggerMetadata["metricName"]; ok { + meta.metricName = 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)) + } else { + meta.metricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-blob", meta.blobContainerName)) + } + } + // If the Use AAD Pod Identity is not present, or set to "none" // then check for connection string switch config.PodIdentity { @@ -150,7 +161,7 @@ func (s *azureBlobScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec { targetBlobCount := resource.NewQuantity(int64(s.metadata.targetBlobCount), resource.DecimalSI) externalMetric := &v2beta2.ExternalMetricSource{ Metric: v2beta2.MetricIdentifier{ - Name: kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-blob", s.metadata.blobContainerName)), + Name: s.metadata.metricName, }, 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 533b76d5680..0020dbefdcc 100644 --- a/pkg/scalers/azure_blob_scaler_test.go +++ b/pkg/scalers/azure_blob_scaler_test.go @@ -29,6 +29,8 @@ var testAzBlobMetadata = []parseAzBlobMetadataTestData{ {map[string]string{}, true, testAzBlobResolvedEnv, map[string]string{}, ""}, // properly formed {map[string]string{"connectionFromEnv": "CONNECTION", "blobContainerName": "sample", "blobCount": "5", "blobDelimiter": "/", "blobPrefix": "blobsubpath"}, false, testAzBlobResolvedEnv, map[string]string{}, ""}, + // properly formed with metricName + {map[string]string{"connectionFromEnv": "CONNECTION", "blobContainerName": "sample", "blobCount": "5", "blobDelimiter": "/", "blobPrefix": "blobsubpath", "metricName": "customname"}, false, testAzBlobResolvedEnv, map[string]string{}, ""}, // Empty blobcontainerName {map[string]string{"connectionFromEnv": "CONNECTION", "blobContainerName": ""}, true, testAzBlobResolvedEnv, map[string]string{}, ""}, // improperly formed blobCount @@ -44,8 +46,9 @@ var testAzBlobMetadata = []parseAzBlobMetadataTestData{ } var azBlobMetricIdentifiers = []azBlobMetricIdentifier{ - {&testAzBlobMetadata[1], "azure-blob-sample"}, - {&testAzBlobMetadata[4], "azure-blob-sample_container"}, + {&testAzBlobMetadata[1], "azure-blob-sample-blobsubpath-"}, + {&testAzBlobMetadata[2], "azure-blob-customname"}, + {&testAzBlobMetadata[5], "azure-blob-sample_container"}, } func TestAzBlobParseMetadata(t *testing.T) {