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: Consider maxSessions in Selenium Grid Scaler #2774

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 @@ -43,6 +43,7 @@
- **GCP Pubsub Scaler** Adding e2e test for GCP PubSub scaler ([#1528](https://github.com/kedacore/keda/issues/1528))
- **Kafka Scaler** Make "disable" a valid value for tls auth parameter ([#2608](https://github.com/kedacore/keda/issues/2608))
- **RabbitMQ Scaler:** Include `vhost` for RabbitMQ when retrieving queue info with `useRegex` ([#2498](https://github.com/kedacore/keda/issues/2498))
- **Selenium Grid Scaler** Consider `maxSession` grid info when scaling. ([#2618](https://github.com/kedacore/keda/issues/2618))
JorTurFer marked this conversation as resolved.
Show resolved Hide resolved

### Breaking Changes

Expand Down
13 changes: 12 additions & 1 deletion pkg/scalers/selenium_grid_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ type seleniumResponse struct {
}

type data struct {
Grid grid `json:"grid"`
SessionsInfo sessionsInfo `json:"sessionsInfo"`
}

type grid struct {
MaxSession int `json:"maxSession"`
}

type sessionsInfo struct {
SessionQueueRequests []string `json:"sessionQueueRequests"`
Sessions []seleniumSession `json:"sessions"`
Expand Down Expand Up @@ -164,7 +169,7 @@ func (s *seleniumGridScaler) IsActive(ctx context.Context) (bool, error) {

func (s *seleniumGridScaler) getSessionsCount(ctx context.Context) (*resource.Quantity, error) {
body, err := json.Marshal(map[string]string{
"query": "{ sessionsInfo { sessionQueueRequests, sessions { id, capabilities, nodeId } } }",
"query": "{ grid { maxSession }, sessionsInfo { sessionQueueRequests, sessions { id, capabilities, nodeId } } }",
})

if err != nil {
Expand Down Expand Up @@ -238,5 +243,11 @@ func getCountFromSeleniumResponse(b []byte, browserName string, browserVersion s
}
}

var gridMaxSession = int64(seleniumResponse.Data.Grid.MaxSession)

if gridMaxSession > 0 {
count = (count + gridMaxSession - 1) / gridMaxSession
JorTurFer marked this conversation as resolved.
Show resolved Hide resolved
}

return resource.NewQuantity(count, resource.DecimalSI), nil
}
35 changes: 35 additions & 0 deletions pkg/scalers/selenium_grid_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
args: args{
b: []byte(`{
"data": {
"grid":{
"maxSession": 1
},
"sessionsInfo": {
"sessionQueueRequests": [],
"sessions": []
Expand All @@ -58,6 +61,9 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
args: args{
b: []byte(`{
"data": {
"grid":{
"maxSession": 1
},
"sessionsInfo": {
"sessionQueueRequests": ["{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}"],
"sessions": [
Expand All @@ -81,6 +87,9 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
args: args{
b: []byte(`{
"data": {
"grid":{
"maxSession": 1
},
"sessionsInfo": {
"sessionQueueRequests": ["{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}"],
"sessions": []
Expand All @@ -93,12 +102,35 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
want: resource.NewQuantity(2, resource.DecimalSI),
wantErr: false,
},
{
name: "active sessions with matching browsername and maxSession=2 should return count as 1",
args: args{
b: []byte(`{
"data": {
"grid":{
"maxSession": 2
},
"sessionsInfo": {
"sessionQueueRequests": ["{\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0\"\n}","{\n \"browserName\": \"chrome\"\n}"],
"sessions": []
}
}
}`),
browserName: "chrome",
browserVersion: "latest",
},
want: resource.NewQuantity(1, resource.DecimalSI),
wantErr: false,
},
{
name: "active sessions with matching browsername should return count as 3",
args: args{
b: []byte(`{
"data": {
"sessionsInfo": {
"grid":{
"maxSession": 1
},
"sessionQueueRequests": ["{\n \"browserName\": \"chrome\"\n}","{\n \"browserName\": \"chrome\"\n}"],
"sessions": [
{
Expand All @@ -121,6 +153,9 @@ func Test_getCountFromSeleniumResponse(t *testing.T) {
args: args{
b: []byte(`{
"data": {
"grid":{
"maxSession": 1
},
"sessionsInfo": {
"sessionQueueRequests": ["{\n \"browserName\": \"chrome\",\n \"browserVersion\": \"91.0\"\n}","{\n \"browserName\": \"chrome\"\n}"],
"sessions": [
Expand Down