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

Deprecate explicitly setting metricName for all scalers #4235

Merged
merged 7 commits into from
Feb 27, 2023
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 @@ -94,6 +94,7 @@ You can find all deprecations in [this overview](https://github.com/kedacore/ked

New deprecation(s):

- **General**: Deprecate explicitly setting `metricName` field from `ScaledObject.triggers[*].metadata` ([#4220])(https://github.com/kedacore/keda/issues/4220)
- **Prometheus Scaler**: `cortexOrgId` metadata deprecated in favor of custom headers ([#4208](https://github.com/kedacore/keda/issues/4208))

### Other
Expand Down
7 changes: 7 additions & 0 deletions controllers/keda/scaledobject_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ func (r *ScaledObjectReconciler) checkTriggers(scaledObject *kedav1alpha1.Scaled
}
}

// FIXME: DEPRECATED to be removed in v2.12
_, hasMetricName := trigger.Metadata["metricName"]
// aws-cloudwatch and huawei-cloudeye have a meaningful use of metricName
if hasMetricName && trigger.Type != "aws-cloudwatch" && trigger.Type != "huawei-cloudeye" {
log.Log.Info("metricName is deprecated and will be removed in v2.12, please do not set it anymore (used in %q)", trigger.Type)
}

name := trigger.Name
if name != "" {
if _, found := triggerNames[name]; found {
Expand Down
1 change: 1 addition & 0 deletions pkg/scalers/azure_blob_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func parseAzureBlobMetadata(config *ScalerConfig, logger logr.Logger) (*azure.Bl
config.PodIdentity = kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderAzure}
}

// FIXME: DEPRECATED to be removed in v2.12
if val, ok := config.TriggerMetadata["metricName"]; ok {
meta.MetricName = kedautil.NormalizeString(fmt.Sprintf("azure-blob-%s", val))
} else {
Expand Down
2 changes: 2 additions & 0 deletions pkg/scalers/azure_log_analytics_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ func parseAzureLogAnalyticsMetadata(config *ScalerConfig) (*azureLogAnalyticsMet
}

// Resolve metricName

// FIXME: DEPRECATED to be removed in v2.12
if val, ok := config.TriggerMetadata["metricName"]; ok {
meta.metricName = kedautil.NormalizeString(fmt.Sprintf("%s-%s", "azure-log-analytics", val))
} else {
Expand Down
1 change: 1 addition & 0 deletions pkg/scalers/cassandra_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func parseCassandraMetadata(config *ScalerConfig) (*CassandraMetadata, error) {
return nil, fmt.Errorf("no keyspace given")
}

// FIXME: DEPRECATED to be removed in v2.12
if val, ok := config.TriggerMetadata["metricName"]; ok {
meta.metricName = kedautil.NormalizeString(fmt.Sprintf("cassandra-%s", val))
} else {
Expand Down
5 changes: 2 additions & 3 deletions pkg/scalers/couchdb_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ func parseCouchDBMetadata(config *ScalerConfig) (*couchDBMetadata, string, error
// nosemgrep: db-connection-string
connStr = "http://" + addr
}
if val, ok := config.TriggerMetadata["metricName"]; ok {
zroubalik marked this conversation as resolved.
Show resolved Hide resolved
meta.metricName = kedautil.NormalizeString(fmt.Sprintf("couchdb-%s", val))
}

// FIXME: DEPRECATED to be removed in v2.12
meta.metricName = GenerateMetricNameWithIndex(config.ScalerIndex, kedautil.NormalizeString(fmt.Sprintf("coucdb-%s", meta.dbName)))
meta.scalerIndex = config.ScalerIndex
return &meta, connStr, nil
Expand Down
10 changes: 7 additions & 3 deletions pkg/scalers/graphite_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ import (
)

const (
graphiteServerAddress = "serverAddress"
graphiteMetricName = "metricName"
graphiteServerAddress = "serverAddress"

// FIXME: DEPRECATED to be removed in v2.12
graphiteMetricName = "metricName"

graphiteQuery = "query"
graphiteThreshold = "threshold"
graphiteActivationThreshold = "activationThreshold"
Expand Down Expand Up @@ -92,10 +95,11 @@ func parseGraphiteMetadata(config *ScalerConfig) (*graphiteMetadata, error) {
return nil, fmt.Errorf("no %s given", graphiteQuery)
}

// FIXME: DEPRECATED to be removed in v2.12
if val, ok := config.TriggerMetadata[graphiteMetricName]; ok && val != "" {
meta.metricName = val
} else {
return nil, fmt.Errorf("no %s given", graphiteMetricName)
meta.metricName = "graphite"
}

if val, ok := config.TriggerMetadata[graphiteQueryTime]; ok && val != "" {
Expand Down
2 changes: 0 additions & 2 deletions pkg/scalers/graphite_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ var testGrapMetadata = []parseGraphiteMetadataTestData{
{map[string]string{"serverAddress": "http://localhost:81", "metricName": "request-count", "threshold": "100", "activationThreshold": "23", "query": "stats.counters.http.hello-world.request.count.count", "queryTime": "-30Seconds"}, false},
// missing serverAddress
{map[string]string{"serverAddress": "", "metricName": "request-count", "threshold": "100", "query": "stats.counters.http.hello-world.request.count.count", "queryTime": "-30Seconds"}, true},
// missing metricName
{map[string]string{"serverAddress": "http://localhost:81", "metricName": "", "threshold": "100", "query": "stats.counters.http.hello-world.request.count.count", "queryTime": "-30Seconds"}, true},
// malformed threshold
{map[string]string{"serverAddress": "http://localhost:81", "metricName": "request-count", "threshold": "one", "query": "stats.counters.http.hello-world.request.count.count", "queryTime": "-30Seconds"}, true},
// malformed activationThreshold
Expand Down
1 change: 1 addition & 0 deletions pkg/scalers/influxdb_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func parseInfluxDBMetadata(config *ScalerConfig) (*influxDBMetadata, error) {
return nil, fmt.Errorf("no server url given")
}

// FIXME: DEPRECATED to be removed in v2.12
if val, ok := config.TriggerMetadata["metricName"]; ok {
metricName = util.NormalizeString(fmt.Sprintf("influxdb-%s", val))
} else {
Expand Down
1 change: 1 addition & 0 deletions pkg/scalers/mongo_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func parseMongoDBMetadata(config *ScalerConfig) (*mongoDBMetadata, string, error
connStr = fmt.Sprintf("mongodb://%s:%s@%s/%s", url.QueryEscape(meta.username), url.QueryEscape(meta.password), addr, meta.dbName)
}

// FIXME: DEPRECATED to be removed in v2.12
if val, ok := config.TriggerMetadata["metricName"]; ok {
meta.metricName = kedautil.NormalizeString(fmt.Sprintf("mongodb-%s", val))
} else {
Expand Down
2 changes: 2 additions & 0 deletions pkg/scalers/mssql_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ func parseMSSQLMetadata(config *ScalerConfig) (*mssqlMetadata, error) {
}

// get the metricName, which can be explicit or from the (masked) connection string

// FIXME: DEPRECATED to be removed in v2.12
if val, ok := config.TriggerMetadata["metricName"]; ok {
meta.metricName = kedautil.NormalizeString(fmt.Sprintf("mssql-%s", val))
} else {
Expand Down
1 change: 1 addition & 0 deletions pkg/scalers/postgresql_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func parsePostgreSQLMetadata(config *ScalerConfig) (*postgreSQLMetadata, error)
meta.connection = strings.Join(params, " ")
}

// FIXME: DEPRECATED to be removed in v2.12
if val, ok := config.TriggerMetadata["metricName"]; ok {
meta.metricName = kedautil.NormalizeString(fmt.Sprintf("postgresql-%s", val))
} else {
Expand Down
10 changes: 7 additions & 3 deletions pkg/scalers/prometheus_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import (
)

const (
promServerAddress = "serverAddress"
promMetricName = "metricName"
promServerAddress = "serverAddress"

// FIXME: DEPRECATED to be removed in v2.12
promMetricName = "metricName"

promQuery = "query"
promThreshold = "threshold"
promActivationThreshold = "activationThreshold"
Expand Down Expand Up @@ -125,10 +128,11 @@ func parsePrometheusMetadata(config *ScalerConfig) (meta *prometheusMetadata, er
return nil, fmt.Errorf("no %s given", promQuery)
}

// FIXME: DEPRECATED to be removed in v2.12
if val, ok := config.TriggerMetadata[promMetricName]; ok && val != "" {
meta.metricName = val
} else {
return nil, fmt.Errorf("no %s given", promMetricName)
meta.metricName = "prometheus"
}

if val, ok := config.TriggerMetadata[promThreshold]; ok && val != "" {
Expand Down
2 changes: 0 additions & 2 deletions pkg/scalers/prometheus_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ var testPromMetadata = []parsePrometheusMetadataTestData{
{map[string]string{"serverAddress": "http://localhost:9090", "metricName": "http_requests_total", "threshold": "100", "query": "up", "activationThreshold": "50"}, false},
// missing serverAddress
{map[string]string{"serverAddress": "", "metricName": "http_requests_total", "threshold": "100", "query": "up"}, true},
// missing metricName
{map[string]string{"serverAddress": "http://localhost:9090", "metricName": "", "threshold": "100", "query": "up"}, true},
// missing threshold
{map[string]string{"serverAddress": "http://localhost:9090", "metricName": "http_requests_total", "query": "up"}, true},
// malformed threshold
Expand Down
2 changes: 2 additions & 0 deletions pkg/scalers/rabbitmq_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ func parseRabbitMQMetadata(config *ScalerConfig) (*rabbitMQMetadata, error) {
}

// Resolve metricName

// FIXME: DEPRECATED to be removed in v2.12
if val, ok := config.TriggerMetadata["metricName"]; ok {
meta.metricName = kedautil.NormalizeString(fmt.Sprintf("rabbitmq-%s", url.QueryEscape(val)))
} else {
Expand Down