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

Selenium Grid: Add trigger param to set custom capabilities for matching specific Nodes #6536

Merged
merged 2 commits into from
Feb 11, 2025

Conversation

VietND96
Copy link
Contributor

@VietND96 VietND96 commented Feb 9, 2025

Provide a description of what has been changed

Besides current main capabilities browserName, browserVersion, platformName are used for matching Node. Selenium Grid supports setting more custom capabilities for matching specific Nodes https://www.selenium.dev/documentation/grid/configuration/toml_options/#setting-custom-capabilities-for-matching-specific-nodes
Via this PR, one more trigger parameter is added with the name capabilities to define a JSON string with custom capabilities for matching specific Nodes. This helps users create more scalers to scale their Nodes with custom capabilities.

For example

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:132.0
          ports:
            - 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\"}"
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: selenium-grid-scaledobject-chrome-132
  namespace: keda
  labels:
    deploymentName: selenium-node-chrome-132
spec:
  maxReplicaCount: 8
  scaleTargetRef:
    name: selenium-node-chrome-132
  triggers:
    - type: selenium-grid
      metadata:
        url: 'http://selenium-hub:4444/graphql'
        browserName: 'chrome'
        platformName: 'Linux'
        browserVersion: '132.0'
        unsafeSsl: 'true'
        # Add custom capabilities for matching specific Nodes in scaler trigger metadata. See: https://github.com/kedacore/keda/pull/6536
        capabilities: "{\"myApp:version\":\"beta\", \"myApp:publish:\":\"public\"}"

The request to trigger this scaler should be

options = ChromeOptions()
options.set_capability('platformName', 'Linux')
options.set_capability('browserVersion', '132.0')
# Add custom capabilities for matching specific Nodes in client binding. See: https://www.selenium.dev/documentation/grid/configuration/toml_options/#setting-custom-capabilities-for-matching-specific-nodes
options.set_capability('myApp:version', 'beta')
options.set_capability('myApp:publish', 'public')
driver = webdriver.Remote(options=options, command_executor=SELENIUM_GRID_URL)

Checklist

Fixes #

Relates to #

@VietND96 VietND96 requested a review from a team as a code owner February 9, 2025 20:07
Signed-off-by: Viet Nguyen Duc <[email protected]>
@zroubalik
Copy link
Member

zroubalik commented Feb 10, 2025

/run-e2e selenium
Update: You can check the progress here

@zroubalik zroubalik merged commit 9d1db63 into kedacore:main Feb 11, 2025
19 checks passed
@VietND96 VietND96 deleted the pr-20250210 branch February 12, 2025 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants