Skip to content

[KEDA] Selenium Grid: Add trigger param overProvisionRatio for ability to scale more than queue request #2907

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

Merged
merged 1 commit into from
Jul 23, 2025

Conversation

VietND96
Copy link
Member

@VietND96 VietND96 commented Jul 21, 2025

User description

Thanks for contributing to the Docker-Selenium project!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines, applied for this repository.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Feature preview of kedacore/keda#6920

Add trigger param overProvisionRatio (float64) to add the ability to scale more than the queue request (called over-provisioned). Since this comes from a request #3453, plus 3 votes. Moreover, I believe this helps in autoscaling Deployment, scale Nodes based on request queue with a buffer (warm standby Nodes are available for a while, since process of a Node container from start up, get ready, registered to Hub, and pick up session would take time, a buffer for peak loads period would be an approach that users are prefer).

  • For example, if there are 20 requests for the browser instead of scaling to 20 Nodes, it is able to scale 20% more than the requested, in this case is 24.
  • With the above example, the trigger param overProvisionRatio is set to 0.2 (representing 20% percentage more than base request)
  • The trigger param only accepts values greater than 0. Otherwise, it will not take effect.

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement


Description

  • Add overProvisionRatio parameter to Selenium Grid KEDA scaler

  • Enable scaling beyond queue request count for better resource provisioning

  • Update metadata structure with float64 types for scaling parameters

  • Update KEDA image tags to latest version (20250721)


Diagram Walkthrough

flowchart LR
  A["Queue Requests"] --> B["getScaledCount()"]
  B --> C["Apply overProvisionRatio"]
  C --> D["Scaled Metric Value"]
  D --> E["KEDA Scaling Decision"]
Loading

File Walkthrough

Relevant files
Enhancement
selenium_grid_scaler.go
Add over-provision ratio scaling logic                                     

.keda/scalers/selenium_grid_scaler.go

  • Add OverProvisionRatio field to metadata struct
  • Change TargetValue and ActivationThreshold from int64 to float64
  • Implement getScaledCount() function to apply over-provision ratio
  • Update metric generation to use scaled count with ratio
+31/-23 
Tests
selenium_grid_scaler_test.go
Update tests for over-provision ratio                                       

.keda/scalers/selenium_grid_scaler_test.go

  • Add overProvisionRatio parameter to test arguments
  • Add test case for over-provision ratio functionality
  • Update test assertions to validate scaled count calculations
  • Remove hardcoded TargetValue from expected metadata
+57/-14 
Documentation
README.md
Update KEDA image tags and documentation                                 

.keda/README.md

  • Update KEDA image tags from 20250717 to 20250721
  • Add reference to upstream PR #6920 for v2.18.0
+8/-6     
CONFIGURATION.md
Add KEDA image configuration documentation                             

charts/selenium-grid/CONFIGURATION.md

  • Add documentation for keda.image configuration object
  • Document KEDA component image registry and tag settings
+1/-0     
Configuration changes
Makefile
Update KEDA build configuration                                                   

Makefile

  • Update KEDA_BASED_TAG from 20250705 to 20250721
  • Change TEST_PATCHED_KEDA from false to true
+2/-2     
values.yaml
Update KEDA image defaults in Helm chart                                 

charts/selenium-grid/values.yaml

  • Uncomment and update KEDA image configuration
  • Update all KEDA component tags to 20250721
  • Enable KEDA image overrides in default values
+13/-13 

Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Logic Error

The over-provision ratio is only applied when greater than 1, but this prevents using ratios between 0 and 1 for under-provisioning scenarios. The condition should allow any positive ratio or have clear documentation about the intended behavior.

if overProvisionRatio > 1 {
	// Apply over-provision ratio to the scaled count
	scaledCount *= overProvisionRatio
}
return scaledCount
Breaking Change

Changing TargetValue and ActivationThreshold from int64 to float64 is a breaking change that could affect existing configurations. The migration path and backward compatibility should be considered.

TargetValue            float64 `keda:"name=targetValue,              order=triggerMetadata, optional"`
ActivationThreshold    float64 `keda:"name=activationThreshold,      order=triggerMetadata, optional"`
Missing Validation

The overProvisionRatio parameter lacks validation for negative values or extremely large values that could cause unexpected scaling behavior. Input validation should be added to prevent invalid configurations.

OverProvisionRatio     float64 `keda:"name=overProvisionRatio,       order=triggerMetadata, optional"`
UnsafeSsl              bool    `keda:"name=unsafeSsl,                order=triggerMetadata, optional"`

Copy link
Contributor

qodo-merge-pro bot commented Jul 21, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Fix misleading error message

The error message is misleading as it mentions "GraphQL response" but the actual
error is from parsing metadata configuration, not a GraphQL response.

.keda/scalers/selenium_grid_scaler.go [179]

-return nil, fmt.Errorf("error parsing Selenium Grid GraphQL response: %w", err)
+return nil, fmt.Errorf("error parsing selenium grid metadata: %w", err)
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a misleading error message that was introduced in the PR, improving clarity and making debugging easier.

Medium
Validate over-provision ratio bounds

The function should validate that overProvisionRatio is not negative or zero to
prevent unexpected scaling behavior. Add a check to ensure the ratio is positive
before applying it.

.keda/scalers/selenium_grid_scaler.go [211-218]

 func getScaledCount(newRequestNodes int64, onGoingSession int64, overProvisionRatio float64) float64 {
 	scaledCount := float64(newRequestNodes + onGoingSession)
 	if overProvisionRatio > 1 {
 		// Apply over-provision ratio to the scaled count
 		scaledCount *= overProvisionRatio
+	} else if overProvisionRatio > 0 && overProvisionRatio <= 1 {
+		// For ratios between 0 and 1, still apply the ratio
+		scaledCount *= overProvisionRatio
 	}
+	// If overProvisionRatio <= 0, return original scaledCount
 	return scaledCount
 }
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that overProvisionRatio should be handled for values other than > 1, improving robustness by preventing negative or zero ratios from causing unexpected scaling.

Low
  • Update

@VietND96 VietND96 force-pushed the new-keda branch 2 times, most recently from 270ca79 to 9673bc2 Compare July 23, 2025 02:02
…y to scale more than queue request

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
@VietND96 VietND96 changed the title [KEDA] Selenium Grid: Add trigger param overProvisionRatio for ability to scale more than queue request [KEDA] Selenium Grid: Add trigger param overProvisionRatio for ability to scale more than queue request Jul 23, 2025
@VietND96 VietND96 merged commit 77bd816 into trunk Jul 23, 2025
54 of 55 checks passed
@VietND96 VietND96 deleted the new-keda branch July 23, 2025 07:14
VietND96 added a commit to NDViet/docker-selenium that referenced this pull request Jul 25, 2025
…ity to scale more than queue request (SeleniumHQ#2907)

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant