-
Notifications
You must be signed in to change notification settings - Fork 1k
jmx-metrics: allow any resource path for classpath resources rules #15413
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
e852dad
d688fc4
2514661
04bf7db
eb0555c
549ff19
0c6e261
5ff7e24
c9750f2
013f4eb
9cabd88
0abd947
4404db3
80d76dc
5f72cf8
8bd15b5
252b5d1
d53a352
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,47 +49,70 @@ public JmxTelemetryBuilder beanDiscoveryDelay(Duration delay) { | |
| } | ||
|
|
||
| /** | ||
| * Adds built-in JMX rules from classpath resource | ||
| * Adds built-in JMX rules from classpath resource. | ||
| * | ||
| * @param target name of target in /jmx/rules/{target}.yaml classpath resource | ||
| * @return builder instance | ||
| * @throws IllegalArgumentException when classpath resource does not exist or can't be parsed | ||
| */ | ||
| // TODO: deprecate this method after 2.23.0 release in favor of addRules | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why don't you deprecate it immediately?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we deprecate it right now, it means the next update of instrumentation dependency in contrib will require to immediately modify the code of Doing that after 2.23.0 gives a bit more time with a timeline like this:
|
||
| @CanIgnoreReturnValue | ||
| public JmxTelemetryBuilder addClassPathRules(String target) { | ||
| String yamlResource = String.format("jmx/rules/%s.yaml", target); | ||
| try (InputStream inputStream = | ||
| JmxTelemetryBuilder.class.getClassLoader().getResourceAsStream(yamlResource)) { | ||
| if (inputStream == null) { | ||
| throw new IllegalArgumentException("JMX rules not found in classpath: " + yamlResource); | ||
| } | ||
| logger.log(FINE, "Adding JMX config from classpath for {0}", yamlResource); | ||
| RuleParser parserInstance = RuleParser.get(); | ||
| parserInstance.addMetricDefsTo(metricConfiguration, inputStream, target); | ||
| } catch (Exception e) { | ||
| String resourcePath = String.format("jmx/rules/%s.yaml", target); | ||
| ClassLoader classLoader = JmxTelemetryBuilder.class.getClassLoader(); | ||
| try (InputStream inputStream = classLoader.getResourceAsStream(resourcePath)) { | ||
| return addRules(inputStream, resourcePath); | ||
| } catch (IOException e) { | ||
| throw new IllegalArgumentException( | ||
| "Unable to load JMX rules from classpath: " + yamlResource, e); | ||
| "Unable to load JMX rules from resource " + resourcePath, e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Adds JMX rules from input stream | ||
| * | ||
| * @param input input to read rules from | ||
| * @param description input description, used for user-friendly logs and parsing error messages | ||
| * @throws IllegalArgumentException when input is {@literal null} | ||
| */ | ||
| @CanIgnoreReturnValue | ||
| public JmxTelemetryBuilder addRules(InputStream input, String description) { | ||
SylvainJuge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (input == null) { | ||
| throw new IllegalArgumentException("JMX rules not found for " + description); | ||
| } | ||
| logger.log(FINE, "Adding JMX config from {0}", description); | ||
| RuleParser parserInstance = RuleParser.get(); | ||
| parserInstance.addMetricDefsTo(metricConfiguration, input, description); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Adds custom JMX rules from file system path | ||
| * Adds JMX rules from file system path | ||
| * | ||
| * @param path path to yaml file | ||
| * @return builder instance | ||
| * @throws IllegalArgumentException when classpath resource does not exist or can't be parsed | ||
| * @throws IllegalArgumentException in case of parsing errors or when file does not exist | ||
| */ | ||
| @CanIgnoreReturnValue | ||
| public JmxTelemetryBuilder addCustomRules(Path path) { | ||
| logger.log(FINE, "Adding JMX config from file: {0}", path); | ||
| RuleParser parserInstance = RuleParser.get(); | ||
| public JmxTelemetryBuilder addRules(Path path) { | ||
| try (InputStream inputStream = Files.newInputStream(path)) { | ||
| parserInstance.addMetricDefsTo(metricConfiguration, inputStream, path.toString()); | ||
| return addRules(inputStream, "file " + path); | ||
| } catch (IOException e) { | ||
| throw new IllegalArgumentException("Unable to load JMX rules in path: " + path, e); | ||
| throw new IllegalArgumentException("Unable to load JMX rules from: " + path, e); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Adds custom JMX rules from file system path | ||
| * | ||
| * @param path path to yaml file | ||
| * @return builder instance | ||
| * @throws IllegalArgumentException when classpath resource does not exist or can't be parsed | ||
| */ | ||
| // TODO: deprecate this method after 2.23.0 release in favor of addRules | ||
| @CanIgnoreReturnValue | ||
| public JmxTelemetryBuilder addCustomRules(Path path) { | ||
| return addRules(path); | ||
| } | ||
|
|
||
| public JmxTelemetry build() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.