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

feat: Introduce activationThreshold/minMetricValue for Openstack Swift Scaler #3440

Merged
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require (
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/google/go-cmp v0.5.8
github.com/gophercloud/gophercloud v0.25.0
github.com/hashicorp/vault/api v1.7.2
github.com/imdario/mergo v0.3.12
github.com/influxdata/influxdb-client-go/v2 v2.9.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ github.com/googleapis/gnostic v0.5.5 h1:9fHAtK0uDfpveeqqo1hkEZJcFvYXAiCN3UutL8F9
github.com/googleapis/gnostic v0.5.5/go.mod h1:7+EbHbldMins07ALC74bsA81Ovc97DwqyJO1AENw9kA=
github.com/googleapis/go-type-adapters v1.0.0 h1:9XdMn+d/G57qq1s8dNc5IesGCXHf6V2HZ2JwRxfA2tA=
github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4=
github.com/gophercloud/gophercloud v0.25.0 h1:C3Oae7y0fUVQGSsBrb3zliAjdX+riCSEh4lNMejFNI4=
github.com/gophercloud/gophercloud v0.25.0/go.mod h1:Q8fZtyi5zZxPS/j9aj3sSxtvj41AdQMDwyo1myduD5c=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
Expand Down
48 changes: 30 additions & 18 deletions pkg/scalers/openstack_swift_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,26 @@ import (
)

const (
defaultOnlyFiles = false
defaultObjectCount = 2
defaultObjectLimit = ""
defaultObjectPrefix = ""
defaultObjectDelimiter = ""
defaultHTTPClientTimeout = 30
defaultOnlyFiles = false
defaultObjectCount = 2
defaultActivationObjectCount = 0
defaultObjectLimit = ""
defaultObjectPrefix = ""
defaultObjectDelimiter = ""
defaultHTTPClientTimeout = 30
)

type openstackSwiftMetadata struct {
swiftURL string
containerName string
objectCount int64
objectPrefix string
objectDelimiter string
objectLimit string
httpClientTimeout int
onlyFiles bool
scalerIndex int
swiftURL string
containerName string
objectCount int64
activationObjectCount int64
objectPrefix string
objectDelimiter string
objectLimit string
httpClientTimeout int
onlyFiles bool
scalerIndex int
}

type openstackSwiftAuthenticationMetadata struct {
Expand Down Expand Up @@ -259,15 +261,25 @@ func parseOpenstackSwiftMetadata(config *ScalerConfig) (*openstackSwiftMetadata,
}

if val, ok := config.TriggerMetadata["objectCount"]; ok {
targetObjectCount, err := strconv.ParseInt(val, 10, 64)
objectCount, err := strconv.ParseInt(val, 10, 64)
if err != nil {
return nil, fmt.Errorf("objectCount parsing error: %s", err.Error())
}
meta.objectCount = targetObjectCount
meta.objectCount = objectCount
} else {
meta.objectCount = defaultObjectCount
}

if val, ok := config.TriggerMetadata["activationObjectCount"]; ok {
activationObjectCount, err := strconv.ParseInt(val, 10, 64)
if err != nil {
return nil, fmt.Errorf("activationObjectCount parsing error: %s", err.Error())
}
meta.activationObjectCount = activationObjectCount
} else {
meta.activationObjectCount = defaultActivationObjectCount
}

if val, ok := config.TriggerMetadata["objectPrefix"]; ok {
meta.objectPrefix = val
} else {
Expand Down Expand Up @@ -362,7 +374,7 @@ func (s *openstackSwiftScaler) IsActive(ctx context.Context) (bool, error) {
return false, err
}

return objectCount > 0, nil
return objectCount > s.metadata.activationObjectCount, nil
}

func (s *openstackSwiftScaler) Close(context.Context) error {
Expand Down
2 changes: 2 additions & 0 deletions pkg/scalers/openstack_swift_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var invalidOpenstackSwiftMetadataTestData = []parseOpenstackSwiftMetadataTestDat
{metadata: map[string]string{"swiftURL": "http://localhost:8080/v1/my-account-id", "objectCount": "5"}},
// objectCount is not an integer value
{metadata: map[string]string{"containerName": "my-container", "swiftURL": "http://localhost:8080/v1/my-account-id", "objectCount": "5.5"}},
// activationObjectCount is not an integer value
{metadata: map[string]string{"containerName": "my-container", "swiftURL": "http://localhost:8080/v1/my-account-id", "objectCount": "5", "activationObjectCount": "5.5"}},
// timeout is not an integer value
{metadata: map[string]string{"containerName": "my-container", "swiftURL": "http://localhost:8080/v1/my-account-id", "objectCount": "5", "timeout": "2.5"}},
// onlyFiles is not a boolean value
Expand Down
Loading