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 scraper with sdk autoconfig #1651

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

Conversation

SylvainJuge
Copy link
Contributor

@SylvainJuge SylvainJuge commented Jan 17, 2025

Refactor jmx scraper configuration to use autoconfiguration.

This provides the following benefits:

  • allow using environment variables in addition to java system properties
  • override the default configuration using SDK API : config provider and config customizer

Now only the the otel.metric.export.interval SDK configuration should be used to define the metric sampling and export interval, compatibility is provided with existing otel.jmx.interval.milliseconds when needed.

When otel.metric.export.interval is not set, the default of 1 minute is applied which remains consistent with the SDK implementation and specification.

The ability to provide configuration through standard input, external properties and the JVM system properties have been preserved.

To be discussed

  • Should we align the default exporter to be otlp to align with the SDK default value, or should we keep the logging as we have currently when it's not set. Setting logging here by default mostly benefits onboarding as users can see what is being captured, but requires to explicitly include otlp which is set by default for the SDK autoconfiguration.

@@ -24,7 +24,6 @@ public class JmxScraperContainer extends GenericContainer<JmxScraperContainer> {
private final String endpoint;
private final Set<String> targetSystems;
private String serviceUrl;
private int intervalMillis;
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 is never changed for tests, so we can use the minimal hard-coded value of 1s.

Comment on lines +102 to +112
static void propagateToSystemProperties(Properties properties) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String key = entry.getKey().toString();
String value = entry.getValue().toString();
if (key.startsWith("javax.net.ssl.keyStore") || key.startsWith("javax.net.ssl.trustStore")) {
if (System.getProperty(key) == null) {
System.setProperty(key, value);
}
}
}
}
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] propagation of system properties is only used to set the java keystore/truststore options from the program arguments/standard input to the global JVM settings, so it was simpler to move it here. In practice this will likely be tested when we add tests with custom keystore/truststore by setting those configuration options from the standard input or the properties file.


package io.opentelemetry.contrib.jmxscraper.config;

public class ConfigurationException extends Exception {
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] there is already a similarly named runtime exception in the SDK autoconfiguration, so reusing it makes more sense and avoid ambiguity.

Comment on lines +123 to +127
if (exportInterval == null || exportInterval.isNegative() || exportInterval.isZero()) {
// if not explicitly set, use default value of 1 minute as defined in specification
scraperConfig.samplingInterval = Duration.ofMinutes(1);
} else {
scraperConfig.samplingInterval = exportInterval;
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 do this because we don't have access to the default value that will be used by the SDK when an explicit value is not present.


@Override
public Map<String, String> apply(ConfigProperties config) {
Map<String, String> result = new HashMap<>();
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] the returned map contains the configuration items that will be explicitly set/overriden so that they can be later read by the SDK initialization. In addition to that we use this to build an instance of JmxScraperConfig from the provided ConfigProperties that will later be used to configure the jmx scraper.

@breedx-splk
Copy link
Contributor

Regarding the question of default logger -- I think we should continue to be consistent with the sdk and default to exporting otlp to localhost. 👍🏻 If a user needs to see details/logging they should be able to opt-into that I think.

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.

3 participants