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

fix: Selenium Grid scaler logic on platformName is set empty or any #6477

Merged
merged 3 commits into from
Jan 17, 2025
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 @@ -77,6 +77,7 @@ Here is an overview of all new **experimental** features:

- **General**: Fix event text when deactivation fails ([#6469](https://github.com/kedacore/keda/issues/6469))
- **AWS Scalers**: Add AWS region to the AWS Config Cache key ([#6128](https://github.com/kedacore/keda/issues/6128))
- **Selenium Grid**: Scaler logic on platformName is set empty or `any` ([#6477](https://github.com/kedacore/keda/issues/6477))

### Deprecations

Expand Down
19 changes: 9 additions & 10 deletions pkg/scalers/selenium_grid_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,35 +251,34 @@ func countMatchingSessions(sessions Sessions, browserName string, browserVersion
// This function checks if the request capabilities match the scaler metadata
func checkRequestCapabilitiesMatch(request Capability, browserName string, browserVersion string, _ string, platformName string) bool {
// Check if browserName matches
browserNameMatch := request.BrowserName == "" && browserName == "" ||
browserNameMatch := (request.BrowserName == "" && browserName == "") ||
strings.EqualFold(browserName, request.BrowserName)

// Check if browserVersion matches
browserVersionMatch := (request.BrowserVersion == "" && browserVersion == "") ||
(request.BrowserVersion == "stable" && browserVersion == "") ||
(strings.HasPrefix(browserVersion, request.BrowserVersion) && request.BrowserVersion != "" && browserVersion != "")
(request.BrowserVersion != "" && strings.HasPrefix(browserVersion, request.BrowserVersion))

// Check if platformName matches
platformNameMatch := request.PlatformName == "" && platformName == "" ||
strings.EqualFold(platformName, request.PlatformName)
platformNameMatch := (request.PlatformName == "" || strings.EqualFold("any", request.PlatformName) || strings.EqualFold(platformName, request.PlatformName)) &&
(platformName == "" || platformName == "any" || strings.EqualFold(platformName, request.PlatformName))

return browserNameMatch && browserVersionMatch && platformNameMatch
}

// This function checks if Node stereotypes or ongoing sessions match the scaler metadata
func checkStereotypeCapabilitiesMatch(capability Capability, browserName string, browserVersion string, sessionBrowserName string, platformName string) bool {
// Check if browserName matches
browserNameMatch := capability.BrowserName == "" && browserName == "" ||
browserNameMatch := (capability.BrowserName == "" && browserName == "") ||
strings.EqualFold(browserName, capability.BrowserName) ||
strings.EqualFold(sessionBrowserName, capability.BrowserName)

// Check if browserVersion matches
browserVersionMatch := capability.BrowserVersion == "" && browserVersion == "" ||
(strings.HasPrefix(browserVersion, capability.BrowserVersion) && capability.BrowserVersion != "" && browserVersion != "")
browserVersionMatch := (capability.BrowserVersion == "" && browserVersion == "") ||
(capability.BrowserVersion != "" && strings.HasPrefix(browserVersion, capability.BrowserVersion))

// Check if platformName matches
platformNameMatch := capability.PlatformName == "" && platformName == "" ||
strings.EqualFold(platformName, capability.PlatformName)
platformNameMatch := (capability.PlatformName == "" || strings.EqualFold("any", capability.PlatformName) || strings.EqualFold(platformName, capability.PlatformName)) &&
(platformName == "" || platformName == "any" || strings.EqualFold(platformName, capability.PlatformName))

return browserNameMatch && browserVersionMatch && platformNameMatch
}
Expand Down
68 changes: 68 additions & 0 deletions pkg/scalers/selenium_grid_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,74 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
wantOnGoingSessions: 2,
wantErr: false,
},
{
name: "1 queue request without platformName and scaler metadata without platfromName should return 1 new node and 1 ongoing session",
args: args{
b: []byte(`{
"data": {
"grid": {
"sessionCount": 2,
"maxSession": 2,
"totalSlots": 2
},
"nodesInfo": {
"nodes": [
{
"id": "node-1",
"status": "UP",
"sessionCount": 1,
"maxSession": 1,
"slotCount": 1,
"stereotypes": "[{\"slots\": 1, \"stereotype\": {\"browserName\": \"chrome\", \"platformName\": \"any\"}}]",
"sessions": [
{
"id": "session-1",
"capabilities": "{\"browserName\": \"chrome\", \"platformName\": \"any\"}",
"slot": {
"id": "9ce1edba-72fb-465e-b311-ee473d8d7b64",
"stereotype": "{\"browserName\": \"chrome\", \"platformName\": \"any\"}"
}
}
]
},
{
"id": "node-2",
"status": "UP",
"sessionCount": 1,
"maxSession": 1,
"slotCount": 1,
"stereotypes": "[{\"slots\": 1, \"stereotype\": {\"browserName\": \"chrome\", \"platformName\": \"linux\"}}]",
"sessions": [
{
"id": "session-2",
"capabilities": "{\"browserName\": \"chrome\", \"browserVersion\": \"91.0\", \"platformName\": \"linux\"}",
"slot": {
"id": "9ce1edba-72fb-465e-b311-ee473d8d7b64",
"stereotype": "{\"browserName\": \"chrome\", \"platformName\": \"linux\"}"
}
}
]
}
]
},
"sessionsInfo": {
"sessionQueueRequests": [
"{\"browserName\": \"chrome\", \"platformName\": \"linux\"}",
"{\"browserName\": \"chrome\"}",
"{\"browserName\": \"chrome\", \"platformName\": \"any\"}"
]
}
}
}`),
browserName: "chrome",
sessionBrowserName: "chrome",
browserVersion: "",
platformName: "",
},
wantNewRequestNodes: 2,
wantOnGoingSessions: 1,
wantErr: false,
},
{
name: "1 active session with matching browsername and version should return count as 2",
args: args{
Expand Down
Loading