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

make targetQueryValue configurable in postgreSQL scaler #643

Merged
merged 1 commit into from
Feb 26, 2020
Merged
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
32 changes: 22 additions & 10 deletions pkg/scalers/postgresql_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/metrics/pkg/apis/external_metrics"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"strconv"
)

const (
Expand All @@ -24,14 +25,15 @@ type postgreSQLScaler struct {
}

type postgreSQLMetadata struct {
connection string
userName string
password string
host string
port string
query string
dbName string
sslmode string
targetQueryValue int
connection string
userName string
password string
host string
port string
query string
dbName string
sslmode string
}

var postgreSQLLog = logf.Log.WithName("postgreSQL_scaler")
Expand Down Expand Up @@ -62,6 +64,16 @@ func parsePostgreSQLMetadata(resolvedEnv, metadata, authParams map[string]string
return nil, fmt.Errorf("no query given")
}

if val, ok := metadata["targetQueryValue"]; ok {
targetQueryValue, err := strconv.Atoi(val)
if err != nil {
return nil, fmt.Errorf("queryValue parsing error %s", err.Error())
}
meta.targetQueryValue = targetQueryValue
} else {
return nil, fmt.Errorf("no targetQueryValue given")
}

if val, ok := authParams["connection"]; ok {
meta.connection = val
} else if val, ok := metadata["connection"]; ok {
Expand Down Expand Up @@ -171,10 +183,10 @@ func (s *postgreSQLScaler) getActiveNumber() (int, error) {

// GetMetricSpecForScaling returns the MetricSpec for the Horizontal Pod Autoscaler
func (s *postgreSQLScaler) GetMetricSpecForScaling() []v2beta1.MetricSpec {
targetListLengthQty := resource.NewQuantity(1, resource.DecimalSI)
targetQueryValue := resource.NewQuantity(int64(s.metadata.targetQueryValue), resource.DecimalSI)
externalMetric := &v2beta1.ExternalMetricSource{
MetricName: pgMetricName,
TargetAverageValue: targetListLengthQty,
TargetAverageValue: targetQueryValue,
}
metricSpec := v2beta1.MetricSpec{
External: externalMetric, Type: externalMetricType,
Expand Down