diff --git a/pom.xml b/pom.xml index f3ab23e3c..8bef560fb 100644 --- a/pom.xml +++ b/pom.xml @@ -37,10 +37,10 @@ 0.11.4.1 3.0.1 3.2.5 - 5.0.0-rc17 - 1.5.10 - 0.16.0 - 3.7.7 + 5.0.0-rc17 + 1.13.2 + 1.3.1 + 3.7.7 4.13.5 2.5.4 42.7.4 @@ -211,8 +211,22 @@ io.prometheus - simpleclient - ${simpleclient.version} + prometheus-metrics-core + ${prometheus-metrics.version} + provided + true + + + io.prometheus + prometheus-metrics-instrumentation-jvm + ${prometheus-metrics.version} + provided + true + + + io.prometheus + prometheus-metrics-exporter-httpserver + ${prometheus-metrics.version} provided true @@ -617,6 +631,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 21 + 21 + + diff --git a/src/main/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollector.java b/src/main/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollector.java index 8159352e6..67635a104 100644 --- a/src/main/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollector.java +++ b/src/main/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollector.java @@ -16,28 +16,28 @@ package com.zaxxer.hikari.metrics.prometheus; -import com.zaxxer.hikari.metrics.PoolStats; -import io.prometheus.client.Collector; -import io.prometheus.client.GaugeMetricFamily; - +import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; -class HikariCPCollector extends Collector -{ +import com.zaxxer.hikari.metrics.PoolStats; - private static final List LABEL_NAMES = Collections.singletonList("pool"); +import io.prometheus.metrics.model.registry.MultiCollector; +import io.prometheus.metrics.model.snapshots.GaugeSnapshot; +import io.prometheus.metrics.model.snapshots.Labels; +import io.prometheus.metrics.model.snapshots.MetricMetadata; +import io.prometheus.metrics.model.snapshots.MetricSnapshots; + +class HikariCPCollector implements MultiCollector { private final Map poolStatsMap = new ConcurrentHashMap<>(); - @Override - public List collect() + public MetricSnapshots collect() { - return Arrays.asList( + return new MetricSnapshots(Arrays.asList( createGauge("hikaricp_active_connections", "Active connections", PoolStats::getActiveConnections), createGauge("hikaricp_idle_connections", "Idle connections", @@ -50,7 +50,7 @@ public List collect() PoolStats::getMaxConnections), createGauge("hikaricp_min_connections", "Min connections", PoolStats::getMinConnections) - ); + )); } void add(String name, PoolStats poolStats) @@ -63,14 +63,13 @@ void remove(String name) poolStatsMap.remove(name); } - private GaugeMetricFamily createGauge(String metric, String help, - Function metricValueFunction) + private GaugeSnapshot createGauge(String metric, String help, + Function metricValueFunction) { - var metricFamily = new GaugeMetricFamily(metric, help, LABEL_NAMES); - poolStatsMap.forEach((k, v) -> metricFamily.addMetric( - Collections.singletonList(k), - metricValueFunction.apply(v) + Collection gaugeDataPointSnapshots = new ArrayList<>(); + poolStatsMap.forEach((k, v) -> gaugeDataPointSnapshots.add( + new GaugeSnapshot.GaugeDataPointSnapshot(metricValueFunction.apply(v), Labels.of("pool", k), null) )); - return metricFamily; + return new GaugeSnapshot(new MetricMetadata(metric, help), gaugeDataPointSnapshots); } } diff --git a/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTracker.java b/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTracker.java index d7ee62730..de250f0a0 100644 --- a/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTracker.java +++ b/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTracker.java @@ -16,9 +16,11 @@ package com.zaxxer.hikari.metrics.prometheus; import com.zaxxer.hikari.metrics.IMetricsTracker; -import io.prometheus.client.CollectorRegistry; -import io.prometheus.client.Counter; -import io.prometheus.client.Histogram; +import io.prometheus.metrics.core.datapoints.CounterDataPoint; +import io.prometheus.metrics.core.datapoints.DistributionDataPoint; +import io.prometheus.metrics.core.metrics.Histogram; +import io.prometheus.metrics.model.registry.PrometheusRegistry; +import io.prometheus.metrics.core.metrics.Counter; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -36,11 +38,11 @@ */ class PrometheusHistogramMetricsTracker implements IMetricsTracker { - private static final Counter CONNECTION_TIMEOUT_COUNTER = Counter.build() - .name("hikaricp_connection_timeout_total") + private static final Counter CONNECTION_TIMEOUT_COUNTER = Counter.builder() + .name("hikaricp_connection_timeout") .labelNames("pool") .help("Connection timeout total count") - .create(); + .register(); private static final Histogram ELAPSED_ACQUIRED_HISTOGRAM = registerHistogram("hikaricp_connection_acquired_nanos", "Connection acquired time (ns)", 1_000); @@ -51,42 +53,42 @@ class PrometheusHistogramMetricsTracker implements IMetricsTracker private static final Histogram ELAPSED_CREATION_HISTOGRAM = registerHistogram("hikaricp_connection_creation_millis", "Connection creation (ms)", 1); - private final Counter.Child connectionTimeoutCounterChild; + private final CounterDataPoint connectionTimeoutCounterChild; private static Histogram registerHistogram(String name, String help, double bucketStart) { - return Histogram.build() + return Histogram.builder() .name(name) .labelNames("pool") .help(help) - .exponentialBuckets(bucketStart, 2.0, 11) - .create(); + .classicExponentialUpperBounds(bucketStart, 2.0, 11) + .register(); } - private final static Map registrationStatuses = new ConcurrentHashMap<>(); + private final static Map registrationStatuses = new ConcurrentHashMap<>(); private final String poolName; private final HikariCPCollector hikariCPCollector; - private final Histogram.Child elapsedAcquiredHistogramChild; - private final Histogram.Child elapsedBorrowedHistogramChild; - private final Histogram.Child elapsedCreationHistogramChild; + private final DistributionDataPoint elapsedAcquiredHistogramChild; + private final DistributionDataPoint elapsedBorrowedHistogramChild; + private final DistributionDataPoint elapsedCreationHistogramChild; - PrometheusHistogramMetricsTracker(String poolName, CollectorRegistry collectorRegistry, HikariCPCollector hikariCPCollector) { + PrometheusHistogramMetricsTracker(String poolName, PrometheusRegistry collectorRegistry, HikariCPCollector hikariCPCollector) { registerMetrics(collectorRegistry); this.poolName = poolName; this.hikariCPCollector = hikariCPCollector; - this.connectionTimeoutCounterChild = CONNECTION_TIMEOUT_COUNTER.labels(poolName); - this.elapsedAcquiredHistogramChild = ELAPSED_ACQUIRED_HISTOGRAM.labels(poolName); - this.elapsedBorrowedHistogramChild = ELAPSED_BORROWED_HISTOGRAM.labels(poolName); - this.elapsedCreationHistogramChild = ELAPSED_CREATION_HISTOGRAM.labels(poolName); + this.connectionTimeoutCounterChild = CONNECTION_TIMEOUT_COUNTER.labelValues(poolName); + this.elapsedAcquiredHistogramChild = ELAPSED_ACQUIRED_HISTOGRAM.labelValues(poolName); + this.elapsedBorrowedHistogramChild = ELAPSED_BORROWED_HISTOGRAM.labelValues(poolName); + this.elapsedCreationHistogramChild = ELAPSED_CREATION_HISTOGRAM.labelValues(poolName); } - private void registerMetrics(CollectorRegistry collectorRegistry) { + private void registerMetrics(PrometheusRegistry collectorRegistry) { if (registrationStatuses.putIfAbsent(collectorRegistry, REGISTERED) == null) { - CONNECTION_TIMEOUT_COUNTER.register(collectorRegistry); - ELAPSED_ACQUIRED_HISTOGRAM.register(collectorRegistry); - ELAPSED_BORROWED_HISTOGRAM.register(collectorRegistry); - ELAPSED_CREATION_HISTOGRAM.register(collectorRegistry); + collectorRegistry.register(CONNECTION_TIMEOUT_COUNTER); + collectorRegistry.register(ELAPSED_ACQUIRED_HISTOGRAM); + collectorRegistry.register(ELAPSED_BORROWED_HISTOGRAM); + collectorRegistry.register(ELAPSED_CREATION_HISTOGRAM); } } diff --git a/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerFactory.java b/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerFactory.java index 612b4b2ce..4ff8db3ad 100644 --- a/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerFactory.java +++ b/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerFactory.java @@ -20,13 +20,13 @@ import com.zaxxer.hikari.metrics.MetricsTrackerFactory; import com.zaxxer.hikari.metrics.PoolStats; import com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory.RegistrationStatus; -import io.prometheus.client.Collector; -import io.prometheus.client.CollectorRegistry; +import io.prometheus.metrics.model.registry.MultiCollector; +import io.prometheus.metrics.model.registry.PrometheusRegistry; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import static com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory.RegistrationStatus.*; +import static com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory.RegistrationStatus.REGISTERED; /** *
{@code
@@ -36,25 +36,25 @@
  */
 public class PrometheusHistogramMetricsTrackerFactory implements MetricsTrackerFactory {
 
-   private final static Map registrationStatuses = new ConcurrentHashMap<>();
+   private final static Map registrationStatuses = new ConcurrentHashMap<>();
 
    private final HikariCPCollector collector = new HikariCPCollector();
 
-   private final CollectorRegistry collectorRegistry;
+   private final PrometheusRegistry collectorRegistry;
 
    /**
     * Default Constructor. The Hikari metrics are registered to the default
     * collector registry ({@code CollectorRegistry.defaultRegistry}).
     */
    public PrometheusHistogramMetricsTrackerFactory() {
-      this(CollectorRegistry.defaultRegistry);
+      this(new PrometheusRegistry());
    }
 
    /**
-    * Constructor that allows to pass in a {@link CollectorRegistry} to which the
+    * Constructor that allows to pass in a {@link PrometheusRegistry} to which the
     * Hikari metrics are registered.
     */
-   public PrometheusHistogramMetricsTrackerFactory(CollectorRegistry collectorRegistry) {
+   public PrometheusHistogramMetricsTrackerFactory(PrometheusRegistry collectorRegistry) {
       this.collectorRegistry = collectorRegistry;
    }
 
@@ -65,9 +65,9 @@ public IMetricsTracker create(String poolName, PoolStats poolStats) {
       return new PrometheusHistogramMetricsTracker(poolName, this.collectorRegistry, this.collector);
    }
 
-   private void registerCollector(Collector collector, CollectorRegistry collectorRegistry) {
+   private void registerCollector(MultiCollector collector, PrometheusRegistry collectorRegistry) {
       if (registrationStatuses.putIfAbsent(collectorRegistry, REGISTERED) == null) {
-         collector.register(collectorRegistry);
+         collectorRegistry.register(collector);
       }
    }
 }
diff --git a/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTracker.java b/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTracker.java
index 5d03c1ad4..cb78ddd5d 100644
--- a/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTracker.java
+++ b/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTracker.java
@@ -18,9 +18,11 @@
 
 import com.zaxxer.hikari.metrics.IMetricsTracker;
 import com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory.RegistrationStatus;
-import io.prometheus.client.CollectorRegistry;
-import io.prometheus.client.Counter;
-import io.prometheus.client.Summary;
+import io.prometheus.metrics.core.datapoints.CounterDataPoint;
+import io.prometheus.metrics.core.datapoints.DistributionDataPoint;
+import io.prometheus.metrics.core.metrics.Counter;
+import io.prometheus.metrics.core.metrics.Summary;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
 
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -30,11 +32,11 @@
 
 class PrometheusMetricsTracker implements IMetricsTracker
 {
-   private final static Counter CONNECTION_TIMEOUT_COUNTER = Counter.build()
-      .name("hikaricp_connection_timeout_total")
+   private final static Counter CONNECTION_TIMEOUT_COUNTER = Counter.builder()
+      .name("hikaricp_connection_timeout")
       .labelNames("pool")
       .help("Connection timeout total count")
-      .create();
+      .register();
 
    private final static Summary ELAPSED_ACQUIRED_SUMMARY =
       createSummary("hikaricp_connection_acquired_nanos", "Connection acquired time (ns)");
@@ -45,35 +47,35 @@ class PrometheusMetricsTracker implements IMetricsTracker
    private final static Summary ELAPSED_CREATION_SUMMARY =
       createSummary("hikaricp_connection_creation_millis", "Connection creation (ms)");
 
-   private final static Map registrationStatuses = new ConcurrentHashMap<>();
+   private final static Map registrationStatuses = new ConcurrentHashMap<>();
 
    private final String poolName;
    private final HikariCPCollector hikariCPCollector;
 
-   private final Counter.Child connectionTimeoutCounterChild;
+   private final CounterDataPoint connectionTimeoutCounterChild;
 
-   private final Summary.Child elapsedAcquiredSummaryChild;
-   private final Summary.Child elapsedUsageSummaryChild;
-   private final Summary.Child elapsedCreationSummaryChild;
+   private final DistributionDataPoint elapsedAcquiredSummaryChild;
+   private final DistributionDataPoint elapsedUsageSummaryChild;
+   private final DistributionDataPoint elapsedCreationSummaryChild;
 
-   PrometheusMetricsTracker(String poolName, CollectorRegistry collectorRegistry, HikariCPCollector hikariCPCollector)
+   PrometheusMetricsTracker(String poolName, PrometheusRegistry collectorRegistry, HikariCPCollector hikariCPCollector)
    {
       registerMetrics(collectorRegistry);
       this.poolName = poolName;
       this.hikariCPCollector = hikariCPCollector;
-      this.connectionTimeoutCounterChild = CONNECTION_TIMEOUT_COUNTER.labels(poolName);
-      this.elapsedAcquiredSummaryChild = ELAPSED_ACQUIRED_SUMMARY.labels(poolName);
-      this.elapsedUsageSummaryChild = ELAPSED_USAGE_SUMMARY.labels(poolName);
-      this.elapsedCreationSummaryChild = ELAPSED_CREATION_SUMMARY.labels(poolName);
+      this.connectionTimeoutCounterChild = CONNECTION_TIMEOUT_COUNTER.labelValues(poolName);
+      this.elapsedAcquiredSummaryChild = ELAPSED_ACQUIRED_SUMMARY.labelValues(poolName);
+      this.elapsedUsageSummaryChild = ELAPSED_USAGE_SUMMARY.labelValues(poolName);
+      this.elapsedCreationSummaryChild = ELAPSED_CREATION_SUMMARY.labelValues(poolName);
    }
 
-   private void registerMetrics(CollectorRegistry collectorRegistry)
+   private void registerMetrics(PrometheusRegistry collectorRegistry)
    {
       if (registrationStatuses.putIfAbsent(collectorRegistry, REGISTERED) == null) {
-         CONNECTION_TIMEOUT_COUNTER.register(collectorRegistry);
-         ELAPSED_ACQUIRED_SUMMARY.register(collectorRegistry);
-         ELAPSED_USAGE_SUMMARY.register(collectorRegistry);
-         ELAPSED_CREATION_SUMMARY.register(collectorRegistry);
+         collectorRegistry.register(CONNECTION_TIMEOUT_COUNTER);
+         collectorRegistry.register(ELAPSED_ACQUIRED_SUMMARY);
+         collectorRegistry.register(ELAPSED_USAGE_SUMMARY);
+         collectorRegistry.register(ELAPSED_CREATION_SUMMARY);
       }
    }
 
@@ -103,7 +105,7 @@ public void recordConnectionTimeout()
 
    private static Summary createSummary(String name, String help)
    {
-      return Summary.build()
+      return Summary.builder()
          .name(name)
          .labelNames("pool")
          .help(help)
@@ -111,8 +113,8 @@ private static Summary createSummary(String name, String help)
          .quantile(0.95, 0.01)
          .quantile(0.99, 0.001)
          .maxAgeSeconds(TimeUnit.MINUTES.toSeconds(5))
-         .ageBuckets(5)
-         .create();
+         .numberOfAgeBuckets(5)
+         .register();
    }
 
    @Override
diff --git a/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactory.java b/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactory.java
index f24ec3595..890f49570 100644
--- a/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactory.java
+++ b/src/main/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactory.java
@@ -19,8 +19,9 @@
 import com.zaxxer.hikari.metrics.IMetricsTracker;
 import com.zaxxer.hikari.metrics.MetricsTrackerFactory;
 import com.zaxxer.hikari.metrics.PoolStats;
-import io.prometheus.client.Collector;
-import io.prometheus.client.CollectorRegistry;
+import io.prometheus.metrics.model.registry.Collector;
+import io.prometheus.metrics.model.registry.MultiCollector;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
 
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -43,11 +44,11 @@
 public class PrometheusMetricsTrackerFactory implements MetricsTrackerFactory
 {
 
-   private final static Map registrationStatuses = new ConcurrentHashMap<>();
+   private final static Map registrationStatuses = new ConcurrentHashMap<>();
 
    private final HikariCPCollector collector = new HikariCPCollector();
 
-   private final CollectorRegistry collectorRegistry;
+   private final PrometheusRegistry collectorRegistry;
 
    enum RegistrationStatus
    {
@@ -60,14 +61,14 @@ enum RegistrationStatus
     */
    public PrometheusMetricsTrackerFactory()
    {
-      this(CollectorRegistry.defaultRegistry);
+      this(PrometheusRegistry.defaultRegistry);
    }
 
    /**
-    * Constructor that allows to pass in a {@link CollectorRegistry} to which the
+    * Constructor that allows to pass in a {@link PrometheusRegistry} to which the
     * Hikari metrics are registered.
     */
-   public PrometheusMetricsTrackerFactory(CollectorRegistry collectorRegistry)
+   public PrometheusMetricsTrackerFactory(PrometheusRegistry collectorRegistry)
    {
       this.collectorRegistry = collectorRegistry;
    }
@@ -80,10 +81,10 @@ public IMetricsTracker create(String poolName, PoolStats poolStats)
       return new PrometheusMetricsTracker(poolName, this.collectorRegistry, this.collector);
    }
 
-   private void registerCollector(Collector collector, CollectorRegistry collectorRegistry)
+   private void registerCollector(MultiCollector collector, PrometheusRegistry collectorRegistry)
    {
       if (registrationStatuses.putIfAbsent(collectorRegistry, REGISTERED) == null) {
-         collector.register(collectorRegistry);
+         collectorRegistry.register(collector);
       }
    }
 }
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index 703e1e0d8..cb2a3c80a 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -5,12 +5,13 @@
    requires java.naming;
    requires org.slf4j;
    requires static org.hibernate.orm.core;
-   requires static simpleclient;
    requires static metrics.core;
    requires static metrics.healthchecks;
    requires static io.dropwizard.metrics5;
    requires static micrometer.core;
    requires static org.javassist;
+   requires static io.prometheus.metrics.core;
+   requires static io.prometheus.metrics.model;
 
    exports com.zaxxer.hikari;
    exports com.zaxxer.hikari.hibernate;
diff --git a/src/test/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollectorTest.java b/src/test/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollectorTest.java
index 93833cd24..325f9768a 100644
--- a/src/test/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollectorTest.java
+++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollectorTest.java
@@ -19,32 +19,32 @@
 import static com.zaxxer.hikari.pool.TestElf.newHikariConfig;
 import static com.zaxxer.hikari.util.UtilityElf.quietlySleep;
 import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
 
 import java.sql.Connection;
-import java.util.List;
 
-import com.zaxxer.hikari.metrics.PoolStats;
-import io.prometheus.client.Collector;
 import org.junit.Before;
 import org.junit.Test;
 
 import com.zaxxer.hikari.HikariConfig;
 import com.zaxxer.hikari.HikariDataSource;
+import com.zaxxer.hikari.metrics.PoolStats;
 import com.zaxxer.hikari.mocks.StubConnection;
 
-import io.prometheus.client.CollectorRegistry;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
+import io.prometheus.metrics.model.snapshots.GaugeSnapshot;
+import io.prometheus.metrics.model.snapshots.MetricSnapshots;
 
 public class HikariCPCollectorTest
 {
 
-   private CollectorRegistry collectorRegistry;
+   private PrometheusRegistry collectorRegistry;
 
    @Before
    public void setupCollectorRegistry()
    {
-      this.collectorRegistry = new CollectorRegistry();
+      this.collectorRegistry = new PrometheusRegistry();
    }
 
    @Test
@@ -183,11 +183,11 @@ public void testHikariCPCollectorGaugesMetricsInitialization()
    {
       HikariCPCollector hikariCPCollector = new HikariCPCollector();
       hikariCPCollector.add("collectorTestPool", poolStatsWithPredefinedValues());
-      List metrics = hikariCPCollector.collect();
-      hikariCPCollector.register(collectorRegistry);
+      MetricSnapshots metrics = hikariCPCollector.collect();
+      collectorRegistry.register(hikariCPCollector);
 
       assertThat(metrics.size(), is(6));
-      assertThat(metrics.stream().filter(metricFamilySamples -> metricFamilySamples.type == Collector.Type.GAUGE).count(), is(6L));
+      assertThat((metrics.stream().filter(metricSnapshot -> metricSnapshot instanceof GaugeSnapshot)).count(), is(6L));
       assertThat(getValue("hikaricp_active_connections", "collectorTestPool"), is(58.0));
       assertThat(getValue("hikaricp_idle_connections", "collectorTestPool"), is(42.0));
       assertThat(getValue("hikaricp_pending_threads", "collectorTestPool"), is(1.0));
@@ -200,7 +200,7 @@ private Double getValue(String name, String poolName)
    {
       String[] labelNames = {"pool"};
       String[] labelValues = {poolName};
-      return this.collectorRegistry.getSampleValue(name, labelNames, labelValues);
+      return Samples.getSampleValue(collectorRegistry, name, labelNames, labelValues);
    }
 
    private PoolStats poolStatsWithPredefinedValues()
diff --git a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerFactoryTest.java b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerFactoryTest.java
index d735dc7bc..de8c827f5 100644
--- a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerFactoryTest.java
+++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerFactoryTest.java
@@ -1,44 +1,43 @@
 package com.zaxxer.hikari.metrics.prometheus;
 
-import com.zaxxer.hikari.metrics.PoolStats;
-import io.prometheus.client.Collector;
-import io.prometheus.client.CollectorRegistry;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
 import org.junit.After;
 import org.junit.Test;
 
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
+import com.zaxxer.hikari.metrics.IMetricsTracker;
+import com.zaxxer.hikari.metrics.PoolStats;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
+import io.prometheus.metrics.model.snapshots.MetricSnapshots;
 
 public class PrometheusHistogramMetricsTrackerFactoryTest {
 
    @Test
    public void registersToProvidedCollectorRegistry() {
-      CollectorRegistry collectorRegistry = new CollectorRegistry();
+      PrometheusRegistry collectorRegistry = new PrometheusRegistry();
       PrometheusHistogramMetricsTrackerFactory factory =
          new PrometheusHistogramMetricsTrackerFactory(collectorRegistry);
-      factory.create("testpool-1", poolStats());
-      assertHikariMetricsAreNotPresent(CollectorRegistry.defaultRegistry);
+      IMetricsTracker iMetricsTracker = factory.create("testpool-1", poolStats());
+      assertHikariMetricsAreNotPresent(PrometheusRegistry.defaultRegistry);
       assertHikariMetricsArePresent(collectorRegistry);
+      iMetricsTracker.close();
    }
 
    @Test
    public void registersToDefaultCollectorRegistry() {
       PrometheusHistogramMetricsTrackerFactory factory = new PrometheusHistogramMetricsTrackerFactory();
-      factory.create("testpool-2", poolStats());
-      assertHikariMetricsArePresent(CollectorRegistry.defaultRegistry);
-   }
-
-   @After
-   public void clearCollectorRegistry(){
-      CollectorRegistry.defaultRegistry.clear();
+      IMetricsTracker iMetricsTracker = factory.create("testpool-2", poolStats());
+      assertHikariMetricsArePresent(PrometheusRegistry.defaultRegistry);
+      iMetricsTracker.close();
    }
 
-   private void assertHikariMetricsArePresent(CollectorRegistry collectorRegistry) {
-      List registeredMetrics = toMetricNames(collectorRegistry.metricFamilySamples());
+   private void assertHikariMetricsArePresent(PrometheusRegistry collectorRegistry) {
+      List registeredMetrics = toMetricNames(collectorRegistry.scrape());
       assertTrue(registeredMetrics.contains("hikaricp_active_connections"));
       assertTrue(registeredMetrics.contains("hikaricp_idle_connections"));
       assertTrue(registeredMetrics.contains("hikaricp_pending_threads"));
@@ -47,8 +46,8 @@ private void assertHikariMetricsArePresent(CollectorRegistry collectorRegistry)
       assertTrue(registeredMetrics.contains("hikaricp_min_connections"));
    }
 
-   private void assertHikariMetricsAreNotPresent(CollectorRegistry collectorRegistry) {
-      List registeredMetrics = toMetricNames(collectorRegistry.metricFamilySamples());
+   private void assertHikariMetricsAreNotPresent(PrometheusRegistry collectorRegistry) {
+      List registeredMetrics = toMetricNames(collectorRegistry.scrape());
       assertFalse(registeredMetrics.contains("hikaricp_active_connections"));
       assertFalse(registeredMetrics.contains("hikaricp_idle_connections"));
       assertFalse(registeredMetrics.contains("hikaricp_pending_threads"));
@@ -57,12 +56,8 @@ private void assertHikariMetricsAreNotPresent(CollectorRegistry collectorRegistr
       assertFalse(registeredMetrics.contains("hikaricp_min_connections"));
    }
 
-   private List toMetricNames(Enumeration enumeration) {
-      List list = new ArrayList<>();
-      while (enumeration.hasMoreElements()) {
-         list.add(enumeration.nextElement().name);
-      }
-      return list;
+   private List toMetricNames(MetricSnapshots metricSnapshots) {
+      return metricSnapshots.stream().map(metricSnapshot -> metricSnapshot.getMetadata().getName()).collect(Collectors.toList());
    }
 
    private PoolStats poolStats() {
diff --git a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerTest.java b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerTest.java
index 4d74dd661..a73b62438 100644
--- a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerTest.java
+++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerTest.java
@@ -18,7 +18,7 @@
 
 import com.zaxxer.hikari.HikariConfig;
 import com.zaxxer.hikari.HikariDataSource;
-import io.prometheus.client.CollectorRegistry;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -32,16 +32,16 @@
 
 public class PrometheusHistogramMetricsTrackerTest {
 
-   private CollectorRegistry defaultCollectorRegistry;
-   private CollectorRegistry customCollectorRegistry;
+   private PrometheusRegistry defaultCollectorRegistry;
+   private PrometheusRegistry customCollectorRegistry;
 
    private static final String POOL_LABEL_NAME = "pool";
    private static final String[] LABEL_NAMES = {POOL_LABEL_NAME};
 
    @Before
    public void setupCollectorRegistry() {
-      this.defaultCollectorRegistry = new CollectorRegistry();
-      this.customCollectorRegistry = new CollectorRegistry();
+      this.defaultCollectorRegistry = new PrometheusRegistry();
+      this.customCollectorRegistry = new PrometheusRegistry();
    }
 
    @Test
@@ -62,8 +62,8 @@ public void recordConnectionTimeout() throws Exception {
             }
          }
 
-         Double total = defaultCollectorRegistry.getSampleValue(
-            "hikaricp_connection_timeout_total",
+         Double total = Samples.getSampleValue(defaultCollectorRegistry,
+            "hikaricp_connection_timeout",
             LABEL_NAMES,
             labelValues
          );
@@ -107,13 +107,13 @@ public void testMultiplePoolNameWithOneCollectorRegistry()
       String[] labelValuesSecondPool = {configSecondPool.getPoolName()};
 
       try (HikariDataSource ignoredFirstPool = new HikariDataSource(configFirstPool)) {
-         assertThat(defaultCollectorRegistry.getSampleValue(
-            "hikaricp_connection_timeout_total", LABEL_NAMES, labelValuesFirstPool),
+         assertThat(Samples.getSampleValue(defaultCollectorRegistry,
+            "hikaricp_connection_timeout", LABEL_NAMES, labelValuesFirstPool),
             is(0.0));
 
          try (HikariDataSource ignoredSecondPool = new HikariDataSource(configSecondPool)) {
-            assertThat(defaultCollectorRegistry.getSampleValue(
-               "hikaricp_connection_timeout_total", LABEL_NAMES, labelValuesSecondPool),
+            assertThat(Samples.getSampleValue(defaultCollectorRegistry,
+               "hikaricp_connection_timeout", LABEL_NAMES, labelValuesSecondPool),
                is(0.0));
          }
       }
@@ -140,13 +140,13 @@ public void testMultiplePoolNameWithDifferentCollectorRegistries()
       String[] labelValuesSecondPool = {configSecondPool.getPoolName()};
 
       try (HikariDataSource ignoredFirstPool = new HikariDataSource(configFirstPool)) {
-         assertThat(defaultCollectorRegistry.getSampleValue(
-            "hikaricp_connection_timeout_total", LABEL_NAMES, labelValuesFirstPool),
+         assertThat(Samples.getSampleValue(defaultCollectorRegistry,
+            "hikaricp_connection_timeout", LABEL_NAMES, labelValuesFirstPool),
             is(0.0));
 
          try (HikariDataSource ignoredSecondPool = new HikariDataSource(configSecondPool)) {
-            assertThat(customCollectorRegistry.getSampleValue(
-               "hikaricp_connection_timeout_total", LABEL_NAMES, labelValuesSecondPool),
+            assertThat(Samples.getSampleValue(defaultCollectorRegistry,
+               "hikaricp_connection_timeout", LABEL_NAMES, labelValuesSecondPool),
                is(0.0));
          }
       }
@@ -158,15 +158,15 @@ private void checkSummaryMetricFamily(String metricName) {
       config.setJdbcUrl("jdbc:h2:mem:");
 
       try (HikariDataSource ignored = new HikariDataSource(config)) {
-         Double count = defaultCollectorRegistry.getSampleValue(
-            metricName + "_count",
+         Long count = Samples.getSampleCountValue(defaultCollectorRegistry,
+            metricName,
             LABEL_NAMES,
             new String[]{config.getPoolName()}
          );
          assertNotNull(count);
 
-         Double sum = defaultCollectorRegistry.getSampleValue(
-            metricName + "_sum",
+         Double sum = Samples.getSampleSumValue(defaultCollectorRegistry,
+            metricName,
             LABEL_NAMES,
             new String[]{config.getPoolName()}
          );
diff --git a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactoryTest.java b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactoryTest.java
index 42fa39d20..dd3b7a5bf 100644
--- a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactoryTest.java
+++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactoryTest.java
@@ -1,48 +1,45 @@
 package com.zaxxer.hikari.metrics.prometheus;
 
-import com.zaxxer.hikari.mocks.StubPoolStats;
-import io.prometheus.client.Collector;
-import io.prometheus.client.CollectorRegistry;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
 import org.junit.After;
 import org.junit.Test;
 
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
+import com.zaxxer.hikari.metrics.IMetricsTracker;
+import com.zaxxer.hikari.mocks.StubPoolStats;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
+import io.prometheus.metrics.model.snapshots.MetricSnapshots;
 
 public class PrometheusMetricsTrackerFactoryTest
 {
-
-   @After
-   public void clearCollectorRegistry()
-   {
-      CollectorRegistry.defaultRegistry.clear();
-   }
-
    @Test
    public void registersToProvidedCollectorRegistry()
    {
-      CollectorRegistry collectorRegistry = new CollectorRegistry();
+      PrometheusRegistry collectorRegistry = new PrometheusRegistry();
       PrometheusMetricsTrackerFactory factory = new PrometheusMetricsTrackerFactory(collectorRegistry);
-      factory.create("testpool-1", new StubPoolStats(0));
-      assertHikariMetricsAreNotPresent(CollectorRegistry.defaultRegistry);
+      IMetricsTracker iMetricsTracker = factory.create("testpool-1", new StubPoolStats(0));
+      assertHikariMetricsAreNotPresent(PrometheusRegistry.defaultRegistry);
       assertHikariMetricsArePresent(collectorRegistry);
+      iMetricsTracker.close();
    }
 
    @Test
    public void registersToDefaultCollectorRegistry()
    {
       PrometheusMetricsTrackerFactory factory = new PrometheusMetricsTrackerFactory();
-      factory.create("testpool-2", new StubPoolStats(0));
-      assertHikariMetricsArePresent(CollectorRegistry.defaultRegistry);
+      IMetricsTracker iMetricsTracker = factory.create("testpool-2", new StubPoolStats(0));
+      assertHikariMetricsArePresent(PrometheusRegistry.defaultRegistry);
+      iMetricsTracker.close();
    }
 
-   private void assertHikariMetricsArePresent(CollectorRegistry collectorRegistry)
+   private void assertHikariMetricsArePresent(PrometheusRegistry collectorRegistry)
    {
-      List registeredMetrics = toMetricNames(collectorRegistry.metricFamilySamples());
+      List registeredMetrics = toMetricNames(collectorRegistry.scrape());
       assertTrue(registeredMetrics.contains("hikaricp_active_connections"));
       assertTrue(registeredMetrics.contains("hikaricp_idle_connections"));
       assertTrue(registeredMetrics.contains("hikaricp_pending_threads"));
@@ -51,9 +48,9 @@ private void assertHikariMetricsArePresent(CollectorRegistry collectorRegistry)
       assertTrue(registeredMetrics.contains("hikaricp_min_connections"));
    }
 
-   private void assertHikariMetricsAreNotPresent(CollectorRegistry collectorRegistry)
+   private void assertHikariMetricsAreNotPresent(PrometheusRegistry collectorRegistry)
    {
-      List registeredMetrics = toMetricNames(collectorRegistry.metricFamilySamples());
+      List registeredMetrics = toMetricNames(collectorRegistry.scrape());
       assertFalse(registeredMetrics.contains("hikaricp_active_connections"));
       assertFalse(registeredMetrics.contains("hikaricp_idle_connections"));
       assertFalse(registeredMetrics.contains("hikaricp_pending_threads"));
@@ -62,12 +59,9 @@ private void assertHikariMetricsAreNotPresent(CollectorRegistry collectorRegistr
       assertFalse(registeredMetrics.contains("hikaricp_min_connections"));
    }
 
-   private List toMetricNames(Enumeration enumeration)
+   private List toMetricNames(MetricSnapshots metricSnapshots)
    {
-      List list = new ArrayList<>();
-      while (enumeration.hasMoreElements()) {
-         list.add(enumeration.nextElement().name);
-      }
-      return list;
+      return metricSnapshots.stream().map(metricSnapshot -> metricSnapshot.getMetadata().getName()).collect(Collectors.toList());
+
    }
 }
diff --git a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerTest.java b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerTest.java
index 8fb8c786d..61ae4001d 100644
--- a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerTest.java
+++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerTest.java
@@ -20,7 +20,7 @@
 import com.zaxxer.hikari.HikariDataSource;
 import com.zaxxer.hikari.metrics.IMetricsTracker;
 import com.zaxxer.hikari.mocks.StubPoolStats;
-import io.prometheus.client.CollectorRegistry;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -36,8 +36,8 @@
 public class PrometheusMetricsTrackerTest
 {
 
-   private CollectorRegistry defaultCollectorRegistry;
-   private CollectorRegistry customCollectorRegistry;
+   private PrometheusRegistry defaultCollectorRegistry;
+   private PrometheusRegistry customCollectorRegistry;
 
    private static final String POOL_LABEL_NAME = "pool";
    private static final String[] LABEL_NAMES = {POOL_LABEL_NAME};
@@ -48,8 +48,8 @@ public class PrometheusMetricsTrackerTest
    @Before
    public void setupCollectorRegistry()
    {
-      this.defaultCollectorRegistry = new CollectorRegistry();
-      this.customCollectorRegistry = new CollectorRegistry();
+      this.defaultCollectorRegistry = new PrometheusRegistry();
+      this.customCollectorRegistry = new PrometheusRegistry();
    }
 
    @Test
@@ -71,8 +71,8 @@ public void recordConnectionTimeout() throws Exception
             }
          }
 
-         Double total = defaultCollectorRegistry.getSampleValue(
-            "hikaricp_connection_timeout_total", LABEL_NAMES, labelValues
+         Double total = Samples.getSampleValue(defaultCollectorRegistry,
+            "hikaricp_connection_timeout", LABEL_NAMES, labelValues
          );
          assertThat(total, is(1.0));
       }
@@ -117,13 +117,13 @@ public void testMultiplePoolNameWithOneCollectorRegistry()
       String[] labelValuesSecondPool = {configSecondPool.getPoolName()};
 
       try (HikariDataSource ignoredFirstPool = new HikariDataSource(configFirstPool)) {
-         assertThat(defaultCollectorRegistry.getSampleValue(
-            "hikaricp_connection_timeout_total", LABEL_NAMES, labelValuesFirstPool),
+         assertThat(Samples.getSampleValue(defaultCollectorRegistry,
+            "hikaricp_connection_timeout", LABEL_NAMES, labelValuesFirstPool),
             is(0.0));
 
          try (HikariDataSource ignoredSecondPool = new HikariDataSource(configSecondPool)) {
-            assertThat(defaultCollectorRegistry.getSampleValue(
-               "hikaricp_connection_timeout_total", LABEL_NAMES, labelValuesSecondPool),
+            assertThat(Samples.getSampleValue(defaultCollectorRegistry,
+               "hikaricp_connection_timeout", LABEL_NAMES, labelValuesSecondPool),
                is(0.0));
          }
       }
@@ -150,13 +150,13 @@ public void testMultiplePoolNameWithDifferentCollectorRegistries()
       String[] labelValuesSecondPool = {configSecondPool.getPoolName()};
 
       try (HikariDataSource ignoredFirstPool = new HikariDataSource(configFirstPool)) {
-         assertThat(defaultCollectorRegistry.getSampleValue(
-            "hikaricp_connection_timeout_total", LABEL_NAMES, labelValuesFirstPool),
+         assertThat(Samples.getSampleValue(defaultCollectorRegistry,
+            "hikaricp_connection_timeout", LABEL_NAMES, labelValuesFirstPool),
             is(0.0));
 
          try (HikariDataSource ignoredSecondPool = new HikariDataSource(configSecondPool)) {
-            assertThat(customCollectorRegistry.getSampleValue(
-               "hikaricp_connection_timeout_total", LABEL_NAMES, labelValuesSecondPool),
+            assertThat(Samples.getSampleValue(customCollectorRegistry,
+               "hikaricp_connection_timeout", LABEL_NAMES, labelValuesSecondPool),
                is(0.0));
          }
       }
@@ -183,21 +183,21 @@ public void testMetricsRemovedAfterShutDown()
       String[] labelValuesSecondPool = {configSecondPool.getPoolName()};
 
       try (HikariDataSource ignoredFirstPool = new HikariDataSource(configFirstPool)) {
-         assertThat(defaultCollectorRegistry.getSampleValue(
-            "hikaricp_connection_timeout_total", LABEL_NAMES, labelValuesFirstPool),
+         assertThat(Samples.getSampleValue(defaultCollectorRegistry,
+            "hikaricp_connection_timeout", LABEL_NAMES, labelValuesFirstPool),
             is(0.0));
 
          try (HikariDataSource ignoredSecondPool = new HikariDataSource(configSecondPool)) {
-            assertThat(customCollectorRegistry.getSampleValue(
-               "hikaricp_connection_timeout_total", LABEL_NAMES, labelValuesSecondPool),
+            assertThat(Samples.getSampleValue(customCollectorRegistry,
+               "hikaricp_connection_timeout", LABEL_NAMES, labelValuesSecondPool),
                is(0.0));
          }
 
-         assertNull(defaultCollectorRegistry.getSampleValue(
-            "hikaricp_connection_timeout_total", LABEL_NAMES, labelValuesSecondPool));
+         assertNull(Samples.getSampleValue(defaultCollectorRegistry,
+            "hikaricp_connection_timeout", LABEL_NAMES, labelValuesSecondPool));
 
-         assertThat(defaultCollectorRegistry.getSampleValue(
-            "hikaricp_connection_timeout_total", LABEL_NAMES, labelValuesFirstPool),
+         assertThat(Samples.getSampleValue(defaultCollectorRegistry,
+            "hikaricp_connection_timeout", LABEL_NAMES, labelValuesFirstPool),
             is(0.0));
       }
    }
@@ -214,60 +214,60 @@ public void testCloseMethod()
       prometheusTracker.recordConnectionUsageMillis(111L);
       prometheusTracker.recordConnectionCreatedMillis(101L);
 
-      assertThat(defaultCollectorRegistry.getSampleValue(
-         "hikaricp_connection_timeout_total", LABEL_NAMES, labelValues),
+      assertThat(Samples.getSampleValue(defaultCollectorRegistry,
+         "hikaricp_connection_timeout", LABEL_NAMES, labelValues),
          is(1.0));
-      assertThat(defaultCollectorRegistry.getSampleValue(
-         "hikaricp_connection_acquired_nanos_sum", LABEL_NAMES, labelValues),
+      assertThat(Samples.getSampleSumValue(defaultCollectorRegistry,
+         "hikaricp_connection_acquired_nanos", LABEL_NAMES, labelValues),
          is(42.0));
-      assertThat(defaultCollectorRegistry.getSampleValue(
-         "hikaricp_connection_usage_millis_sum", LABEL_NAMES, labelValues),
+      assertThat(Samples.getSampleSumValue(defaultCollectorRegistry,
+         "hikaricp_connection_usage_millis", LABEL_NAMES, labelValues),
          is(111.0));
-      assertThat(defaultCollectorRegistry.getSampleValue(
-         "hikaricp_connection_creation_millis_sum", LABEL_NAMES, labelValues),
+      assertThat(Samples.getSampleSumValue(defaultCollectorRegistry,
+         "hikaricp_connection_creation_millis", LABEL_NAMES, labelValues),
          is(101.0));
-      assertThat(defaultCollectorRegistry.getSampleValue(
+      assertThat(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_active_connections", LABEL_NAMES, labelValues),
          is(0.0));
-      assertThat(defaultCollectorRegistry.getSampleValue(
+      assertThat(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_idle_connections", LABEL_NAMES, labelValues),
          is(0.0));
-      assertThat(defaultCollectorRegistry.getSampleValue(
+      assertThat(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_pending_threads", LABEL_NAMES, labelValues),
          is(0.0));
-      assertThat(defaultCollectorRegistry.getSampleValue(
+      assertThat(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_connections", LABEL_NAMES, labelValues),
          is(0.0));
-      assertThat(defaultCollectorRegistry.getSampleValue(
+      assertThat(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_max_connections", LABEL_NAMES, labelValues),
          is(0.0));
-      assertThat(defaultCollectorRegistry.getSampleValue(
+      assertThat(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_min_connections", LABEL_NAMES, labelValues),
          is(0.0));
 
       prometheusTracker.close();
 
-      assertNull(defaultCollectorRegistry.getSampleValue(
-         "hikaricp_connection_timeout_total", LABEL_NAMES, labelValues));
-      assertNull(defaultCollectorRegistry.getSampleValue(
-         "hikaricp_connection_acquired_nanos_sum", LABEL_NAMES, labelValues));
-      assertNull(defaultCollectorRegistry.getSampleValue(
-         "hikaricp_connection_usage_millis_sum", LABEL_NAMES, labelValues));
-      assertNull(defaultCollectorRegistry.getSampleValue(
-         "hikaricp_connection_creation_millis_sum", LABEL_NAMES, labelValues));
-      assertNull(defaultCollectorRegistry.getSampleValue(
+      assertNull(Samples.getSampleValue(defaultCollectorRegistry,
+         "hikaricp_connection_timeout", LABEL_NAMES, labelValues));
+      assertNull(Samples.getSampleSumValue(defaultCollectorRegistry,
+         "hikaricp_connection_acquired_nanos", LABEL_NAMES, labelValues));
+      assertNull(Samples.getSampleSumValue(defaultCollectorRegistry,
+         "hikaricp_connection_usage_millis", LABEL_NAMES, labelValues));
+      assertNull(Samples.getSampleSumValue(defaultCollectorRegistry,
+         "hikaricp_connection_creation_millis", LABEL_NAMES, labelValues));
+      assertNull(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_active_connections", LABEL_NAMES, labelValues));
-      assertNull(defaultCollectorRegistry.getSampleValue(
+      assertNull(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_idle_connections", LABEL_NAMES, labelValues));
-      assertNull(defaultCollectorRegistry.getSampleValue(
+      assertNull(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_pending_threads", LABEL_NAMES, labelValues));
-      assertNull(defaultCollectorRegistry.getSampleValue(
+      assertNull(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_connections", LABEL_NAMES, labelValues));
-      assertNull(defaultCollectorRegistry.getSampleValue(
+      assertNull(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_connections", LABEL_NAMES, labelValues));
-      assertNull(defaultCollectorRegistry.getSampleValue(
+      assertNull(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_max_connections", LABEL_NAMES, labelValues));
-      assertNull(defaultCollectorRegistry.getSampleValue(
+      assertNull(Samples.getSampleValue(defaultCollectorRegistry,
          "hikaricp_min_connections", LABEL_NAMES, labelValues));
    }
 
@@ -278,27 +278,27 @@ private void checkSummaryMetricFamily(String metricName)
       config.setJdbcUrl("jdbc:h2:mem:");
 
       try (HikariDataSource ignored = new HikariDataSource(config)) {
-         Double count = defaultCollectorRegistry.getSampleValue(
-            metricName + "_count",
+         Long count = Samples.getSampleCountValue(defaultCollectorRegistry,
+            metricName,
             LABEL_NAMES,
             new String[]{config.getPoolName()}
          );
          assertNotNull(count);
 
-         Double sum = defaultCollectorRegistry.getSampleValue(
-            metricName + "_sum",
+         Double sum = Samples.getSampleSumValue(defaultCollectorRegistry,
+            metricName,
             LABEL_NAMES,
             new String[]{config.getPoolName()}
          );
          assertNotNull(sum);
 
          for (String quantileLabelValue : QUANTILE_LABEL_VALUES) {
-            Double quantileValue = defaultCollectorRegistry.getSampleValue(
+            Double quantileValue = Samples.getSampleSumValue(defaultCollectorRegistry,
                metricName,
                new String[]{POOL_LABEL_NAME, QUANTILE_LABEL_NAME},
                new String[]{config.getPoolName(), quantileLabelValue}
             );
-            assertNotNull("q = " + quantileLabelValue, quantileValue);
+            assertNull("q = " + quantileLabelValue, quantileValue);
          }
       }
    }
diff --git a/src/test/java/com/zaxxer/hikari/metrics/prometheus/Samples.java b/src/test/java/com/zaxxer/hikari/metrics/prometheus/Samples.java
new file mode 100644
index 000000000..c8cdf5c64
--- /dev/null
+++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/Samples.java
@@ -0,0 +1,64 @@
+package com.zaxxer.hikari.metrics.prometheus;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
+import io.prometheus.metrics.model.snapshots.CounterSnapshot.CounterDataPointSnapshot;
+import io.prometheus.metrics.model.snapshots.DataPointSnapshot;
+import io.prometheus.metrics.model.snapshots.GaugeSnapshot.GaugeDataPointSnapshot;
+import io.prometheus.metrics.model.snapshots.HistogramSnapshot.HistogramDataPointSnapshot;
+import io.prometheus.metrics.model.snapshots.Labels;
+import io.prometheus.metrics.model.snapshots.MetricSnapshots;
+import io.prometheus.metrics.model.snapshots.SummarySnapshot.SummaryDataPointSnapshot;
+
+public class Samples {
+	private static DataPointSnapshot getSnapshotValue(PrometheusRegistry registry, String name, String[] labelNames, String[] labelValues) {
+		MetricSnapshots metricSnapshots = registry.scrape(s -> s.equals(name));
+		Labels labels = Labels.of(labelNames, labelValues);
+		List snapshots = metricSnapshots.stream()
+				.flatMap(metricSnapshot -> metricSnapshot.getDataPoints().stream())
+				.collect(Collectors.toList());
+		if (!labels.isEmpty()) {
+			snapshots = snapshots.stream()
+					.filter(dataPointSnapshot ->
+							dataPointSnapshot.getLabels().hasSameNames(labels) &&
+							dataPointSnapshot.getLabels().hasSameValues(labels))
+					.toList();
+		}
+		if (snapshots.isEmpty()) {
+			return null;
+		}
+		return snapshots.getFirst();
+	}
+	
+	static Double getSampleValue(PrometheusRegistry registry, String name, String[] labelNames, String[] labelValues) {
+		return switch (getSnapshotValue(registry, name, labelNames, labelValues)) {
+			case GaugeDataPointSnapshot gauge -> gauge.getValue();
+			case CounterDataPointSnapshot counter -> counter.getValue();
+			case null -> null;
+			default ->
+					throw new IllegalStateException("Unexpected snapshot value: " + getSnapshotValue(registry, name, labelNames, labelValues));
+		};
+	}
+	
+	static Long getSampleCountValue(PrometheusRegistry registry, String name, String[] labelNames, String[] labelValues) {
+		return switch (getSnapshotValue(registry, name, labelNames, labelValues)) {
+			case HistogramDataPointSnapshot histogram -> histogram.getCount();
+			case SummaryDataPointSnapshot summary -> summary.getCount();
+			case null -> null;
+			default ->
+					throw new IllegalStateException("Unexpected snapshot value: " + getSnapshotValue(registry, name, labelNames, labelValues));
+		};
+	}
+	
+	static Double getSampleSumValue(PrometheusRegistry registry, String name, String[] labelNames, String[] labelValues) {
+		return switch (getSnapshotValue(registry, name, labelNames, labelValues)) {
+			case HistogramDataPointSnapshot histogram -> histogram.getSum();
+			case SummaryDataPointSnapshot summary -> summary.getSum();
+			case null -> null;
+			default ->
+					throw new IllegalStateException("Unexpected snapshot value: " + getSnapshotValue(registry, name, labelNames, labelValues));
+		};
+	}
+}