-
Couldn't load subscription status.
- Fork 168
[WIP] JMX scraper #1445
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
Merged
Merged
[WIP] JMX scraper #1445
Changes from 26 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
0f60e22
module bootstrap
SylvainJuge 720633c
add dependencies + test setup
SylvainJuge 07027a2
spotless
SylvainJuge 5a82aac
resolve dependencies on maven local repo
SylvainJuge d623abe
@robsunday PR with upstream updates
SylvainJuge f7b5a31
@SylvainJuge PR
SylvainJuge 48b095d
spotless
SylvainJuge 8dfe174
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-c…
SylvainJuge e4f4769
prepare for tomcat e2e test
SylvainJuge 71e6258
start wiring things together
SylvainJuge 586f780
remove stack trace when sasl not supported
SylvainJuge 966aee6
enhance comments & test cmd log msg
SylvainJuge 350f8a9
More tests
robsunday 91976c0
refactor to use test containers
SylvainJuge d28fd42
make it mergeable without snapshot
SylvainJuge 9072de0
tidy a few things
SylvainJuge c0ac43f
remove JmxClient
SylvainJuge 39b6341
Merge pull request #3 from robsunday/jmx-scraper-impl
SylvainJuge 14c0c2d
post-review changes
SylvainJuge 1a6533e
remove warnings
SylvainJuge aecf5ff
Merge pull request #4 from SylvainJuge/tomcat-it
SylvainJuge ea46e8d
reformat again
SylvainJuge f8461b2
update readme
SylvainJuge 71a5749
disable publication until ready
SylvainJuge 317fcde
remove test dependency from runtime
SylvainJuge c89e527
Merge pull request #5 from SylvainJuge/update-readme
SylvainJuge 378af7a
add TODOs to ensure we don't forget about it
SylvainJuge 178fae3
Apply suggestions from code review
SylvainJuge c656bf7
remove maven local repo
SylvainJuge 2d24b22
post-review: arguments parsing
SylvainJuge bb74e6e
post-review: move factory creation
SylvainJuge 1f0fc84
post-review: properties loading
SylvainJuge 140ac17
restore missing serialization ids
SylvainJuge 4c61c22
rework JmxScraper creation
SylvainJuge 8917452
cleanup
SylvainJuge 7a7fed7
remove useless config check
SylvainJuge ffc05c1
post-review: JmxRemoteClient > JmxConnectorBuilder
SylvainJuge 30094f5
post-review de-groovify + static factory
SylvainJuge 2c16a92
fix tests
SylvainJuge 8ad40e0
attempt to fix tests on some jdks
SylvainJuge 7d0be38
allow empty user config when using system properties
SylvainJuge c15f40d
Code review followup changes
robsunday 86c3e54
Merge pull request #6 from robsunday/jmx-scraper-impl
SylvainJuge 2c95782
Code review followup changes - added default value for OTLP endpoint
robsunday 3a1021f
Merge pull request #7 from robsunday/jmx-scraper-impl
SylvainJuge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # JMX Metric Scraper | ||
|
|
||
| This utility provides a way to query JMX metrics and export them to an OTLP endpoint. | ||
| The JMX MBeans and their metrics mapping is defined in YAML and is reusing implementation from | ||
SylvainJuge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [jmx-metrics instrumentation](https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/jmx-metrics). | ||
|
|
||
| This is currently a work-in-progress component not ready to be used in production. | ||
| The end goal is to provide an alternative to the [JMX Gatherer](../jmx-metrics/README.md) utility. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| plugins { | ||
| application | ||
| id("com.github.johnrengelman.shadow") | ||
|
|
||
| id("otel.java-conventions") | ||
|
|
||
| // publishing disabled until component is ready to be used | ||
| // id("otel.publish-conventions") | ||
SylvainJuge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| description = "JMX metrics scraper" | ||
| otelJava.moduleName.set("io.opentelemetry.contrib.jmxscraper") | ||
|
|
||
| application.mainClass.set("io.opentelemetry.contrib.jmxscraper.JmxScraper") | ||
|
|
||
| dependencies { | ||
| implementation("io.opentelemetry:opentelemetry-api") | ||
| implementation("io.opentelemetry:opentelemetry-sdk") | ||
| implementation("io.opentelemetry:opentelemetry-sdk-metrics") | ||
| implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure") | ||
|
|
||
| implementation("io.opentelemetry.instrumentation:opentelemetry-jmx-metrics") | ||
|
|
||
| testImplementation("org.junit-pioneer:junit-pioneer") | ||
| testImplementation("io.opentelemetry:opentelemetry-sdk-testing") | ||
| } | ||
|
|
||
| testing { | ||
| suites { | ||
| val integrationTest by registering(JvmTestSuite::class) { | ||
| dependencies { | ||
| implementation("org.testcontainers:junit-jupiter") | ||
| implementation("org.slf4j:slf4j-simple") | ||
| implementation("com.linecorp.armeria:armeria-junit5") | ||
| implementation("com.linecorp.armeria:armeria-grpc") | ||
| implementation("io.opentelemetry.proto:opentelemetry-proto:0.20.0-alpha") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks { | ||
| shadowJar { | ||
| mergeServiceFiles() | ||
|
|
||
| manifest { | ||
| attributes["Implementation-Version"] = project.version | ||
| } | ||
| // This should always be standalone, so remove "-all" to prevent unnecessary artifact. | ||
| archiveClassifier.set("") | ||
| } | ||
|
|
||
| jar { | ||
| archiveClassifier.set("noshadow") | ||
| } | ||
|
|
||
| withType<Test>().configureEach { | ||
| dependsOn(shadowJar) | ||
| dependsOn(named("appJar")) | ||
| systemProperty("shadow.jar.path", shadowJar.get().archiveFile.get().asFile.absolutePath) | ||
| systemProperty("app.jar.path", named<Jar>("appJar").get().archiveFile.get().asFile.absolutePath) | ||
| systemProperty("gradle.project.version", "${project.version}") | ||
| } | ||
|
|
||
| // Because we reconfigure publishing to only include the shadow jar, the Gradle metadata is not correct. | ||
| // Since we are fully bundled and have no dependencies, Gradle metadata wouldn't provide any advantage over | ||
| // the POM anyways so in practice we shouldn't be losing anything. | ||
| withType<GenerateModuleMetadata>().configureEach { | ||
| enabled = false | ||
| } | ||
| } | ||
|
|
||
| tasks.register<Jar>("appJar") { | ||
| from(sourceSets.get("integrationTest").output) | ||
| archiveClassifier.set("app") | ||
| manifest { | ||
| attributes["Main-Class"] = "io.opentelemetry.contrib.jmxscraper.TestApp" | ||
| } | ||
| } | ||
|
|
||
| // Don't publish non-shadowed jar (shadowJar is in shadowRuntimeElements) | ||
| with(components["java"] as AdhocComponentWithVariants) { | ||
| configurations.forEach { | ||
| withVariantsFromConfiguration(configurations["apiElements"]) { | ||
| skip() | ||
| } | ||
| withVariantsFromConfiguration(configurations["runtimeElements"]) { | ||
| skip() | ||
| } | ||
| } | ||
| } | ||
107 changes: 107 additions & 0 deletions
107
...per/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxScraperContainer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.contrib.jmxscraper; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
| import java.time.Duration; | ||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Set; | ||
| import org.testcontainers.containers.GenericContainer; | ||
| import org.testcontainers.containers.wait.strategy.Wait; | ||
| import org.testcontainers.utility.MountableFile; | ||
|
|
||
| /** Test container that allows to execute {@link JmxScraper} in an isolated container */ | ||
| public class JmxScraperContainer extends GenericContainer<JmxScraperContainer> { | ||
|
|
||
| private final String endpoint; | ||
| private final Set<String> targetSystems; | ||
| private String serviceUrl; | ||
| private int intervalMillis; | ||
| private final Set<String> customYamlFiles; | ||
|
|
||
| public JmxScraperContainer(String otlpEndpoint) { | ||
| super("openjdk:8u272-jre-slim"); | ||
|
|
||
| String scraperJarPath = System.getProperty("shadow.jar.path"); | ||
| assertThat(scraperJarPath).isNotNull(); | ||
|
|
||
| this.withCopyFileToContainer(MountableFile.forHostPath(scraperJarPath), "/scraper.jar") | ||
| .waitingFor( | ||
| Wait.forLogMessage(".*JMX scraping started.*", 1) | ||
| .withStartupTimeout(Duration.ofSeconds(10))); | ||
|
|
||
| this.endpoint = otlpEndpoint; | ||
| this.targetSystems = new HashSet<>(); | ||
| this.customYamlFiles = new HashSet<>(); | ||
| this.intervalMillis = 1000; | ||
| } | ||
|
|
||
| @CanIgnoreReturnValue | ||
| public JmxScraperContainer withTargetSystem(String targetSystem) { | ||
| targetSystems.add(targetSystem); | ||
| return this; | ||
| } | ||
|
|
||
| @CanIgnoreReturnValue | ||
| public JmxScraperContainer withIntervalMillis(int intervalMillis) { | ||
| this.intervalMillis = intervalMillis; | ||
| return this; | ||
| } | ||
|
|
||
| @CanIgnoreReturnValue | ||
| public JmxScraperContainer withService(String host, int port) { | ||
| // TODO: adding a way to provide 'host:port' syntax would make this easier for end users | ||
| this.serviceUrl = | ||
| String.format( | ||
| Locale.getDefault(), "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi", host, port); | ||
| return this; | ||
| } | ||
|
|
||
| @CanIgnoreReturnValue | ||
| public JmxScraperContainer withCustomYaml(String yamlPath) { | ||
| this.customYamlFiles.add(yamlPath); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public void start() { | ||
| // for now only configure through JVM args | ||
| List<String> arguments = new ArrayList<>(); | ||
| arguments.add("java"); | ||
| arguments.add("-Dotel.exporter.otlp.endpoint=" + endpoint); | ||
|
|
||
| if (!targetSystems.isEmpty()) { | ||
| arguments.add("-Dotel.jmx.target.system=" + String.join(",", targetSystems)); | ||
| } | ||
|
|
||
| if (serviceUrl == null) { | ||
| throw new IllegalStateException("Missing service URL"); | ||
| } | ||
| arguments.add("-Dotel.jmx.service.url=" + serviceUrl); | ||
| arguments.add("-Dotel.jmx.interval.milliseconds=" + intervalMillis); | ||
|
|
||
| if (!customYamlFiles.isEmpty()) { | ||
| for (String yaml : customYamlFiles) { | ||
| this.withCopyFileToContainer(MountableFile.forClasspathResource(yaml), yaml); | ||
| } | ||
| arguments.add("-Dotel.jmx.config=" + String.join(",", customYamlFiles)); | ||
| } | ||
|
|
||
| arguments.add("-jar"); | ||
| arguments.add("/scraper.jar"); | ||
|
|
||
| this.withCommand(arguments.toArray(new String[0])); | ||
|
|
||
| logger().info("Starting scraper with command: " + String.join(" ", arguments)); | ||
|
|
||
| super.start(); | ||
| } | ||
| } |
60 changes: 60 additions & 0 deletions
60
jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestApp.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.contrib.jmxscraper; | ||
|
|
||
| import java.lang.management.ManagementFactory; | ||
| import javax.management.MBeanServer; | ||
| import javax.management.ObjectName; | ||
|
|
||
| @SuppressWarnings("all") | ||
| public class TestApp implements TestAppMXBean { | ||
|
|
||
| public static final String APP_STARTED_MSG = "app started"; | ||
| public static final String OBJECT_NAME = "io.opentelemetry.test:name=TestApp"; | ||
|
|
||
| private volatile boolean running; | ||
|
|
||
| public static void main(String[] args) { | ||
| TestApp app = TestApp.start(); | ||
| while (app.isRunning()) { | ||
| try { | ||
| Thread.sleep(100); | ||
| } catch (InterruptedException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private TestApp() {} | ||
|
|
||
| static TestApp start() { | ||
| TestApp app = new TestApp(); | ||
| MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); | ||
| try { | ||
| ObjectName objectName = new ObjectName(OBJECT_NAME); | ||
| mbs.registerMBean(app, objectName); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| app.running = true; | ||
| System.out.println(APP_STARTED_MSG); | ||
| return app; | ||
| } | ||
|
|
||
| @Override | ||
| public int getIntValue() { | ||
| return 42; | ||
| } | ||
|
|
||
| @Override | ||
| public void stopApp() { | ||
| running = false; | ||
| } | ||
|
|
||
| boolean isRunning() { | ||
| return running; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.