Skip to content

Commit

Permalink
feat: Introduce activationThreshold/minMetricValue for Selenium Scaler (
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Turrado Ferrero committed Jul 28, 2022
1 parent df27def commit 2d789ac
Show file tree
Hide file tree
Showing 4 changed files with 596 additions and 702 deletions.
26 changes: 18 additions & 8 deletions pkg/scalers/selenium_grid_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ type seleniumGridScaler struct {
}

type seleniumGridScalerMetadata struct {
url string
browserName string
sessionBrowserName string
targetValue int64
browserVersion string
unsafeSsl bool
scalerIndex int
url string
browserName string
sessionBrowserName string
targetValue int64
activationThreshold int64
browserVersion string
unsafeSsl bool
scalerIndex int
}

type seleniumResponse struct {
Expand Down Expand Up @@ -116,6 +117,15 @@ func parseSeleniumGridScalerMetadata(config *ScalerConfig) (*seleniumGridScalerM
meta.sessionBrowserName = meta.browserName
}

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

if val, ok := config.TriggerMetadata["browserVersion"]; ok && val != "" {
meta.browserVersion = val
} else {
Expand Down Expand Up @@ -170,7 +180,7 @@ func (s *seleniumGridScaler) IsActive(ctx context.Context) (bool, error) {
return false, err
}

return v > 0, nil
return v > s.metadata.activationThreshold, nil
}

func (s *seleniumGridScaler) getSessionsCount(ctx context.Context) (int64, error) {
Expand Down
39 changes: 28 additions & 11 deletions pkg/scalers/selenium_grid_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,27 +424,44 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) {
},
},
{
name: "valid url, browsername and unsafeSsl should return metadata",
name: "valid url, browsername, unsafeSsl and activationThreshold should return metadata",
args: args{
config: &ScalerConfig{
TriggerMetadata: map[string]string{
"url": "http://selenium-hub:4444/graphql",
"browserName": "chrome",
"browserVersion": "91.0",
"unsafeSsl": "true",
"url": "http://selenium-hub:4444/graphql",
"browserName": "chrome",
"browserVersion": "91.0",
"unsafeSsl": "true",
"activationThreshold": "10",
},
},
},
wantErr: false,
want: &seleniumGridScalerMetadata{
url: "http://selenium-hub:4444/graphql",
browserName: "chrome",
sessionBrowserName: "chrome",
targetValue: 1,
browserVersion: "91.0",
unsafeSsl: true,
url: "http://selenium-hub:4444/graphql",
browserName: "chrome",
sessionBrowserName: "chrome",
targetValue: 1,
activationThreshold: 10,
browserVersion: "91.0",
unsafeSsl: true,
},
},
{
name: "valid url, browsername and unsafeSsl but invalid activationThreshold should throw an error",
args: args{
config: &ScalerConfig{
TriggerMetadata: map[string]string{
"url": "http://selenium-hub:4444/graphql",
"browserName": "chrome",
"browserVersion": "91.0",
"unsafeSsl": "true",
"activationThreshold": "AA",
},
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading

0 comments on commit 2d789ac

Please sign in to comment.