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

Rename runtime-metrics to runtime-telemetry-jmx #8165

Merged
merged 12 commits into from
May 16, 2023

Conversation

roberttoyonaga
Copy link
Contributor

@roberttoyonaga roberttoyonaga commented Mar 29, 2023

Summary of Changes
Rename the JMX metrics gatherer to runtime-telemetry-jmx to be consistent with its JFR counterpart. This change was also talked about a bit here: open-telemetry/opentelemetry-java-contrib#749 (comment)

This is a follow up to: #7886

Edit after discussion below

  • Restructuring and renaming has been done according to "Alternative C"
  • The Java17 entry point RuntimeMetrics sets up the metric gatherers from both JMX and JFR implementations.
  • The agent instrumentation in the Java8 module does not get applied if the Java17 instrumentation is being applied (so the JMX gatherers don't get registered twice.)
  • Set the scope for both JMX and JFR implementations to be io.opentelemetry.instrumentation.runtime-metrics
  • Made the JMX observables closeable similar to the JFR ones

@roberttoyonaga roberttoyonaga requested a review from a team March 29, 2023 20:49
@trask
Copy link
Member

trask commented Apr 1, 2023

hey @roberttoyonaga!

we discussed the naming of these modules in Java SIG meeting this week

I had a couple of concerns with the current proposal (runtime-telemetry-jmx and runtime-telemetry-jfr):

  • from user perspective (especially for library instrumentation users), they are "instrumenting the Java Runtime", and jmx or jfr are just implementation details
  • the difference between the runtime-telemetry-jmx and jmx-metrics artifacts seems potentially confusing

A couiple of alternatives were discussed:

Alternative A

  • runtime-metrics/
    • runtime-metrics-java8/
    • runtime-metrics-java17/

this mirrors other instrumentations which apply to different versions

@mateuszrzeszutek one thought I had since we discussed is that it seems confusing that Java 17 library users would want to use both -java8 and -java17 artifacts (and initialize them both in their code)

Alternative B

have a single runtime-metrics module which is a multi-release jar

@laurit @mateuszrzeszutek is the only argument against mrjar the added complexity?

we have one mrjar example module:

and while that's not being used by the javaagent, it does look like AgentClassLoader supports mrjars:

so maybe added complexity is not too bad?

@mateuszrzeszutek
Copy link
Member

and while that's not being used by the javaagent, it does look like AgentClassLoader supports mrjars:

AFAIR we use that in the resource providers module.

so maybe added complexity is not too bad?

I suspect most of the complexity will be in implementing the runtime-metrics module in a way that applies as many metrics as possible, depending on the Java version used. E.g. do we have a single entrypoint for all metrics (like JFR) or separate classes (JMX-style)? For the Java 17+ features, how should they appear in the public API of the module (which must be Java 8 compatible)?

@roberttoyonaga
Copy link
Contributor Author

one thought I had since we discussed is that it seems confusing that Java 17 library users would want to use both -java8 and -java17 artifacts (and initialize them both in their code)

Could an Alternative C be: Use the same structure as in "Alternative A" but have the entry point in runtime-metrics-java17 also set up the metrics from runtime-metrics-java8. Since we would be drawing a distinction between versions and not underlying implementations, it would be fine to make it transparent to the user that we are using both JMX and JFR. This way a user only needs to directly use the java 8 or java 17 module, depending on their java version. Then we could rename the JFR entry point to a more generalized name.

I'm not that knowledgeable about multi release jars. But would the following make sense:

For the java agent, I think we could have a Java 8 implementation that only registers the JMX handlers, and a Java 17 version which registers JFR as well.

With respect to the libraries, I think it could be good to introduce a single entry point for JMX (similar to JFR) that can register all the JMX handlers (since they are all required anyway). Once that's in place, we can have an over-arching GeneralRuntimeMetricsEntryPoint that abstracts over the JMX and JFR single entry points and provides the public API for users. In the mrjar this GeneralRuntimeMetricsEntryPoint can either call the JMX and JFR or only the JMX entrypoints, depending on the java version.

@laurit
Copy link
Contributor

laurit commented Apr 3, 2023

One potential issue with mrjar is that class loader needs to support mrjar for it to work. If user includes the metrics library in his war and deploys it into his favourite app server then this app server has to support mrjar to get access to the jdk17 features. As mrjars have been around for a while it is quite possible that support for them has been implemented everywhere where it matters.

@trask
Copy link
Member

trask commented Apr 4, 2023

For the Java 17+ features, how should they appear in the public API of the module (which must be Java 8 compatible)?

ah, yes, like opt-ing in to some higher-cardinality metrics, e.g. open-telemetry/opentelemetry-specification#3352 (comment)

Could an Alternative C be: Use the same structure as in "Alternative A" but have the entry point in runtime-metrics-java17 also set up the metrics from runtime-metrics-java8

this idea makes good sense to me

In this case I don't think we need mrjar, and the javaagent instrumentation can be written so that it also only applies to java8 or java17 (but not both)

@trask
Copy link
Member

trask commented May 10, 2023

@roberttoyonaga sorry for the delay, will merge this right after the 1.26.0 release tomorrow

@@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.runtimemetrics;
package io.opentelemetry.instrumentation.runtimemetricsjava8;
Copy link
Member

Choose a reason for hiding this comment

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

WDYT about renaming the package to ...runtimemetrics.java8? (or ..runtimemetrics.j8)

I think that the java8/java17 implementations are somewhat similar to our usual v1_2 package name suffixes; this is the same feature/instrumentation, but for different runtime versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I've renamed to ...runtimemetrics.java8 and ...runtimemetrics.java17

.setDescription("The number of buffers in the pool")
.setUnit("{buffers}")
.buildWithCallback(callback(bufferBeans, BufferPoolMXBean::getCount));
public static void closeObservers() {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of keeping a global stateful list of observers, WDYT about making the registerObservers(OpenTelemetry) function return a Closeable? The users can decide how to handle these themselves.

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 think this is a good idea. I have applied your suggestion.


private static final String INSTRUMENTATION_NAME = "io.opentelemetry.runtime-metrics";
private static final String INSTRUMENTATION_NAME =
"io.opentelemetry.instrumentation.runtime-metrics";
Copy link
Member

Choose a reason for hiding this comment

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

We usually name our instrumentations io.opentelemetry.<name-version>

Suggested change
"io.opentelemetry.instrumentation.runtime-metrics";
"io.opentelemetry.runtime-metrics-java8";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

if (config.getBoolean("otel.instrumentation.runtime-metrics-java17.enable-all", false)) {
runtimeMetrics = RuntimeMetrics.builder(openTelemetry).enableAllFeatures().build();
} else if (config.getBoolean("otel.instrumentation.runtime-metrics-java17.enabled", false)) {
runtimeMetrics = RuntimeMetrics.create(openTelemetry);
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should enable both JMX+JFR default metrics if otel.instrumentation.runtime-metrics.enabled is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm yeah we talked a bit about this here. It was decided that we'd wait for the semantic conventions to be updated first in-case the JFR metrics end up changing.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I see.
At the very least, let's add a condition checking otel.instrumentation.runtime-metrics.enabled somewhere in this method -- the current version of that is impossible to turn off on java 17+

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 that's a good point. I'll add the same check that's done in Java8RuntimeMetricsInstaller before enabling the JMX gathered metrics.

@roberttoyonaga
Copy link
Contributor Author

@roberttoyonaga sorry for the delay, will merge this right after the 1.26.0 release tomorrow

Thanks @trask ! Actually, can you hold off on merging for another day? I'm going to try implementing Mateusz's new suggestions.

@roberttoyonaga
Copy link
Contributor Author

ok @trask I'm done with the updates!

@@ -12,10 +12,9 @@
import java.util.List;
import javax.annotation.Nullable;

class JmxRuntimeMetricsUtil {
public class JmxRuntimeMetricsUtil {
Copy link
Member

Choose a reason for hiding this comment

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

Can you move it to an .internal package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I've moved it to io.opentelemetry.instrumentation.runtimemetrics.java8.internal now

@trask
Copy link
Member

trask commented May 11, 2023

@dependabot update

@trask
Copy link
Member

trask commented May 11, 2023

@opentelemetrybot update

CHANGELOG.md Outdated Show resolved Hide resolved
@trask trask merged commit 3d0971b into open-telemetry:main May 16, 2023
@trask
Copy link
Member

trask commented May 16, 2023

thx @roberttoyonaga!

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.

5 participants