|
| 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