Skip to content

Commit

Permalink
Extend Azure Monitor scaler to support custom metrics (#1883)
Browse files Browse the repository at this point in the history
Signed-off-by: amirschw <[email protected]>
  • Loading branch information
amirschw authored Jun 14, 2021
1 parent d11b1d6 commit 145a13b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

### New

- Extend Azure Monitor scaler to support custom metrics ([#1883](https://github.com/kedacore/keda/pull/1883))
- Support non-public cloud environments in the Azure Storage Queue and Azure Storage Blob scalers ([#1863](https://github.com/kedacore/keda/pull/1863))
- Show HashiCorp Vault Address when using `kubectl get ta` or `kubectl get cta` ([#1862](https://github.com/kedacore/keda/pull/1862))

Expand Down
15 changes: 9 additions & 6 deletions pkg/scalers/azure/azure_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

type azureExternalMetricRequest struct {
MetricName string
MetricNamespace string
SubscriptionID string
ResourceName string
ResourceProviderNamespace string
Expand All @@ -37,6 +38,7 @@ type MonitorInfo struct {
SubscriptionID string
ResourceGroupName string
Name string
Namespace string
Filter string
AggregationInterval string
AggregationType string
Expand Down Expand Up @@ -79,11 +81,12 @@ func createMetricsClient(info MonitorInfo, podIdentityEnabled bool) insights.Met

func createMetricsRequest(info MonitorInfo) (*azureExternalMetricRequest, error) {
metricRequest := azureExternalMetricRequest{
MetricName: info.Name,
SubscriptionID: info.SubscriptionID,
Aggregation: info.AggregationType,
Filter: info.Filter,
ResourceGroup: info.ResourceGroupName,
MetricName: info.Name,
MetricNamespace: info.Namespace,
SubscriptionID: info.SubscriptionID,
Aggregation: info.AggregationType,
Filter: info.Filter,
ResourceGroup: info.ResourceGroupName,
}

resourceInfo := strings.Split(info.ResourceURI, "/")
Expand Down Expand Up @@ -126,7 +129,7 @@ func getAzureMetric(ctx context.Context, client insights.MetricsClient, azMetric
metricResult, err := client.List(ctx, metricResourceURI,
azMetricRequest.Timespan, nil,
azMetricRequest.MetricName, azMetricRequest.Aggregation, nil,
"", azMetricRequest.Filter, "", "")
"", azMetricRequest.Filter, "", azMetricRequest.MetricNamespace)
if err != nil {
return -1, err
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/scalers/azure_monitor_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ func parseAzureMonitorMetadata(config *ScalerConfig) (*azureMonitorMetadata, err
return nil, fmt.Errorf("no tenantId given")
}

if val, ok := config.TriggerMetadata["metricNamespace"]; ok {
meta.azureMonitorInfo.Namespace = val
}

clientID, clientPassword, err := parseAzurePodIdentityParams(config)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/scalers/azure_monitor_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var testParseAzMonitorMetadata = []parseAzMonitorMetadataTestData{
// nothing passed
{map[string]string{}, true, map[string]string{}, map[string]string{}, ""},
// properly formed
{map[string]string{"resourceURI": "test/resource/uri", "tenantId": "123", "subscriptionId": "456", "resourceGroupName": "test", "metricName": "metric", "metricAggregationInterval": "0:15:0", "metricAggregationType": "Average", "activeDirectoryClientId": "CLIENT_ID", "activeDirectoryClientPasswordFromEnv": "CLIENT_PASSWORD", "targetValue": "5"}, false, testAzMonitorResolvedEnv, map[string]string{}, ""},
{map[string]string{"resourceURI": "test/resource/uri", "tenantId": "123", "subscriptionId": "456", "resourceGroupName": "test", "metricName": "metric", "metricAggregationInterval": "0:15:0", "metricAggregationType": "Average", "activeDirectoryClientId": "CLIENT_ID", "activeDirectoryClientPasswordFromEnv": "CLIENT_PASSWORD", "targetValue": "5", "metricNamespace": "namespace"}, false, testAzMonitorResolvedEnv, map[string]string{}, ""},
// no optional parameters
{map[string]string{"resourceURI": "test/resource/uri", "tenantId": "123", "subscriptionId": "456", "resourceGroupName": "test", "metricName": "metric", "metricAggregationType": "Average", "activeDirectoryClientId": "CLIENT_ID", "activeDirectoryClientPasswordFromEnv": "CLIENT_PASSWORD", "targetValue": "5"}, false, testAzMonitorResolvedEnv, map[string]string{}, ""},
// incorrectly formatted resourceURI
Expand Down

0 comments on commit 145a13b

Please sign in to comment.