Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Brouwer <rickbrouwer@gmail.com>
  • Loading branch information
rickbrouwer committed Sep 16, 2024
1 parent 6306f89 commit d871178
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 40 deletions.
79 changes: 40 additions & 39 deletions pkg/scalers/mssql_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion pkg/scalers/mssql_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d871178

Please sign in to comment.