-
Notifications
You must be signed in to change notification settings - Fork 157
jmx reuse instrumentation metrics #1782
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
Changes from all commits
f55ba57
aaa7b9d
54b8754
c5fc196
ceb7d7e
7c83b3f
8f9c92a
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 |
---|---|---|
|
@@ -7,12 +7,13 @@ | |
|
||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; | ||
import java.io.InputStream; | ||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
import java.util.logging.Logger; | ||
import javax.annotation.Nullable; | ||
|
@@ -37,37 +38,23 @@ public class JmxScraperConfig { | |
static final String JMX_CONFIG_LEGACY = "otel.jmx.custom.scraping.config"; | ||
|
||
static final String JMX_TARGET_SYSTEM = "otel.jmx.target.system"; | ||
static final String JMX_TARGET_SOURCE = "otel.jmx.target.source"; | ||
|
||
static final String JMX_USERNAME = "otel.jmx.username"; | ||
static final String JMX_PASSWORD = "otel.jmx.password"; | ||
|
||
// TODO: document those when they will be supported | ||
static final String JMX_REGISTRY_SSL = "otel.jmx.remote.registry.ssl"; | ||
static final String JMX_REMOTE_PROFILE = "otel.jmx.remote.profile"; | ||
static final String JMX_REALM = "otel.jmx.realm"; | ||
|
||
private static final List<String> AVAILABLE_TARGET_SYSTEMS = | ||
Collections.unmodifiableList( | ||
Arrays.asList( | ||
"activemq", | ||
"cassandra", | ||
"hbase", | ||
"hadoop", | ||
"jetty", | ||
"jvm", | ||
"kafka", | ||
"kafka-consumer", | ||
"kafka-producer", | ||
"solr", | ||
"tomcat", | ||
"wildfly")); | ||
|
||
private String serviceUrl = ""; | ||
|
||
private List<String> jmxConfig = Collections.emptyList(); | ||
|
||
private Set<String> targetSystems = Collections.emptySet(); | ||
|
||
private TargetSystemSource targetSystemSource = TargetSystemSource.AUTO; | ||
|
||
private Duration samplingInterval = Duration.ofMinutes(1); | ||
|
||
@Nullable private String username; | ||
|
@@ -79,6 +66,20 @@ public class JmxScraperConfig { | |
@Nullable private String remoteProfile; | ||
private boolean registrySsl; | ||
|
||
public enum TargetSystemSource { | ||
AUTO, | ||
INSTRUMENTATION, | ||
LEGACY; | ||
|
||
static TargetSystemSource fromString(String source) { | ||
try { | ||
return TargetSystemSource.valueOf(source.toUpperCase(Locale.ROOT)); | ||
} catch (IllegalArgumentException e) { | ||
throw new IllegalArgumentException("Invalid target system source: " + source, e); | ||
} | ||
} | ||
} | ||
|
||
private JmxScraperConfig() {} | ||
|
||
public String getServiceUrl() { | ||
|
@@ -93,6 +94,57 @@ public Set<String> getTargetSystems() { | |
return targetSystems; | ||
} | ||
|
||
/** | ||
* Resolves the target system yaml from configuration | ||
* | ||
* @param system target system | ||
* @return input stream on target system yaml definitions | ||
* @throws ConfigurationException when no yaml for system is available | ||
*/ | ||
public InputStream getTargetSystemYaml(String system) { | ||
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. [for reviewer] technically speaking this could be left outside of configuration however we now have to use the presence of yaml files to check if system is supported, which is something that the configuration should check for (this is already tested in tests like |
||
InputStream yaml; | ||
switch (targetSystemSource) { | ||
case LEGACY: | ||
yaml = getTargetSystemYaml(system, TargetSystemSource.LEGACY); | ||
break; | ||
case INSTRUMENTATION: | ||
yaml = getTargetSystemYaml(system, TargetSystemSource.INSTRUMENTATION); | ||
break; | ||
case AUTO: | ||
yaml = getTargetSystemYaml(system, TargetSystemSource.INSTRUMENTATION); | ||
if (yaml == null) { | ||
yaml = getTargetSystemYaml(system, TargetSystemSource.LEGACY); | ||
} | ||
break; | ||
default: | ||
throw new IllegalStateException("unsupported target system source: " + targetSystemSource); | ||
} | ||
|
||
if (yaml == null) { | ||
throw new ConfigurationException( | ||
"unsupported target system: '" + system + "', source: " + targetSystemSource); | ||
} | ||
return yaml; | ||
} | ||
|
||
@Nullable | ||
private static InputStream getTargetSystemYaml(String system, TargetSystemSource source) { | ||
String path; | ||
switch (source) { | ||
case LEGACY: | ||
path = String.format("%s.yaml", system); | ||
break; | ||
case INSTRUMENTATION: | ||
path = String.format("jmx/rules/%s.yaml", system); | ||
break; | ||
case AUTO: | ||
default: | ||
throw new IllegalArgumentException("invalid source" + source); | ||
} | ||
|
||
return JmxScraperConfig.class.getClassLoader().getResourceAsStream(path); | ||
} | ||
|
||
public Duration getSamplingInterval() { | ||
return samplingInterval; | ||
} | ||
|
@@ -164,12 +216,6 @@ public static JmxScraperConfig fromConfig(ConfigProperties config) { | |
throw new ConfigurationException( | ||
"at least one of '" + JMX_TARGET_SYSTEM + "' or '" + JMX_CONFIG + "' must be set"); | ||
} | ||
targetSystem.forEach( | ||
s -> { | ||
if (!AVAILABLE_TARGET_SYSTEMS.contains(s)) { | ||
throw new ConfigurationException("unsupported target system: '" + s + "'"); | ||
} | ||
}); | ||
|
||
scraperConfig.jmxConfig = Collections.unmodifiableList(jmxConfig); | ||
scraperConfig.targetSystems = Collections.unmodifiableSet(new HashSet<>(targetSystem)); | ||
|
@@ -180,6 +226,13 @@ public static JmxScraperConfig fromConfig(ConfigProperties config) { | |
scraperConfig.realm = config.getString("otel.jmx.realm"); | ||
scraperConfig.registrySsl = config.getBoolean("otel.jmx.remote.registry.ssl", false); | ||
|
||
// checks target system is supported by resolving the yaml resource, throws exception on | ||
// missing/error | ||
scraperConfig.targetSystems.forEach(scraperConfig::getTargetSystemYaml); | ||
|
||
String source = config.getString(JMX_TARGET_SOURCE, TargetSystemSource.AUTO.name()); | ||
scraperConfig.targetSystemSource = TargetSystemSource.fromString(source); | ||
|
||
return scraperConfig; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[for reviewer] this table will have to be updated on every instrumentation dependency release if there are new systems or definitions in instrumentation.