Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Azure Monitor scaler to support custom metrics #1883

Merged
merged 1 commit into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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