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

Update docs for Selenium Grid scaler #1515

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
221 changes: 194 additions & 27 deletions content/docs/2.16/scalers/selenium-grid-scaler.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ This specification describes the `selenium-grid` trigger that scales browser nod

The scaler creates one browser node per pending request in session queue, divided by the max amount of sessions that can run in parallel. You will have to create one trigger per browser capability that you would like to support in your Selenium Grid.

The below is an example trigger configuration for chrome node.
The below is an example trigger configuration with default values represent.

```yaml
triggers:
- type: selenium-grid
metadata:
url: 'http://selenium-hub:4444/graphql' # Required. Can be ommitted if specified via TriggerAuthentication/ClusterTriggerAuthentication.
browserName: 'chrome' # Required
browserVersion: '91.0' # Optional. Only required when supporting multiple versions of browser in your Selenium Grid.
unsafeSsl : 'true' # Optional
activationThreshold: 5 # Optional
platformName: 'Linux' # Optional
browserName: '' # Optional. Required to be matched with the request in queue and Node stereotypes (Similarly for `browserVersion` and `platformName`).
browserVersion: '' # Optional.
platformName: 'linux' # Optional.
unsafeSsl : 'false' # Optional.
activationThreshold: 0 # Optional.
```

**Parameter list:**

- `url` - Graphql url of your Selenium Grid. Refer to the Selenium Grid's documentation [here](https://www.selenium.dev/documentation/en/grid/grid_4/graphql_support/) to for more info. If endpoint requires authentication, you can use `TriggerAuthentication` to provide the credentials instead of embedding in the URL.
- `browserName` - Name of browser that usually gets passed in the browser capability. 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.
- `browserName` - Name of browser that usually gets passed in the browser capability. 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)
- `sessionBrowserName` - Name of the browser when it is an active session, only set if `BrowserName` changes between the queue and the active session. See the Edge example below for further detail. (Optional)
- `browserVersion` - Version of browser that usually gets passed in the browser capability. 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)
- `unsafeSsl` - Skip certificate validation when connecting over HTTPS. (Values: `true`, `false`, Default: `false`, Optional)
Expand All @@ -49,67 +49,226 @@ triggers:
Here is a full example of scaled object definition using Selenium Grid trigger:

```yaml
kind: Deployment
metadata:
name: selenium-node-chrome
labels:
deploymentName: selenium-node-chrome
spec:
replicas: 1
template:
spec:
containers:
- name: selenium-node-chrome
image: selenium/node-chrome:latest
ports:
- containerPort: 5555
env:
- name: SE_NODE_BROWSER_VERSION
value: ''

---

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: selenium-grid-chrome-scaledobject
name: selenium-grid-scaledobject-chrome
namespace: keda
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'
unsafeSsl : 'true'
```

Noted:
- From `v2.16.1+`, the trigger metadata `browserVersion`, `platformName` is recommended to be set explicitly to have the correct scaling behavior (especially when your Grid includes autoscaling Nodes, non-autoscaling Nodes, relay Nodes, etc.). Besides that, in client binding, it is also recommended to set the `browserVersion`, `platformName` to align with the trigger metadata. Please see below examples for more details.

The above example will create Chrome browser nodes equal to the requests pending in session queue for Chrome browser, which is created from client. For example in Python binding

```python
options = ChromeOptions()
options.set_capability('platformName', 'Linux')
driver = webdriver.Remote(options=options, command_executor=SELENIUM_GRID_URL)
```

With above script, the request is sent to Grid. Via GraphQL response, it looks like

```json
{
"data": {
"grid": {
"sessionCount": 0,
"maxSession": 0,
"totalSlots": 0
},
"nodesInfo": {
"nodes": []
},
"sessionsInfo": {
"sessionQueueRequests": [
"{\"browserName\": \"chrome\", \"platformName\": \"linux\"}"
]
}
}
}
```

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.

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

```json
{
"data": {
"grid": {
"sessionCount": 0,
"maxSession": 1,
"totalSlots": 1
},
"nodesInfo": {
"nodes": [
{
"id": "UUID-of-Node",
"status": "UP",
"sessionCount": 0,
"maxSession": 1,
"slotCount": 1,
"stereotypes": "[{\"slots\": 1, \"stereotype\": {\"browserName\": \"chrome\", \"browserVersion\": \"\", \"platformName\": \"Linux\"}}]",
"sessions": []
}
]
},
"sessionsInfo": {
"sessionQueueRequests": [
"{\"browserName\": \"chrome\", \"platformName\": \"linux\"}"
]
}
}
}
```

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.

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

```yaml
kind: Deployment
metadata:
name: selenium-node-chrome-131
labels:
deploymentName: selenium-node-chrome-131
spec:
replicas: 1
template:
spec:
containers:
- name: selenium-node-chrome
image: selenium/node-chrome:131.0
ports:
- containerPort: 5555

---

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

The above example will create Chrome browser nodes equal to the requests pending in session queue for Chrome browser.
The request to trigger this scaler should be

```python
options = ChromeOptions()
options.set_capability('platformName', 'Linux')
options.set_capability('browserVersion', '131.0')
driver = webdriver.Remote(options=options, command_executor=SELENIUM_GRID_URL)
```

Similarly for Firefox
Similarly, for Firefox

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

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

```python
options = FirefoxOptions()
options.set_capability('platformName', 'Linux')
driver = webdriver.Remote(options=options, command_executor=SELENIUM_GRID_URL)
```

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

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

Request to trigger the scaler

```python
options = EdgeOptions()
options.set_capability('platformName', 'Linux')
driver = webdriver.Remote(options=options, command_executor=SELENIUM_GRID_URL)
```

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.
Expand All @@ -121,17 +280,19 @@ metadata:
name: selenium-grid-chrome-scaledobject
namespace: keda
labels:
deploymentName: selenium-chrome-node
deploymentName: selenium-node-chrome
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-chrome-node
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.
Expand All @@ -143,17 +304,19 @@ metadata:
name: selenium-grid-chrome-91-scaledobject
namespace: keda
labels:
deploymentName: selenium-chrome-node-91
deploymentName: selenium-node-chrome-91
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-chrome-node-91
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
Expand All @@ -163,17 +326,19 @@ metadata:
name: selenium-grid-chrome-90-scaledobject
namespace: keda
labels:
deploymentName: selenium-chrome-node-90
deploymentName: selenium-node-chrome-90
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-chrome-node-90
name: selenium-node-chrome-90
triggers:
- type: selenium-grid
metadata:
url: 'http://selenium-hub:4444/graphql'
browserName: 'chrome'
platformName: 'Linux'
browserVersion: '90.0'
unsafeSsl : 'true'
```

### Authentication Parameters
Expand Down Expand Up @@ -219,15 +384,17 @@ metadata:
name: selenium-grid-chrome-scaledobject
namespace: keda
labels:
deploymentName: selenium-chrome-node
deploymentName: selenium-node-chrome
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-chrome-node
name: selenium-node-chrome
triggers:
- type: selenium-grid
metadata:
browserName: 'chrome'
platformName: 'Linux'
unsafeSsl : 'true'
authenticationRef:
name: keda-trigger-auth-selenium-grid-secret
```
Loading
Loading