Skip to content

jmx-scraper: reconnect when connection is lost#2910

Merged
jaydeluca merged 4 commits into
open-telemetry:mainfrom
laurit:jmx-reconnect
Jun 15, 2026
Merged

jmx-scraper: reconnect when connection is lost#2910
jaydeluca merged 4 commits into
open-telemetry:mainfrom
laurit:jmx-reconnect

Conversation

@laurit

@laurit laurit commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Resolves #2909

@laurit
laurit requested a review from a team as a code owner June 12, 2026 15:56
Copilot AI review requested due to automatic review settings June 12, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the jmx-scraper runtime to better tolerate target restarts by re-establishing the JMX connection after it is lost (addressing issue #2909), and adds an integration test to validate reconnect behavior.

Changes:

  • Add a connection wrapper in JmxScraper that can drop the current MBeanServerConnection on disconnect and lazily reconnect on the next scrape cycle.
  • Refactor integration-test container orchestration into a shared base class to reduce duplication.
  • Add a new integration test that stops and restarts the target container and verifies metrics resume after restart.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxScraper.java Introduces a ConnectionHandler used by the JMX telemetry supplier to reconnect when the connector disconnects.
jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java Simplifies target-system integration tests by inheriting shared container lifecycle from the new base.
jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/BaseTargetSystemIntegrationTest.java New shared integration-test base class containing OTLP test server + container startup/verification helpers.
jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/ReconnectTest.java New integration test that validates scraper reconnect behavior across a target container restart.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment on lines +26 to +30
target.stop();
otlpServer.reset();
Thread.sleep(2_000);
List<ExportMetricsServiceRequest> receivedMetrics = otlpServer.getMetrics();
assertThat(receivedMetrics).isEmpty();

jmxTelemetry.start(() -> singletonList(connection));
try (ConnectionHandler connectionHandler = new ConnectionHandler(client)) {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What are the known cases where the context CL matters here ? It would be worth to document that a bit with a comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

wildfly tests fail without it, comment added

@github-actions
github-actions Bot requested a review from SylvainJuge June 15, 2026 13:04
@jaydeluca
jaydeluca added this pull request to the merge queue Jun 15, 2026
Merged via the queue into open-telemetry:main with commit cccbadf Jun 15, 2026
22 checks passed
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.

IO error while resolving mbean

4 participants