Skip to content

Commit

Permalink
Selenium Grid: Add trigger param to set custom capabilities for match…
Browse files Browse the repository at this point in the history
…ing specific Nodes

Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Feb 9, 2025
1 parent 6986fe5 commit 0341263
Showing 1 changed file with 46 additions and 9 deletions.
55 changes: 46 additions & 9 deletions content/docs/2.17/scalers/selenium-grid-scaler.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ triggers:
browserName: '' # Optional. Required to be matched with the request in queue and Node stereotypes (Similarly for `browserVersion` and `platformName`).
browserVersion: '' # Optional.
platformName: '' # Optional.
unsafeSsl : 'false' # Optional.
unsafeSsl: 'false' # Optional.
activationThreshold: 0 # Optional.
```
Expand All @@ -37,6 +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)

**Trigger Authentication**
- `username` - Username for basic authentication in GraphQL endpoint instead of embedding in the URL. (Optional)
Expand Down Expand Up @@ -88,7 +89,7 @@ spec:
url: 'http://selenium-hub:4444/graphql'
browserName: 'chrome'
platformName: 'Linux'
unsafeSsl : 'true'
unsafeSsl: 'true'
```

Noted:
Expand Down Expand Up @@ -198,7 +199,7 @@ spec:
browserName: 'chrome'
platformName: 'Linux'
browserVersion: '131.0'
unsafeSsl : 'true'
unsafeSsl: 'true'
```

The request to trigger this scaler should be
Expand All @@ -210,6 +211,42 @@ options.set_capability('browserVersion', '131.0')
driver = webdriver.Remote(options=options, command_executor=SELENIUM_GRID_URL)
```

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

```yaml
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: selenium-grid-scaledobject-chrome-131
namespace: keda
labels:
deploymentName: selenium-node-chrome-131
spec:
maxReplicaCount: 8
scaleTargetRef:
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'
capabilities: "{\"myApp:version\": \"beta\", \"myApp:scope\": \"internal\"}"
```

The request to trigger this scaler should be

```python
options = ChromeOptions()
options.set_capability('platformName', 'Linux')
options.set_capability('browserVersion', '131.0')
options.set_capability('myApp:version', 'beta')
options.set_capability('myApp:scope', 'internal')
driver = webdriver.Remote(options=options, command_executor=SELENIUM_GRID_URL)
```

Similarly, for Firefox

```yaml
Expand All @@ -230,7 +267,7 @@ spec:
url: 'http://selenium-hub:4444/graphql'
browserName: 'firefox'
platformName: 'Linux'
unsafeSsl : 'true'
unsafeSsl: 'true'
```

Request to trigger the scaler
Expand Down Expand Up @@ -262,7 +299,7 @@ spec:
browserName: 'MicrosoftEdge'
sessionBrowserName: 'msedge'
platformName: 'Linux'
unsafeSsl : 'true'
unsafeSsl: 'true'
```

Request to trigger the scaler
Expand Down Expand Up @@ -294,7 +331,7 @@ spec:
browserName: 'chrome'
platformName: 'Linux'
nodeMaxSessions: 4
unsafeSsl : 'true'
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 @@ -318,7 +355,7 @@ spec:
browserName: 'chrome'
platformName: 'Linux'
browserVersion: '91.0'
unsafeSsl : 'true'
unsafeSsl: 'true'
```

```yaml
Expand All @@ -340,7 +377,7 @@ spec:
browserName: 'chrome'
platformName: 'Linux'
browserVersion: '90.0'
unsafeSsl : 'true'
unsafeSsl: 'true'
```

### Authentication Parameters
Expand Down Expand Up @@ -396,7 +433,7 @@ spec:
metadata:
browserName: 'chrome'
platformName: 'Linux'
unsafeSsl : 'true'
unsafeSsl: 'true'
authenticationRef:
name: keda-trigger-auth-selenium-grid-secret
```

0 comments on commit 0341263

Please sign in to comment.