You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 change implements the getAttributes() method on the JMX MBean object(s), returning an AttributeList with the current attributes of the MBean.
It also updates the return type of the MBean attributes which are Number based to their appropriate Number data type instead of String objects.
Motivation and Context
Motivation for this change is driven by trying to export the custom JMX metrics out of the Grid and into Prometheus, with the end goal being that those metrics once in Prometheus in an OpenShift environment can drive autoscaling of Node pods for a Grid instance. The JMX exporter in question is the Prometheus JMX Exporter, which leverages the getAttributes() method of any DynamicMBeans in order to determine if any attributes should be exported.
If implemented, this addition will allow those running Selenium Grid to more easily export the custom Grid metrics into a Prometheus environment.
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)
Possible Bug: The use of NumberFormat.getInstance().parse(res.toString()) in getAttribute method might not be the most efficient or error-free way to convert numbers. Consider using more direct methods like Integer.valueOf() or Double.valueOf() depending on the expected type.
Exception Handling: The broad catch of Exception in the getAttributes method might mask other unexpected runtime issues. It's generally better to catch more specific exceptions if possible.
Why: Catching specific exceptions instead of a generic Exception is a best practice as it prevents masking other potential issues and helps in handling exceptions more accurately.
8
Performance
Return Number directly instead of parsing its string representation back to a number
Use Number directly instead of parsing the string representation back to a number in the getAttribute method.
Why: Returning the Number object directly is more efficient and cleaner than parsing its string representation back to a number, thus improving performance.
7
Maintainability
Extract repeated parsing and assertion logic into a helper method
Extract the repeated parsing and assertion logic into a helper method to reduce code duplication and improve readability.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 change implements the
getAttributes()
method on the JMX MBean object(s), returning anAttributeList
with the current attributes of the MBean.It also updates the return type of the MBean attributes which are Number based to their appropriate Number data type instead of String objects.
Motivation and Context
Motivation for this change is driven by trying to export the custom JMX metrics out of the Grid and into Prometheus, with the end goal being that those metrics once in Prometheus in an OpenShift environment can drive autoscaling of Node pods for a Grid instance. The JMX exporter in question is the Prometheus JMX Exporter, which leverages the
getAttributes()
method of any DynamicMBeans in order to determine if any attributes should be exported.If implemented, this addition will allow those running Selenium Grid to more easily export the custom Grid metrics into a Prometheus environment.
Types of changes
Checklist
PR Type
Enhancement, Tests
Description
getAttributes()
method in theMBean
class to return anAttributeList
with current attributes.getAttribute
method to correctly handle and parseNumber
types.getAttribute
method to includeParseException
.getAttributes
method.Number
types instead ofString
.getAttributeList
in tests to streamline attribute retrieval.Changes walkthrough 📝
MBean.java
Implement `getAttributes` method and update `getAttribute` handling
java/src/org/openqa/selenium/grid/jmx/MBean.java
getAttributes()
method to return anAttributeList
withcurrent MBean attributes.
getAttribute
method to handleNumber
types and parse themcorrectly.
ParseException
.JmxTest.java
Add unit tests for `getAttributes` and update attribute type checks
java/test/org/openqa/selenium/grid/router/JmxTest.java
getAttributes
method.Number
types instead of
String
.getAttributeList
to streamline attributeretrieval in tests.