Skip to content

Commit 2af6166

Browse files
authored
Experimental: Selenium Grid scaler in K8s implementation preview (#2400)
1 parent e27f6ed commit 2af6166

15 files changed

+2555
-21
lines changed

Diff for: .github/workflows/deploy.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ jobs:
152152
continue_on_error: true
153153
command: VERSION="${GRID_VERSION}" BUILD_DATE=${BUILD_DATE} make release_latest
154154
- name: Update package versions
155-
run: make generate_latest_sbom
155+
run: |
156+
make generate_latest_sbom
157+
make fetch_grid_scaler_resources
156158
- name: Tag browser images
157159
if: github.event.inputs.skip-build-push-image != 'true'
158160
uses: nick-invision/retry@master

Diff for: .keda/README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Introduction
2+
3+
Selenium Grid Scaler is a built-in scaler is maintained in upstream KEDA [repository](https://github.com/kedacore/keda). The scaler implementation could be found [here](https://github.com/kedacore/keda/blob/main/pkg/scalers/selenium_grid_scaler.go). The official docs of the scaler could be seen [here](https://keda.sh/docs/latest/scalers/selenium-grid-scaler/).
4+
5+
Now, [SeleniumHQ/docker-selenium](https://github.com/SeleniumHQ/docker-selenium) involves as the maintainer for the scaler.
6+
7+
In order to deliver and get feedback continuously on any new bug fixes, improvement, or features for the Selenium Grid scaler. We select the latest stable version of KEDA core, patch the scaler implementation then build and deploy KEDA container images following our image tag convention.
8+
9+
The stable implementation will be merged to the upstream KEDA repository frequently and will be available in the next KEDA core release.
10+
11+
# How to use the patched scaler
12+
13+
Replace the image registry and tag of these KEDA components with the patched image tag:
14+
15+
```bash
16+
docker pull selenium/keda:2.15.1-selenium-grid-20240907
17+
docker pull selenium/keda-metrics-apiserver:2.15.1-selenium-grid-20240907
18+
docker pull selenium/keda-admission-webhooks:2.15.1-selenium-grid-20240907
19+
```
20+
21+
Besides that, you also can use image tag `latest` or `nightly`.
22+
23+
If you are deploying KEDA core using their official Helm chart, you can overwrite the image registry and tag by providing the following values in the `values.yaml` file. For example:
24+
25+
```yaml
26+
image:
27+
keda:
28+
registry: selenium
29+
repository: keda
30+
tag: "2.15.1-selenium-grid-20240907"
31+
metricsApiServer:
32+
registry: selenium
33+
repository: keda-metrics-apiserver
34+
tag: "2.15.1-selenium-grid-20240907"
35+
webhooks:
36+
registry: selenium
37+
repository: keda-admission-webhooks
38+
tag: "2.15.1-selenium-grid-20240907"
39+
```
40+
41+
If you are deployment Selenium Grid chart with `autoscaling.enabled` is `true` (implies installing KEDA sub-chart), KEDA images registry and tag already set in the `values.yaml`. Refer to list [configuration](../charts/selenium-grid/CONFIGURATION.md).
42+
43+
# Pull requests under testing
44+
45+
Here is list of pull requests that are under testing and will be merged to the upstream KEDA repository.
46+
You can involve to review and discuss the pull requests to help us early detect and fix any issues.
47+
48+
[kedacore/keda](https://github.com/kedacore/keda)
49+
50+
- https://github.com/kedacore/keda/pull/6169
51+
52+
[kedacore/keda-docs](https://github.com/kedacore/keda-docs)
53+
54+
- https://github.com/kedacore/keda-docs/pull/1468
55+
56+
# Resources
57+
58+
You can inspect the implementation of current Selenium Grid scaler:
59+
60+
- [selenium_grid_scaler.go](./scalers/selenium_grid_scaler.go)
61+
- [selenium_grid_scaler_test.go](./scalers/selenium_grid_scaler_test.go)
62+
- [selenium-grid-scaler.md](./scalers/selenium-grid-scaler.md)

Diff for: .keda/scalers/selenium-grid-scaler.md

+207
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
+++
2+
title = "Selenium Grid Scaler"
3+
availability = "v2.4+"
4+
maintainer = "Volvo Cars, SeleniumHQ"
5+
category = "Testing"
6+
description = "Scales Selenium browser nodes based on number of requests waiting in session queue"
7+
go_file = "selenium_grid_scaler"
8+
+++
9+
10+
### Trigger Specification
11+
12+
This specification describes the `selenium-grid` trigger that scales browser nodes based on number of requests in session queue and the max sessions per grid.
13+
14+
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.
15+
16+
The below is an example trigger configuration for chrome node.
17+
18+
```yaml
19+
triggers:
20+
- type: selenium-grid
21+
metadata:
22+
url: 'http://selenium-hub:4444/graphql' # Required. Can be ommitted if specified via TriggerAuthentication/ClusterTriggerAuthentication.
23+
browserName: 'chrome' # Required
24+
browserVersion: '91.0' # Optional. Only required when supporting multiple versions of browser in your Selenium Grid.
25+
unsafeSsl : 'true' # Optional
26+
activationThreshold: 5 # Optional
27+
platformName: 'Linux' # Optional
28+
```
29+
30+
**Parameter list:**
31+
32+
- `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.
33+
- `username` - Username for basic authentication in GraphQL endpoint instead of embedding in the URL. (Optional)
34+
- `password` - Password for basic authentication in GraphQL endpoint instead of embedding in the URL. (Optional)
35+
- `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.
36+
- `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)
37+
- `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)
38+
- `unsafeSsl` - Skip certificate validation when connecting over HTTPS. (Values: `true`, `false`, Default: `false`, Optional)
39+
- `activationThreshold` - Target value for activating the scaler. Learn more about activation [here](./../concepts/scaling-deployments.md#activating-and-scaling-thresholds). (Default: `0`, Optional)
40+
- `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. (Default: `Linux`, Optional)
41+
- `nodeMaxSessions` - Number of maximum sessions that can run in parallel on a Node. (Default: `1`, Optional). Update this parameter align with node config `--max-sessions` (`SE_NODE_MAX_SESSIONS`) to have the correct scaling behavior.
42+
43+
### Example
44+
45+
Here is a full example of scaled object definition using Selenium Grid trigger:
46+
47+
```yaml
48+
apiVersion: keda.sh/v1alpha1
49+
kind: ScaledObject
50+
metadata:
51+
name: selenium-grid-chrome-scaledobject
52+
namespace: keda
53+
labels:
54+
deploymentName: selenium-chrome-node
55+
spec:
56+
maxReplicaCount: 8
57+
scaleTargetRef:
58+
name: selenium-chrome-node
59+
triggers:
60+
- type: selenium-grid
61+
metadata:
62+
url: 'http://selenium-hub:4444/graphql'
63+
browserName: 'chrome'
64+
```
65+
66+
The above example will create Chrome browser nodes equal to the requests pending in session queue for Chrome browser.
67+
68+
Similarly for Firefox
69+
70+
```yaml
71+
apiVersion: keda.sh/v1alpha1
72+
kind: ScaledObject
73+
metadata:
74+
name: selenium-grid-firefox-scaledobject
75+
namespace: keda
76+
labels:
77+
deploymentName: selenium-firefox-node
78+
spec:
79+
maxReplicaCount: 8
80+
scaleTargetRef:
81+
name: selenium-firefox-node
82+
triggers:
83+
- type: selenium-grid
84+
metadata:
85+
url: 'http://selenium-hub:4444/graphql'
86+
browserName: 'firefox'
87+
```
88+
89+
Similarly for Edge. Note that for Edge you must set the `sessionBrowserName` to `msedge` inorder for scaling to work properly.
90+
91+
```yaml
92+
apiVersion: keda.sh/v1alpha1
93+
kind: ScaledObject
94+
metadata:
95+
name: selenium-grid-edge-scaledobject
96+
namespace: keda
97+
labels:
98+
deploymentName: selenium-edge-node
99+
spec:
100+
maxReplicaCount: 8
101+
scaleTargetRef:
102+
name: selenium-edge-node
103+
triggers:
104+
- type: selenium-grid
105+
metadata:
106+
url: 'http://selenium-hub:4444/graphql'
107+
browserName: 'MicrosoftEdge'
108+
sessionBrowserName: 'msedge'
109+
```
110+
111+
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.
112+
113+
```yaml
114+
apiVersion: keda.sh/v1alpha1
115+
kind: ScaledObject
116+
metadata:
117+
name: selenium-grid-chrome-91-scaledobject
118+
namespace: keda
119+
labels:
120+
deploymentName: selenium-chrome-node-91
121+
spec:
122+
maxReplicaCount: 8
123+
scaleTargetRef:
124+
name: selenium-chrome-node-91
125+
triggers:
126+
- type: selenium-grid
127+
metadata:
128+
url: 'http://selenium-hub:4444/graphql'
129+
browserName: 'chrome'
130+
browserVersion: '91.0'
131+
```
132+
133+
```yaml
134+
apiVersion: keda.sh/v1alpha1
135+
kind: ScaledObject
136+
metadata:
137+
name: selenium-grid-chrome-90-scaledobject
138+
namespace: keda
139+
labels:
140+
deploymentName: selenium-chrome-node-90
141+
spec:
142+
maxReplicaCount: 8
143+
scaleTargetRef:
144+
name: selenium-chrome-node-90
145+
triggers:
146+
- type: selenium-grid
147+
metadata:
148+
url: 'http://selenium-hub:4444/graphql'
149+
browserName: 'chrome'
150+
browserVersion: '90.0'
151+
```
152+
153+
### Authentication Parameters
154+
155+
It is possible to specify the Graphql url of your Selenium Grid using authentication parameters. This useful if you have enabled Selenium Grid's Basic HTTP Authentication and would like to keep your credentials secure.
156+
157+
- `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/) for more info.
158+
- `username` - Username for basic authentication in GraphQL endpoint instead of embedding in the URL. (Optional)
159+
- `password` - Password for basic authentication in GraphQL endpoint instead of embedding in the URL. (Optional)
160+
161+
```yaml
162+
apiVersion: v1
163+
kind: Secret
164+
metadata:
165+
name: selenium-grid-secret
166+
namespace: keda
167+
type: Opaque
168+
data:
169+
graphql-url: base64 encoded value of GraphQL URL
170+
graphql-username: base64 encoded value of GraphQL Username
171+
graphql-password: base64 encoded value of GraphQL Password
172+
---
173+
apiVersion: keda.sh/v1alpha1
174+
kind: TriggerAuthentication
175+
metadata:
176+
name: keda-trigger-auth-selenium-grid-secret
177+
namespace: keda
178+
spec:
179+
secretTargetRef:
180+
- parameter: url
181+
name: selenium-grid-secret
182+
key: graphql-url
183+
- parameter: username
184+
name: selenium-grid-secret
185+
key: graphql-username
186+
- parameter: password
187+
name: selenium-grid-secret
188+
key: graphql-password
189+
---
190+
apiVersion: keda.sh/v1alpha1
191+
kind: ScaledObject
192+
metadata:
193+
name: selenium-grid-chrome-scaledobject
194+
namespace: keda
195+
labels:
196+
deploymentName: selenium-chrome-node
197+
spec:
198+
maxReplicaCount: 8
199+
scaleTargetRef:
200+
name: selenium-chrome-node
201+
triggers:
202+
- type: selenium-grid
203+
metadata:
204+
browserName: 'chrome'
205+
authenticationRef:
206+
name: keda-trigger-auth-selenium-grid-secret
207+
```

0 commit comments

Comments
 (0)