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

[non urgent] uptime metric tracks whether --enable-preview is set #1548

Merged
merged 4 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/@unreleased/pr-1548.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: feature
feature:
description: The `uptime` metric now has an additional tag `enablePreview` which
signifies if the `--enable-preview` flag is passed to java at runtime or not.
links:
- https://github.com/palantir/tritium/pull/1548
iamdanfox marked this conversation as resolved.
Show resolved Hide resolved
- https://openjdk.org/jeps/12
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.palantir.logsafe.logger.SafeLogger;
import com.palantir.logsafe.logger.SafeLoggerFactory;
import com.palantir.tritium.metrics.MetricRegistries;
import com.palantir.tritium.metrics.jvm.InternalJvmMetrics.AttributeUptime_EnablePreview;
import com.palantir.tritium.metrics.registry.TaggedMetricRegistry;
import java.lang.management.ClassLoadingMXBean;
import java.lang.management.ManagementFactory;
Expand Down Expand Up @@ -80,6 +81,10 @@ private static void registerAttributes(InternalJvmMetrics metrics) {
.javaRuntimeVersion(System.getProperty("java.runtime.version", "unknown"))
.javaVendorVersion(System.getProperty("java.vendor.version", "unknown"))
.javaVmVendor(System.getProperty("java.vm.vendor", "unknown"))
.enablePreview(
runtimeMxBean.getInputArguments().contains("--enable-preview")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like we don't have junit tests to prove this method gives us sensible values, but I did validate this:

$ jshell --enable-preview
|  Welcome to JShell -- Version 15.0.7
|  For an introduction type: /help intro

jshell> java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments()
$1 ==> [-agentlib:jdwp=transport=dt_socket,address=localhost:61023, --enable-preview]

Copy link
Contributor

Choose a reason for hiding this comment

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

If we wanted to unit test this, I think we'd need to bump source and library target to at least 12 and enable preview at compilation, effectively forcing consumers to JDK 15. I don't think we are quite ready to force that JDK dependency bump for tritium quite yet (though possibly soon).

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 don't think we ever want to --enable-preview for the compilation of published jars, because they can only be run by the same java version that was used to compile them (i.e. if we did this with java15 for :tritium-metrics-jvm then anyone running java17 in production would fail to start)... I think this would quickly lead to unsolveable dependency graphs and much angst in #dev-backend-infra.

We'd need to either invent a gradle API for setting --enable-preview on the test sourceset only (I didn't add support for this initially palantir/gradle-baseline#2322), or make up an entire separate gradle project that we would enable preview on.

? AttributeUptime_EnablePreview.TRUE
: AttributeUptime_EnablePreview.FALSE)
.build(runtimeMxBean::getUptime);
}

Expand Down
25 changes: 16 additions & 9 deletions tritium-metrics-jvm/src/main/metrics/metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@ namespaces:
attribute.uptime:
type: gauge
docs: |
Provides the Java virtual machine uptime value in milliseconds. Example tags:
javaSpecificationVersion = 11, javaVersion = 11.0.3, javaVersionDate = 2019-04-16,
javaRuntimeVersion = 11.0.3+7-LTS, javaVendorVersion = Zulu11.31+11-CA, javaVmVendor = Azul Systems, Inc.
Provides the Java virtual machine uptime value in milliseconds.
tags:
- javaSpecificationVersion
- javaVersion
- javaVersionDate
- javaRuntimeVersion
- javaVendorVersion
- javaVmVendor
- name: javaSpecificationVersion
docs: "Example: 11"
- name: javaVersion
docs: "Example: 11.0.3"
- name: javaVersionDate
docs: "Example: 2019-04-16"
- name: javaRuntimeVersion
docs: "Example: 11.0.3+7-LTS"
- name: javaVendorVersion
docs: "Example: Zulu11.31+11-CA"
- name: javaVmVendor
docs: "Example: Azul Systems, Inc."
- name: enablePreview
docs: "Whether the JVM is running with --enable-preview (see https://openjdk.org/jeps/12 )"
values: [true, false]
classloader.loaded:
type: gauge
docs: Total number of classes that have been loaded since the jvm started.
Expand Down