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 scaledObject always matching when browserVersion is latest in trigger metadata #4348

Merged
merged 3 commits into from
Mar 9, 2023
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 @@ -94,6 +94,7 @@ Here is an overview of all new **experimental** features:
- **NATS Jetstream Scaler:** Fix compatibility when cluster not on kubernetes ([#4101](https://github.com/kedacore/keda/issues/4101))
- **Prometheus Metrics**: Expose Prometheus Metrics also when getting ScaledObject state ([#4075](https://github.com/kedacore/keda/issues/4075))
- **Redis Scalers**: Fix panic produced by incorrect logger initialization ([#4197](https://github.com/kedacore/keda/issues/4197))
- **Selenium Grid Scaler**: ScaledObject with a trigger whose metadata browserVersion is latest is always being triggered regardless of the browserVersion requested by the user ([#4347](https://github.com/kedacore/keda/issues/4347))

### Deprecations

Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/selenium_grid_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func getCountFromSeleniumResponse(b []byte, browserName string, browserVersion s
var platformNameMatches = capability.PlatformName == "" || strings.EqualFold(capability.PlatformName, platformName)
if strings.HasPrefix(capability.BrowserVersion, browserVersion) && platformNameMatches {
count++
} else if browserVersion == DefaultBrowserVersion && platformNameMatches {
} else if len(strings.TrimSpace(capability.BrowserVersion)) == 0 && browserVersion == DefaultBrowserVersion && platformNameMatches {
count++
}
}
Expand All @@ -255,7 +255,7 @@ func getCountFromSeleniumResponse(b []byte, browserName string, browserVersion s
if capability.BrowserName == sessionBrowserName {
if strings.HasPrefix(capability.BrowserVersion, browserVersion) && platformNameMatches {
count++
} else if browserVersion == DefaultBrowserVersion && platformNameMatches {
} else if len(strings.TrimSpace(capability.BrowserVersion)) == 0 && browserVersion == DefaultBrowserVersion && platformNameMatches {
count++
}
}
Expand Down
52 changes: 37 additions & 15 deletions pkg/scalers/selenium_grid_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,36 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
wantErr: false,
},
{
name: "2 active sessions with matching browsername on 2 nodes and maxSession=4 should return count as 3 (rounded up from 2.5)",
name: "2 session queue with matching browsername and browserversion should return count as 1",
args: args{
b: []byte(`{
"data": {
"grid":{
"maxSession": 4,
"nodeCount": 2
},
"sessionsInfo": {
"sessionQueueRequests": ["{\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0\"\n}","{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}"]
}
}
}`),
browserName: "chrome",
sessionBrowserName: "chrome",
browserVersion: "latest",
platformName: "linux",
},
want: 1,
wantErr: false,
},
{
name: "2 active sessions with matching browsername on 2 nodes and maxSession=4 should return count as 1 (rounded up from 0.75)",
args: args{
b: []byte(`{
"data": {
"grid":{
"maxSession": 4,
"nodeCount": 1
},
"sessionsInfo": {
"sessionQueueRequests": ["{\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0\"\n}","{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}"],
"sessions": [
Expand All @@ -139,14 +161,14 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
}`),
browserName: "chrome",
sessionBrowserName: "chrome",
browserVersion: "latest",
browserVersion: "91.0",
platformName: "linux",
},
want: 3,
want: 1,
wantErr: false,
},
{
name: "2 active sessions with matching browsername on 1 node and maxSession=3 should return count as 2 (rounded up from 1.33)",
name: "2 active sessions with matching browsername on 1 node and maxSession=3 should return count as 1 (rounded up from 0.33)",
args: args{
b: []byte(`{
"data": {
Expand Down Expand Up @@ -176,20 +198,20 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
browserVersion: "latest",
platformName: "linux",
},
want: 2,
want: 1,
wantErr: false,
},
{
name: "2 active sessions with matching browsername on 2 nodes should return count as 5",
args: args{
b: []byte(`{
"data": {
"grid":{
"maxSession": 2,
"nodeCount": 2
},
"sessionsInfo": {
"grid":{
"maxSession": 2,
"nodeCount": 2
},
"sessionQueueRequests": ["{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}"],
"sessionQueueRequests": ["{\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0\"\n}","{\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0\"\n}","{\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0\"\n}"],
"sessions": [
{
"id": "0f9c5a941aa4d755a54b84be1f6535b1",
Expand All @@ -207,7 +229,7 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
}`),
browserName: "chrome",
sessionBrowserName: "chrome",
browserVersion: "latest",
browserVersion: "91.0",
platformName: "linux",
},
want: 5,
Expand Down Expand Up @@ -252,7 +274,7 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
"nodeCount": 1
},
"sessionsInfo": {
"sessionQueueRequests": ["{\n \"browserName\": \"MicrosoftEdge\"\n}","{\n \"browserName\": \"MicrosoftEdge\"\n}"],
"sessionQueueRequests": ["{\n \"browserName\": \"MicrosoftEdge\",\n \"browserVersion\": \"91.0\"\n}","{\n \"browserName\": \"MicrosoftEdge\",\n \"browserVersion\": \"91.0\"\n}"],
"sessions": [
{
"id": "0f9c5a941aa4d755a54b84be1f6535b1",
Expand All @@ -265,7 +287,7 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
}`),
browserName: "MicrosoftEdge",
sessionBrowserName: "msedge",
browserVersion: "latest",
browserVersion: "91.0",
platformName: "linux",
},
want: 3,
Expand Down Expand Up @@ -385,7 +407,7 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
"nodeCount": 1
},
"sessionsInfo": {
"sessionQueueRequests": ["{\n \"browserName\": \"chrome\",\n \"platformName\": \"linux\"\n}","{\n \"browserName\": \"chrome\",\n \"platformName\": \"Windows 11\"\n}"],
"sessionQueueRequests": ["{\n \"browserName\": \"chrome\",\n \"platformName\": \"linux\"\n}","{\n \"browserName\": \"chrome\",\n \"platformName\": \"Windows 11\",\n \"browserVersion\": \"91.0\"\n}"],
"sessions": [
{
"id": "0f9c5a941aa4d755a54b84be1f6535b1",
Expand All @@ -403,7 +425,7 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
}`),
browserName: "chrome",
sessionBrowserName: "chrome",
browserVersion: "latest",
browserVersion: "91.0",
platformName: "Windows 11",
},
want: 2,
Expand Down