Skip to content

Commit

Permalink
change target value to float64 for GCP pub sub and stackdriver
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>
  • Loading branch information
octothorped committed Dec 2, 2022
1 parent c69e250 commit 2cd39eb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions pkg/scalers/gcp_pubsub_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type pubsubScaler struct {

type pubsubMetadata struct {
mode string
value int64
value float64
activationValue float64

subscriptionName string
Expand Down Expand Up @@ -79,7 +79,7 @@ func parsePubSubMetadata(config *ScalerConfig, logger logr.Logger) (*pubsubMetad
}
logger.Info("subscriptionSize field is deprecated. Use mode and value fields instead")
meta.mode = pubsubModeSubscriptionSize
subSizeValue, err := strconv.ParseInt(subSize, 10, 64)
subSizeValue, err := strconv.ParseFloat(subSize, 64)
if err != nil {
return nil, fmt.Errorf("value parsing error %s", err.Error())
}
Expand All @@ -99,7 +99,7 @@ func parsePubSubMetadata(config *ScalerConfig, logger logr.Logger) (*pubsubMetad
}

if valuePresent {
triggerValue, err := strconv.ParseInt(value, 10, 64)
triggerValue, err := strconv.ParseFloat(value, 64)
if err != nil {
return nil, fmt.Errorf("value parsing error %s", err.Error())
}
Expand Down Expand Up @@ -175,7 +175,7 @@ func (s *pubsubScaler) GetMetricSpecForScaling(context.Context) []v2.MetricSpec
Metric: v2.MetricIdentifier{
Name: GenerateMetricNameWithIndex(s.metadata.scalerIndex, kedautil.NormalizeString(fmt.Sprintf("gcp-ps-%s", s.metadata.subscriptionName))),
},
Target: GetMetricTarget(s.metricType, s.metadata.value),
Target: GetMetricTargetMili(s.metricType, s.metadata.value),
}

// Create the metric spec for the HPA
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/gcp_pubsub_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ var testPubSubMetadata = []parsePubSubMetadataTestData{
{nil, map[string]string{"subscriptionName": "projects/myproject/subscriptions/mysubscription", "subscriptionSize": "7", "credentialsFromEnv": "SAMPLE_CREDS"}, false},
// with full (bad) link to subscription
{nil, map[string]string{"subscriptionName": "projects/myproject/mysubscription", "subscriptionSize": "7", "credentialsFromEnv": "SAMPLE_CREDS"}, false},
// properly formed float activationTargetValue
{nil, map[string]string{"subscriptionName": "mysubscription", "value": "7", "credentialsFromEnv": "SAMPLE_CREDS", "activationValue": "2.0"}, false},
// properly formed float value and activationTargetValue
{nil, map[string]string{"subscriptionName": "mysubscription", "value": "7.1", "credentialsFromEnv": "SAMPLE_CREDS", "activationValue": "2.1"}, false},
}

var gcpPubSubMetricIdentifiers = []gcpPubSubMetricIdentifier{
Expand Down
6 changes: 3 additions & 3 deletions pkg/scalers/gcp_stackdriver_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type stackdriverScaler struct {
type stackdriverMetadata struct {
projectID string
filter string
targetValue int64
targetValue float64
activationTargetValue float64
metricName string

Expand Down Expand Up @@ -91,7 +91,7 @@ func parseStackdriverMetadata(config *ScalerConfig, logger logr.Logger) (*stackd
meta.metricName = GenerateMetricNameWithIndex(config.ScalerIndex, name)

if val, ok := config.TriggerMetadata["targetValue"]; ok {
targetValue, err := strconv.ParseInt(val, 10, 64)
targetValue, err := strconv.ParseFloat(val, 64)
if err != nil {
logger.Error(err, "Error parsing targetValue")
return nil, fmt.Errorf("error parsing targetValue: %s", err.Error())
Expand Down Expand Up @@ -188,7 +188,7 @@ func (s *stackdriverScaler) GetMetricSpecForScaling(context.Context) []v2.Metric
Metric: v2.MetricIdentifier{
Name: s.metadata.metricName,
},
Target: GetMetricTarget(s.metricType, s.metadata.targetValue),
Target: GetMetricTargetMili(s.metricType, s.metadata.targetValue),
}

// Create the metric spec for the HPA
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/gcp_stackdriver_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ var testStackdriverMetadata = []parseStackdriverMetadataTestData{
{nil, map[string]string{"projectId": "myProject", "filter": sdFilter, "credentialsFromEnv": "SAMPLE_CREDS", "alignmentPeriodSeconds": "30"}, true},
// With bad alignment period
{nil, map[string]string{"projectId": "myProject", "filter": sdFilter, "credentialsFromEnv": "SAMPLE_CREDS", "alignmentPeriodSeconds": "a"}, true},
// properly formed float activationTargetValue
{nil, map[string]string{"projectId": "myProject", "filter": sdFilter, "credentialsFromEnv": "SAMPLE_CREDS", "activationTargetValue": "2.0"}, false},
// properly formed float targetValue and activationTargetValue
{nil, map[string]string{"projectId": "myProject", "filter": sdFilter, "credentialsFromEnv": "SAMPLE_CREDS", "targetValue": "1.1", "activationTargetValue": "2.1"}, false},
}

var gcpStackdriverMetricIdentifiers = []gcpStackdriverMetricIdentifier{
Expand Down

0 comments on commit 2cd39eb

Please sign in to comment.