Skip to content

Commit

Permalink
Update structure
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Feb 10, 2025
1 parent 03472ac commit 3b38f6f
Showing 1 changed file with 94 additions and 55 deletions.
149 changes: 94 additions & 55 deletions content/docs/2.17/scalers/selenium-grid-scaler.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ triggers:
- `activationThreshold` - Target value for activating the scaler. Learn more about activation [here](./../concepts/scaling-deployments.md#activating-and-scaling-thresholds). (Default: `0`, Optional)
- `platformName` - Name of the browser platform. Refer to the [Selenium Grid's](https://www.selenium.dev/documentation/en/getting_started_with_webdriver/browsers/) and [WebdriverIO's](https://webdriver.io/docs/options/#capabilities) documentation for more info. (Optional)
- `nodeMaxSessions` - Number of maximum sessions that can run in parallel on a Node. Update this parameter align with node config `--max-sessions` (`SE_NODE_MAX_SESSIONS`) to have the correct scaling behavior. (Default: `1`, Optional).
- `capabilities` - Add more custom capabilities for matching specific Nodes. (Optional)
- `capabilities` - Add more custom capabilities for matching specific Nodes. It should be in JSON string, see [example](https://www.selenium.dev/documentation/grid/configuration/toml_options/#setting-custom-capabilities-for-matching-specific-nodes) (Optional)

**Trigger Authentication**
- `username` - Username for basic authentication in GraphQL endpoint instead of embedding in the URL. (Optional)
Expand All @@ -47,6 +47,8 @@ triggers:

### Example

#### Selenium Grid scaler trigger metadata for Chrome browser with `platformNane` and empty `browserVersion`

Here is a full example of scaled object definition using Selenium Grid trigger:

```yaml
Expand Down Expand Up @@ -125,7 +127,7 @@ With above script, the request is sent to Grid. Via GraphQL response, it looks l
}
```

In Node deployment spec, there is environment variable `SE_NODE_BROWSER_VERSION` which is set to empty. This is used to unset `browserVersion` in Node stereotypes (it is in project [docker-selenium](https://github.com/SeleniumHQ/docker-selenium) setting short browser build number by default), which is expected to match with the request capabilities in queue and scaler trigger metadata.
In Node deployment spec, there is environment variable `SE_NODE_BROWSER_VERSION` which can be set to empty. This is used to unset `browserVersion` in Node stereotypes (it is in project [docker-selenium](https://github.com/SeleniumHQ/docker-selenium) setting short browser build number by default), which is expected to match with the request capabilities in queue and scaler trigger metadata.

When the request capabilities match with scaler trigger metadata, the scaler will create a new Node and connect to the Hub. Now the GraphQL response looks like

Expand Down Expand Up @@ -161,6 +163,8 @@ When the request capabilities match with scaler trigger metadata, the scaler wil

Now, the request can be picked up by the Node and the session is created. Session queue will be cleared and the scaler will not create a new Node until the next request comes in.

#### Selenium Grid scaler trigger metadata for Chrome browser with `browserVersion` and `platformName`

Moreover, at the same time, you can create one more scaled object for Chrome browser request with specific `browserVersion`. For example

```yaml
Expand All @@ -178,6 +182,11 @@ spec:
image: selenium/node-chrome:131.0
ports:
- containerPort: 5555
env:
- name: SE_NODE_BROWSER_VERSION
value: '131.0'
- name: SE_NODE_PLATFORM_NAME
value: 'Linux'
---
Expand Down Expand Up @@ -211,6 +220,8 @@ options.set_capability('browserVersion', '131.0')
driver = webdriver.Remote(options=options, command_executor=SELENIUM_GRID_URL)
```

#### Selenium Grid scaler trigger metadata with extra `capabilities`

For an advanced use case, you also can set custom capabilities for matching specific Nodes in the scaler trigger metadata. For example

```yaml
Expand All @@ -227,15 +238,15 @@ spec:
- name: selenium-node-chrome
image: selenium/node-chrome:132.0
ports:
- containerPort: 5555
- containerPort: 5555
env:
- name: SE_NODE_BROWSER_VERSION
value: '132.0'
- name: SE_NODE_PLATFORM_NAME
value: 'Linux'
# Append custom capabilities to Node stereotype. See: https://github.com/SeleniumHQ/docker-selenium?tab=readme-ov-file#node-configuration-options
- name: SE_NODE_STEREOTYPE_EXTRA
value: "{\"myApp:version\":\"beta\", \"myApp:publish:\":\"public\"}"
- name: SE_NODE_BROWSER_VERSION
value: '132.0'
- name: SE_NODE_PLATFORM_NAME
value: 'Linux'
# Append custom capabilities to Node stereotype. See: https://github.com/SeleniumHQ/docker-selenium?tab=readme-ov-file#node-configuration-options
- name: SE_NODE_STEREOTYPE_EXTRA
value: "{\"myApp:version\":\"beta\", \"myApp:publish:\":\"public\"}"
---
Expand Down Expand Up @@ -274,9 +285,31 @@ options.set_capability('myApp:publish', 'public')
driver = webdriver.Remote(options=options, command_executor=SELENIUM_GRID_URL)
```

Similarly, for Firefox
#### Selenium Grid scaler trigger metadata for Firefox browser

```yaml
kind: Deployment
metadata:
name: selenium-node-firefox
labels:
deploymentName: selenium-node-firefox
spec:
replicas: 1
template:
spec:
containers:
- name: selenium-node-firefox
image: selenium/node-firefox:latest
ports:
- containerPort: 5555
env:
- name: SE_NODE_BROWSER_VERSION
value: ''
- name: SE_NODE_PLATFORM_NAME
value: 'Linux'
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
Expand Down Expand Up @@ -305,9 +338,33 @@ options.set_capability('platformName', 'Linux')
driver = webdriver.Remote(options=options, command_executor=SELENIUM_GRID_URL)
```

#### Selenium Grid scaler trigger metadata for Edge browser

Similarly, for Edge. Note that for Edge you must set the `sessionBrowserName` to `msedge` inorder for scaling to work properly.

```yaml
kind: Deployment
metadata:
name: selenium-node-edge
labels:
deploymentName: selenium-node-edge
spec:
replicas: 1
template:
spec:
containers:
- name: selenium-node-edge
image: selenium/node-edge:latest
ports:
- containerPort: 5555
env:
- name: SE_NODE_BROWSER_VERSION
value: ''
- name: SE_NODE_PLATFORM_NAME
value: 'Linux'
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
Expand Down Expand Up @@ -337,73 +394,55 @@ options.set_capability('platformName', 'Linux')
driver = webdriver.Remote(options=options, command_executor=SELENIUM_GRID_URL)
```

#### Selenium Grid scaler trigger metadata for Chrome browser with `nodeMaxSessions`

In case you want to scale from 0 (`minReplicaCount: 0`), and browser nodes are configured different `--max-sessions` greater than 1, you can set `nodeMaxSessions` for scaler align with number of slots available per node to have the correct scaling behavior.

```yaml
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
kind: Deployment
metadata:
name: selenium-grid-chrome-scaledobject
namespace: keda
name: selenium-node-chrome
labels:
deploymentName: selenium-node-chrome
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-node-chrome
triggers:
- type: selenium-grid
metadata:
url: 'http://selenium-hub:4444/graphql'
browserName: 'chrome'
platformName: 'Linux'
nodeMaxSessions: 4
unsafeSsl: 'true'
```

If you are supporting multiple versions of browser capability in your Selenium Grid, You should create one scaler for every browser version and pass the `browserVersion` in the metadata.
replicas: 1
template:
spec:
containers:
- name: selenium-node-chrome
image: selenium/node-chrome:latest
ports:
- containerPort: 5555
env:
- name: SE_NODE_BROWSER_VERSION
value: ''
- name: SE_NODE_PLATFORM_NAME
value: 'Linux'
- name: SE_NODE_OVERRIDE_MAX_SESSIONS
value: 'true'
- name: SE_NODE_MAX_SESSIONS
value: '4'
```yaml
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: selenium-grid-chrome-91-scaledobject
namespace: keda
labels:
deploymentName: selenium-node-chrome-91
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-node-chrome-91
triggers:
- type: selenium-grid
metadata:
url: 'http://selenium-hub:4444/graphql'
browserName: 'chrome'
platformName: 'Linux'
browserVersion: '91.0'
unsafeSsl: 'true'
```
---
```yaml
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: selenium-grid-chrome-90-scaledobject
name: selenium-grid-chrome-scaledobject
namespace: keda
labels:
deploymentName: selenium-node-chrome-90
deploymentName: selenium-node-chrome
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-node-chrome-90
name: selenium-node-chrome
triggers:
- type: selenium-grid
metadata:
url: 'http://selenium-hub:4444/graphql'
browserName: 'chrome'
platformName: 'Linux'
browserVersion: '90.0'
nodeMaxSessions: 4
unsafeSsl: 'true'
```

Expand Down

0 comments on commit 3b38f6f

Please sign in to comment.