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

Reuse JMX Insights in Scraper + Tomcat support #1485

Merged
merged 12 commits into from
Oct 16, 2024

Conversation

SylvainJuge
Copy link
Contributor

@SylvainJuge SylvainJuge commented Oct 2, 2024

  • add snapshot dependency
  • first working poc with tomcat
  • add comments for future config enhancement
  • port tomcat YAML definiton from groovy
  • port jvm YAML definiton from groovy

Description:

Part of #1362

Testing:

Integration tests from JMX Gatherer almost copied as-is for jvm and tomcat systems.

Manual testing on a local tomcat server started with following JVM options in bin/setenv.sh

#!/bin/bash
opts=''
opts="${opts} -Dcom.sun.management.jmxremote.port=12345"
opts="${opts} -Dcom.sun.management.jmxremote.local.only=false"
opts="${opts} -Dcom.sun.management.jmxremote.authenticate=false"
opts="${opts} -Dcom.sun.management.jmxremote.ssl=false"
export CATALINA_OPTS="${opts:-}"

Scraper started with command line (in the ./jmx-scraper subfolder as working directory).

java \
-Dotel.metrics.exporter=otlp,logging \
-Dotel.exporter.otlp.endpoint=${OTEL_EXPORTER_OTLP_ENDPOINT} \
-Dotel.jmx.service.url=service:jmx:rmi:///jndi/rmi://localhost:12345/jmxrmi \
-Dotel.jmx.target.system=tomcat \
-jar ./build/libs/opentelemetry-jmx-scraper-1.40.0-alpha-SNAPSHOT.jar

The explicit otel.exporter.otlp.endpoint and otel.metrics.exporter Java system properties are needed due to a check in the configuration parsing (and they aren't yet read from the env variables), but this will later be refactored to use auto-configuration in a later PR to solve this.

throw new IllegalStateException("no support for " + system);
}
} catch (Exception e) {
throw new IllegalStateException("error while loading rules for system " + system, e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Other exception would be better here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll leave this one as-is for now, as we don't have dedicated runtime exceptions, but this could be an improvement later.

private int intervalMilliseconds;
private String metricsExporterType = "";
private String otlpExporterEndpoint = "";
private int intervalMilliseconds; // TODO only used to set 'otel.metric.export.interval' from SDK
Copy link
Contributor

Choose a reason for hiding this comment

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

What this TODO means here? Is there anything aditional to be implemented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, basically this configuration option is only used to configure the metrics polling interval and there is already a dedicated configuration option in the SDK for this, so if someone is used to configure the SDK using this one we should reuse the existing config option (we'll deal with that when adding auto-configuration here).

@SylvainJuge SylvainJuge marked this pull request as ready for review October 4, 2024 15:44
@SylvainJuge SylvainJuge requested a review from a team as a code owner October 4, 2024 15:44
@SylvainJuge
Copy link
Contributor Author

@robsunday I have just added support for both the JVM metrics and the Tomcat metrics with tests from Gatherer, so we have end-to-end testing now 🎉.

If you have some time for another review that would be great !

@SylvainJuge
Copy link
Contributor Author

In the context of integration tests, we always want to send data to otlp as otherwise we don't have a way to validate what it's captured, this is not meant to be a reusable test container outside of those integration tests.

For the filtering on the metrics, there was a filter on the metrics that are sent with a specific sdk version, now that we reuse code from instrumentation we do not get the project version as we used to have, but the version of the instrumentation project which is used as dependency.

@trask
Copy link
Member

trask commented Oct 16, 2024

sorry @robsunday, I hit the wrong button and re-requested a review from you, which also cleared your approval, can you re-approve? and let me know if there are any outstanding discussions, and if not I'll merge, thanks!

@trask
Copy link
Member

trask commented Oct 16, 2024

@SylvainJuge sorry, can you fix up the merge conflicts from #1480? thanks!

@@ -35,15 +44,25 @@ public class JmxScraper {
*/
@SuppressWarnings({"SystemOut", "SystemExitOutsideMain"})
public static void main(String[] args) {

// enable SDK auto-configure if not explicitly set by user
// TODO: refactor this to use AutoConfiguredOpenTelemetrySdk
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines +19 to +22
// TODO: remove snapshot repository once 2.9.0 is released
maven {
setUrl("https://oss.sonatype.org/content/repositories/snapshots")
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm merging anyways since

  • the jmx-scraper artifact isn't published yet so no worries about relying on snapshot repo from maven central
  • merging will unblock other work
  • we expect to update this to 2.9.0 within a week

@@ -76,6 +76,7 @@ public void start() {
// for now only configure through JVM args
List<String> arguments = new ArrayList<>();
arguments.add("java");
arguments.add("-Dotel.metrics.exporter=otlp");
Copy link
Member

Choose a reason for hiding this comment

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

I think it makes sense to align (long-term) if possible with the autoconfigure SDK defaults

@trask trask merged commit dc66266 into open-telemetry:main Oct 16, 2024
14 checks passed
@SylvainJuge SylvainJuge deleted the scraper-connect branch October 16, 2024 15:29
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.

4 participants