Skip to content

Conversation

@SylvainJuge
Copy link
Contributor

First part for #14674

Introduces idiomatic Telemetry / TelemetryBuilder for JMX metrics.

  • provides a new JmxTelemetry / JmxTelemetryBuilder that delegates to the existing implementation.
  • keeps the implementation almost as-is to prevent breaking jmx-scraper in contrib until this change is included in a release.
  • yaml parsing errors are new throwing runtime exceptions at the parser level, in the agent the error is logged as a warning to remain consistent with current behavior (warn but not thrown exception).

@SylvainJuge SylvainJuge requested a review from a team as a code owner November 4, 2025 15:18
@SylvainJuge SylvainJuge self-assigned this Nov 4, 2025
@SylvainJuge SylvainJuge changed the title jmx idiomatic library API jmx idiomatic library API - part 1 Nov 4, 2025
private static String resourceFor(String platform) {
return "/jmx/rules/" + platform + ".yaml";
}

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] this part is now embedded directly into the library, so we don't expose internal details anymore, this also enables removing similar code in contrib jmx-scraper (or anything that does rely on this library).

Copy link
Member

Choose a reason for hiding this comment

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

do we have a plan how to use declarative configuration instead of a separate yaml file in the future?

I bring it up because a library redesign would be a good opportunity to plan ahead for that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point, we don't have any concrete plan for declarative config, but this is something that we need to think about in the future, I have already opened #14916 to not forget about it.

Comment on lines +39 to +41
} catch (IllegalArgumentException e) {
// for now only log JMX errors as they do not prevent agent startup
logger.log(Level.SEVERE, "Error while loading JMX configuration", e);
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] for now an invalid configuration does not prevent the agent from starting, it just logs an error which was also the current behavior.

Copy link
Member

Choose a reason for hiding this comment

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

why is that changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The overall behavior does not change here, the agent currently starts with warnings in the logs when there are parsing errors, now an exception is thrown and it only logs the first error thanks to this catch statement.

* @param conf the metric configuration
* @param is the InputStream with the YAML rules
* @param id identifier of the YAML ruleset, such as a filename
* @throws IllegalArgumentException when unable to parse YAML
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] throwning an exception here allows to let the caller of the library how to handle parsing errors, for now the agent just logs the first that happen. Doing so also allows to validate existing yaml configuration in the "legacy" state that are not included in the library (but in the agent), all of that without relying on classes that will be moved to internal packages later.

rule.buildMetricDef();
}
// loading rules from direct file access
JmxTelemetry.builder(OpenTelemetry.noop()).addCustomRules(filePath);
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] we have to load those files through direct file access because we can't resolve them directly because they are part of the unamed module and Class#getResource(...) does not work in this case, this should be fine because this test class will be removed later and everything will be tested through classpath when moved to library.

Copy link
Member

Choose a reason for hiding this comment

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

it might be easier just to wait for the library release (that was my experience working with different java repos)

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 don't think the library release will change the resource visibility as both this test and the library are part of the same repository.

The goal of this test is just to ensure that there are no parsing errors, there aren't any dedicated assertions on the metrics definitions themselves.

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