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

Issue 7212 - Allow multiple YAML configuration files for JMX rules #7284

Merged

Conversation

PeterF778
Copy link
Contributor

No description provided.

@PeterF778 PeterF778 requested a review from a team as a code owner November 23, 2022 01:13
try {

JmxConfig config = loadConfig(is);
if (config != null) {
logger.log(INFO, "Found {0} metric rules", config.getRules().size());
logger.log(INFO, id + ": found {0} metric rules", config.getRules().size());
Copy link
Member

Choose a reason for hiding this comment

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

Can you use placeholders?

Suggested change
logger.log(INFO, id + ": found {0} metric rules", config.getRules().size());
logger.log(INFO, "{0}: found {1} metric rules", new Object[] {id, config.getRules().size()});

config.addMetricDefsTo(conf);
}
} catch (Exception exception) {
logger.log(WARNING, "Failed to parse YAML rules: " + rootCause(exception));
logger.log(WARNING, "Failed to parse YAML rules from " + id + ": " + rootCause(exception));
Copy link
Member

Choose a reason for hiding this comment

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

Same here, please use placeholders instead of glueing log messages manually

Comment on lines 83 to 84
String files = configProperties.getString("otel.jmx.config", "");
String[] configFiles = files.isEmpty() ? new String[0] : files.split(",");
Copy link
Member

Choose a reason for hiding this comment

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

You can use ConfigProperties#getList() instead

} catch (Exception e) {
JmxMetricInsight.getLogger().warning(e.getMessage());
JmxMetricInsight.getLogger().warning(e.toString());
Copy link
Member

Choose a reason for hiding this comment

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

This pretty much only logs the message; shouldn't we log the whole stacktrace here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not in this case. An exception at this location indicates difficulties with reading the file (user error), and the message should be sufficient for troubleshooting.

Copy link
Member

Choose a reason for hiding this comment

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

is there a specific exception that indicates parsing error (e.g. YamlException)? or is the code inside the try block narrow enough that there shouldn't be any other type of exception here?

Copy link
Contributor Author

@PeterF778 PeterF778 Nov 23, 2022

Choose a reason for hiding this comment

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

Parsing errors are handled by RuleParser, and an effort has been made to provide as useful contextual info there as possible. But again, without stack traces, as they would not get any value for the users, IMHO.
Only file access related exceptions are expected here.

RuleParser parserInstance = RuleParser.get();
try (InputStream inputStream = Files.newInputStream(new File(jmxDir.trim()).toPath())) {
parserInstance.addMetricDefsTo(conf, inputStream);
try (InputStream inputStream = Files.newInputStream(new File(configFile).toPath())) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
try (InputStream inputStream = Files.newInputStream(new File(configFile).toPath())) {
try (InputStream inputStream = Files.newInputStream(Paths.get(configFile))) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review, @mateuszrzeszutek!

…emetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
@mateuszrzeszutek mateuszrzeszutek merged commit c4ceaaa into open-telemetry:main Nov 24, 2022
@PeterF778 PeterF778 deleted the 7212_multiple_config_files branch November 28, 2022 17:43
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.

None yet

4 participants