Skip to content

Commit

Permalink
Azure Blob Scaler - Fix multiple scalers with the same blobContainerN…
Browse files Browse the repository at this point in the history
…ame (#1816)

* include blobPrefix in metricName and allow custom metricName for azure-blob scaler

Signed-off-by: Matt Jeanes <mattjeanes23@gmail.com>

* Update changelog for PR 1816

Signed-off-by: Matt Jeanes <mattjeanes23@gmail.com>
  • Loading branch information
MattJeanes committed May 24, 2021
1 parent 347e897 commit 6565347
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 12 additions & 1 deletion pkg/scalers/azure_blob_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type azureBlobMetadata struct {
blobPrefix string
connection string
accountName string
metricName string
}

var azureBlobLog = logf.Log.WithName("azure_blob_scaler")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions pkg/scalers/azure_blob_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 6565347

Please sign in to comment.