-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[grid] Improve SlotMatcher and SlotSelector on request browserVersion #14914
base: trunk
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
CI Failure Feedback 🧐(Checks updated until commit 7369c6a)
|
public String getBrowserVersion() { | ||
return slots.parallelStream() | ||
.map(slot -> slot.getStereotype().getBrowserVersion()) | ||
.filter(Objects::nonNull) | ||
.min(NodeStatus::semVerComparator) | ||
.orElse(""); | ||
} | ||
|
||
public static int semVerComparator(String v1, String v2) { | ||
// Custom semver comparator with empty strings first | ||
if (v1.isEmpty() && v2.isEmpty()) return 0; | ||
if (v1.isEmpty()) return -1; // Empty string comes first | ||
if (v2.isEmpty()) return 1; | ||
|
||
String[] parts1 = v1.split("\\."); | ||
String[] parts2 = v2.split("\\."); | ||
|
||
int maxLength = Math.max(parts1.length, parts2.length); | ||
for (int i = 0; i < maxLength; i++) { | ||
String part1 = i < parts1.length ? parts1[i] : "0"; | ||
String part2 = i < parts2.length ? parts2[i] : part1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code shouldn't be here. It probably belongs to the DefaultSlotMatcher
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it to CapabilitiesComparator
for reusable. Since this is used for both sorting in selector and slot matcher
// Then sort by stereotype browserVersion (descending order). SemVer comparison with | ||
// considering empty value at first. | ||
.thenComparing( | ||
Comparator.comparing( | ||
NodeStatus::getBrowserVersion, NodeStatus::semVerComparator)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The semVerComparator
returns true
or false
. This is more suitable for a filter. Which is done below, through the matcher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still needed since multiple matches returned from SlotMatcher should be sorted to move the latest version to top
744678d
to
00449d7
Compare
Signed-off-by: Viet Nguyen Duc <[email protected]>
00449d7
to
7369c6a
Compare
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
This improvement helps autoscaling control strictly on a request without the capability to set
browserVersion
will be assigned to list Slots with top priority on stereotype withoutbrowserVersion
or a latestbrowserVersion
(based on SemVer comparison).Improve DefaultSlotMatcher, where the request with cap
browserVersion=130
can match to slot with stereotypebrowserVersion=130.0
(based on SemVer comparison return 0). Few corner case also covered e.gMotivation and Context
This pull request introduces several important changes to the Selenium Grid project, focusing on improving the way browser versions are compared and sorted. The changes include implementing a custom semantic version comparator, updating the slot selection logic, and adding relevant tests.
Improvements to browser version comparison:
java/src/org/openqa/selenium/grid/data/NodeStatus.java
: Added agetBrowserVersion
method and a customsemVerComparator
method for comparing semantic versions with empty strings considered first.Updates to slot selection logic:
java/src/org/openqa/selenium/grid/data/DefaultSlotMatcher.java
: Modified thematches
method to use the newsemVerComparator
for browser version comparison.java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java
: Updated the slot selection logic to sort nodes by browser version using the new comparator.Addition of tests:
java/test/org/openqa/selenium/grid/data/NodeStatusTest.java
: Added tests for thesemVerComparator
method to ensure correct browser version matching.java/test/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelectorTest.java
: Added tests to verify nodes are ordered correctly by browser version. [1] [2]Miscellaneous:
rust/src/lock.rs
: Added license information to the file.Types of changes
Checklist
PR Type
Enhancement
Description
Enhanced browser version handling in Selenium Grid with the following improvements:
Implemented semantic version comparison for better browser version matching
Improved slot selection and matching logic:
Added comprehensive test coverage:
Code quality improvements:
Changes walkthrough 📝
DefaultSlotMatcher.java
Improved browser version matching logic
java/src/org/openqa/selenium/grid/data/DefaultSlotMatcher.java
semVerComparator
for moreflexible matching
NodeStatus.java
Added semantic version comparison functionality
java/src/org/openqa/selenium/grid/data/NodeStatus.java
getBrowserVersion
method to retrieve minimum browser versionsemVerComparator
for semantic version comparisonisNumber
for version parsingDefaultSlotSelector.java
Enhanced slot selection with version-based sorting
java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java
NodeStatusTest.java
Added tests for semantic version comparison
java/test/org/openqa/selenium/grid/data/NodeStatusTest.java
DefaultSlotSelectorTest.java
Added tests for version-based node ordering
java/test/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelectorTest.java
lock.rs
Added missing license header
rust/src/lock.rs