From bf6bc2c12a12ae481f9cca91fde446bdfd1967df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20St=C3=A4ber?= Date: Mon, 22 Jan 2024 13:49:45 +0100 Subject: [PATCH] Fix flaky JVM Thread metrics test (#915) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Stäber --- .../metrics/instrumentation/jvm/JvmThreadsMetricsTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmThreadsMetricsTest.java b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmThreadsMetricsTest.java index 7be7892a9..94cadc268 100644 --- a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmThreadsMetricsTest.java +++ b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmThreadsMetricsTest.java @@ -108,8 +108,9 @@ public void testIgnoredMetricNotScraped() { @Test public void testInvalidThreadIds() { try { - int javaVersion = Integer.parseInt(System.getProperty("java.version")); - if (javaVersion >= 21) { + String javaVersion = System.getProperty("java.version"); // Example: "21.0.2" + String majorJavaVersion = javaVersion.replaceAll("\\..*", ""); // Example: "21" + if (Integer.parseInt(majorJavaVersion) >= 21) { // With Java 21 and newer you can no longer have invalid thread ids. return; }