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

Conversation

iamdanfox
Copy link
Contributor

Before this PR

I've been slowly trying to enable folks to use pattern-matching switch expressions instead of visitors for their conjure unions (see #hackweek-2022-sealed-unions), and one of the requirements for this is to add the --enable-preview flag at runtime (palantir/sls-packaging#1365).

It occurred to me that if folks ever actually started using this in production, we'd probably want a convenient way to be able to eyeball precisely which installations are using it... especially if we found some undesirable behaviour that only manifested in the --enable-preview case and we wanted to find usages and warn/remediate them.

After this PR

==COMMIT_MSG==
The uptime metric now has an additional tag enablePreview which signifies if the --enable-preview flag is passed to java at runtime or not.
==COMMIT_MSG==

Possible downsides?

  • I'm not using a typed accessor to detect if this is enabled, so if java maintainers changed their mind about how the flag could be enabled (e.g. using a config file) then my attribute could incorrectly report false.

@changelog-app
Copy link

changelog-app bot commented Aug 8, 2022

Generate changelog in changelog/@unreleased

Type
See change types. Select one:

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

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.

Check the box to generate changelog(s)

  • Generate changelog entry

@@ -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.

@iamdanfox iamdanfox changed the title uptime metric tracks whether --enable-preview is set [non urgent] uptime metric tracks whether --enable-preview is set Aug 8, 2022
Copy link
Contributor

@schlosna schlosna left a comment

Choose a reason for hiding this comment

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

Overall seems reasonable to track.

changelog/@unreleased/pr-1548.v2.yml Show resolved Hide resolved
Comment on lines 48 to 50
- name: enablePreview
docs: "Whether the JVM is running with --enable-preview (see JEP 12)"
values: [true, false]
Copy link
Contributor

Choose a reason for hiding this comment

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

palantir/metric-schema#832 recently added the runtime JDK version info as tags to all metrics. Including enablePreview tag on every metric produced is likely extraneous noise, so putting this on uptime seems reasonable and shouldn't change metric cardinality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Interesting that we've added it in metric-schema - I guess that means it's slightly easier to split up a graph in datadog by javaversion only!

tritium-metrics-jvm/src/main/metrics/metrics.yml Outdated Show resolved Hide resolved
@@ -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

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).

iamdanfox and others added 2 commits August 10, 2022 11:22
Co-authored-by: David Schlosnagle <schlosna@gmail.com>
Co-authored-by: David Schlosnagle <schlosna@gmail.com>
@iamdanfox
Copy link
Contributor Author

iamdanfox commented Aug 10, 2022

👍 to approve dschlosnagle's suggested commits - now just down to your +1

EDIT nvm I think my +1 is meaningless as I'm no longer an admin on this repo sorry

image

@bulldozer-bot bulldozer-bot bot merged commit 4ef3e44 into develop Aug 10, 2022
@bulldozer-bot bulldozer-bot bot deleted the dfox/enable-preview-metrics branch August 10, 2022 21:28
@svc-autorelease
Copy link
Collaborator

Released 0.52.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants