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

jmx metrics attribute lowercase modifier #13385

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

SylvainJuge
Copy link
Contributor

Fixes #13361

Adds the ability to use lowercase(...) function to the metric attributes.

Other modifiers might be added in the future but for now only the lower-case variant is needed for #13361.

@SylvainJuge SylvainJuge requested a review from a team as a code owner February 24, 2025 14:55
@@ -136,7 +136,18 @@ private List<MetricAttribute> addMetricAttributes(Map<String, Object> metricAttr
return list;
}

private static MetricAttribute buildMetricAttribute(String key, String target) {
// package protected for testing
static MetricAttribute buildMetricAttribute(String key, String target) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] making this package-private makes unit-testing easier in MetricStructureTest (see below).

@@ -30,7 +31,8 @@ public String getAttributeName() {
return name;
}

String acquireAttributeValue(MBeanServerConnection connection, ObjectName objectName) {
@Nullable
public String acquireAttributeValue(MBeanServerConnection connection, ObjectName objectName) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] extractor return value can be null

@Test
void attributeValueLowercase() {

JmxConfig config = parseConf(CONF10);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] here we only test the parsing as we can rely on unit tests in MetricStructureTest to validate the expected value modifications.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, however it would be nice to add also some negative test to verify parsing errors related to use of lowercase(...)

// an optional modifier may wrap the target
// - lowercase(param(STRING))
boolean lowercase = false;
if (target.startsWith("lowercase(")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitating if it should be ''lowercase' or 'lowerCase'.
Currently it looks like we have no consistent convention in the yaml file. We already have camelcase and lowercase naming used, for example metricAttribute and beanattr.
I understand that you followed existing attribute extractor yaml naming pattern, but this is inconsistent with the rest of yaml names and maybe this is one more item to discuss on the SIG meeting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't have any strong opinion on this, there might be a few inconsistencies but keeping it in line with param, beanattr and const should be a safe choice for now.

If we aim to fix those inconsistencies, I would suggest to do it in a separate PR and it would be relevant to also check what is the convention in the declarative configuration because at some point the JMX yaml configuration will be nested in it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great you added this test !

@Test
void attributeValueLowercase() {

JmxConfig config = parseConf(CONF10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, however it would be nice to add also some negative test to verify parsing errors related to use of lowercase(...)

// an optional modifier may wrap the target
// - lowercase(param(STRING))
boolean lowercase = false;
String lowerCaseExpr = tryParseFunction("lowercase", targetExpr, target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess for now it doesn't matter, but if you plan to add more transforms then it would be beneficial to restructure the parsing logic so that lowercase(lowercase(const(Hello))) would be valid.

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.

jmx metrics with yaml: need ability to post-process some attribute values
3 participants