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

max_returned_metrics: parse string value with fallback #537

Closed
wants to merge 2 commits into from

Conversation

tbavelier
Copy link
Member

What does this PR do ?

This PR allows the use of integer string value for the max_returned_metrics parameter. If the string cannot be parsed, falls back to default limit instead.

Motivation

Recent customer case where their JMX configuration would not work once they added max_returned_metrics. As they were using k8s annotations, they tried to use a string in the JSON instead of the integer, causing the instance not to be loaded with the error message Unable to create instance. Please check your yaml file :

{
  "instances": [
    {
      "host": "%%host%%",
      "port": 9999,
      "max_returned_metrics": "2000"
    }
  ]
}

instead of

{
  "instances": [
    {
      "host": "%%host%%",
      "port": 9999,
      "max_returned_metrics": 2000
    }
  ]
}

With this PR, both syntaxes would work.

@tbavelier tbavelier requested a review from a team as a code owner August 23, 2024 09:07
@@ -97,6 +97,31 @@ public void testBaselineDefaultHostname() throws Exception {
}
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you ❤️

try {
this.maxReturnedMetrics = Integer.parseInt((String) maxReturnedMetrics);
} catch (NumberFormatException e) {
log.warn("Cannot convert max_returned_metrics to integer in your instance configuration. Defaulting to '{}'.", MAX_RETURNED_METRICS);
Copy link
Contributor

Choose a reason for hiding this comment

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

This line might break the linter (waiting for it to run) so you may want to do something like this (I probably have the spaces all wrong):

Suggested change
log.warn("Cannot convert max_returned_metrics to integer in your instance configuration. Defaulting to '{}'.", MAX_RETURNED_METRICS);
log.warn(
"Cannot convert max_returned_metrics to integer in your instance configuration. Defaulting to '{}'.",
MAX_RETURNED_METRICS);

@carlosroman carlosroman self-requested a review August 23, 2024 09:22
@tbavelier
Copy link
Member Author

Superseded by #539

@tbavelier tbavelier closed this Aug 23, 2024
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.

2 participants