diff --git a/pkg/scalers/mssql_scaler.go b/pkg/scalers/mssql_scaler.go index 0b4ae633979..f9a3d731743 100644 --- a/pkg/scalers/mssql_scaler.go +++ b/pkg/scalers/mssql_scaler.go @@ -27,21 +27,22 @@ type mssqlScaler struct { } type mssqlMetadata struct { - ConnectionString string `keda:"name=connectionString,order=authParams;resolvedEnv;triggerMetadata,optional"` - Username string `keda:"name=username,order=authParams;triggerMetadata,optional"` - Password string `keda:"name=password,order=authParams;resolvedEnv;triggerMetadata,optional"` - Host string `keda:"name=host,order=authParams;triggerMetadata,optional"` - Port int `keda:"name=port,order=authParams;triggerMetadata,optional"` - Database string `keda:"name=database,order=authParams;triggerMetadata,optional"` - Query string `keda:"name=query,order=triggerMetadata"` - TargetValue float64 `keda:"name=targetValue,order=triggerMetadata"` - ActivationTargetValue float64 `keda:"name=activationTargetValue,order=triggerMetadata,optional,default=0"` - WorkloadIdentityClientID string `keda:"name=WorkloadIdentityClientID,order=authParams;triggerMetadata,optional"` - WorkloadIdentityTenantID string `keda:"name=WorkloadIdentityTenantID,order=authParams;triggerMetadata,optional"` - WorkloadIdentityAuthorityHost string `keda:"name=WorkloadIdentityAuthorityHost,order=authParams;triggerMetadata,optional"` - WorkloadIdentityResource string `keda:"name=WorkloadIdentityResource,order=authParams;triggerMetadata,optional"` + ConnectionString string `keda:"name=connectionString,order=authParams;resolvedEnv;triggerMetadata,optional"` + Username string `keda:"name=username,order=authParams;triggerMetadata,optional"` + Password string `keda:"name=password,order=authParams;resolvedEnv;triggerMetadata,optional"` + Host string `keda:"name=host,order=authParams;triggerMetadata,optional"` + Port int `keda:"name=port,order=authParams;triggerMetadata,optional"` + Database string `keda:"name=database,order=authParams;triggerMetadata,optional"` + Query string `keda:"name=query,order=triggerMetadata"` + TargetValue float64 `keda:"name=targetValue,order=triggerMetadata"` + ActivationTargetValue float64 `keda:"name=activationTargetValue,order=triggerMetadata,optional,default=0"` TriggerIndex int + + WorkloadIdentityResource string `keda:"name=WorkloadIdentityResource,order=authParams;triggerMetadata,optional"` + WorkloadIdentityClientID string + WorkloadIdentityTenantID string + WorkloadIdentityAuthorityHost string } func (m *mssqlMetadata) Validate() error { @@ -144,32 +145,6 @@ func getMSSQLConnectionString(meta mssqlMetadata) string { return connectionURL.String() } -func (s *mssqlScaler) GetMetricSpecForScaling(context.Context) []v2.MetricSpec { - externalMetric := &v2.ExternalMetricSource{ - Metric: v2.MetricIdentifier{ - Name: GenerateMetricNameWithIndex(s.metadata.TriggerIndex, "mssql"), - }, - Target: GetMetricTargetMili(s.metricType, s.metadata.TargetValue), - } - - metricSpec := v2.MetricSpec{ - External: externalMetric, Type: externalMetricType, - } - - return []v2.MetricSpec{metricSpec} -} - -func (s *mssqlScaler) GetMetricsAndActivity(ctx context.Context, metricName string) ([]external_metrics.ExternalMetricValue, bool, error) { - num, err := s.getQueryResult(ctx) - if err != nil { - return []external_metrics.ExternalMetricValue{}, false, fmt.Errorf("error inspecting mssql: %w", err) - } - - metric := GenerateMetricInMili(metricName, num) - - return []external_metrics.ExternalMetricValue{metric}, num > s.metadata.ActivationTargetValue, nil -} - func (s *mssqlScaler) getQueryResult(ctx context.Context) (float64, error) { var value float64 @@ -217,3 +192,29 @@ func (s *mssqlScaler) Close(context.Context) error { return nil } + +func (s *mssqlScaler) GetMetricSpecForScaling(context.Context) []v2.MetricSpec { + externalMetric := &v2.ExternalMetricSource{ + Metric: v2.MetricIdentifier{ + Name: GenerateMetricNameWithIndex(s.metadata.TriggerIndex, "mssql"), + }, + Target: GetMetricTargetMili(s.metricType, s.metadata.TargetValue), + } + + metricSpec := v2.MetricSpec{ + External: externalMetric, Type: externalMetricType, + } + + return []v2.MetricSpec{metricSpec} +} + +func (s *mssqlScaler) GetMetricsAndActivity(ctx context.Context, metricName string) ([]external_metrics.ExternalMetricValue, bool, error) { + num, err := s.getQueryResult(ctx) + if err != nil { + return []external_metrics.ExternalMetricValue{}, false, fmt.Errorf("error inspecting mssql: %w", err) + } + + metric := GenerateMetricInMili(metricName, num) + + return []external_metrics.ExternalMetricValue{metric}, num > s.metadata.ActivationTargetValue, nil +} diff --git a/pkg/scalers/mssql_scaler_test.go b/pkg/scalers/mssql_scaler_test.go index 22ae1c14a21..2d18d495c3c 100644 --- a/pkg/scalers/mssql_scaler_test.go +++ b/pkg/scalers/mssql_scaler_test.go @@ -122,7 +122,7 @@ var testMSSQLMetadata = []parseMSSQLMetadataTestData{ }, resolvedEnv: map[string]string{}, authParams: map[string]string{ - "workloadIdentityResource": "https://database.windows.net/", + "workloadIdentityResource": "mssql-resource-id", }, podIdentity: v1alpha1.AuthPodIdentity{ Provider: v1alpha1.PodIdentityProviderAzureWorkload,