diff --git a/pom.xml b/pom.xml index bfd596d66..27bf7318c 100644 --- a/pom.xml +++ b/pom.xml @@ -19,8 +19,8 @@ 0.11.4.1 3.0.1 3.2.5 - 1.5.10 - 0.9.0 + 1.13.2 + 1.3.1 3.7.7 4.13.5 2.5.4 @@ -199,8 +199,8 @@ io.prometheus - simpleclient - ${simpleclient.version} + prometheus-metrics-core + ${prometheus-metrics.version} provided true 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..c71c12380 100644 --- a/src/main/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollector.java +++ b/src/main/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollector.java @@ -17,27 +17,25 @@ package com.zaxxer.hikari.metrics.prometheus; import com.zaxxer.hikari.metrics.PoolStats; -import io.prometheus.client.Collector; -import io.prometheus.client.GaugeMetricFamily; +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; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; -class HikariCPCollector extends Collector +class HikariCPCollector implements MultiCollector { - private static final List LABEL_NAMES = Collections.singletonList("pool"); 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 +48,7 @@ public List collect() PoolStats::getMaxConnections), createGauge("hikaricp_min_connections", "Min connections", PoolStats::getMinConnections) - ); + )); } void add(String name, PoolStats poolStats) @@ -63,14 +61,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..53bce9271 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() + private static final Counter CONNECTION_TIMEOUT_COUNTER = Counter.builder() .name("hikaricp_connection_timeout_total") .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..c94139acd 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()
+   private final static Counter CONNECTION_TIMEOUT_COUNTER = Counter.builder()
       .name("hikaricp_connection_timeout_total")
       .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 dd7142a69..880861fed 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -5,11 +5,12 @@
    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 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..4ee258845 100644
--- a/src/test/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollectorTest.java
+++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollectorTest.java
@@ -26,7 +26,9 @@
 import java.util.List;
 
 import com.zaxxer.hikari.metrics.PoolStats;
-import io.prometheus.client.Collector;
+import io.prometheus.metrics.model.registry.MultiCollector;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
+import io.prometheus.metrics.model.snapshots.MetricSnapshots;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -34,17 +36,15 @@
 import com.zaxxer.hikari.HikariDataSource;
 import com.zaxxer.hikari.mocks.StubConnection;
 
-import io.prometheus.client.CollectorRegistry;
-
 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(metricFamilySamples -> metricFamilySamples.type == Collector.Type.GAUGE).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));
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..358d537f2 100644
--- a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerFactoryTest.java
+++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerFactoryTest.java
@@ -3,12 +3,16 @@
 import com.zaxxer.hikari.metrics.PoolStats;
 import io.prometheus.client.Collector;
 import io.prometheus.client.CollectorRegistry;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
+import io.prometheus.metrics.model.snapshots.MetricSnapshot;
+import io.prometheus.metrics.model.snapshots.MetricSnapshots;
 import org.junit.After;
 import org.junit.Test;
 
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -17,11 +21,11 @@ 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);
+      assertHikariMetricsAreNotPresent(PrometheusRegistry.defaultRegistry);
       assertHikariMetricsArePresent(collectorRegistry);
    }
 
@@ -29,16 +33,16 @@ public void registersToProvidedCollectorRegistry() {
    public void registersToDefaultCollectorRegistry() {
       PrometheusHistogramMetricsTrackerFactory factory = new PrometheusHistogramMetricsTrackerFactory();
       factory.create("testpool-2", poolStats());
-      assertHikariMetricsArePresent(CollectorRegistry.defaultRegistry);
+      assertHikariMetricsArePresent(PrometheusRegistry.defaultRegistry);
    }
 
    @After
    public void clearCollectorRegistry(){
-      CollectorRegistry.defaultRegistry.clear();
+//      PrometheusRegistry.defaultRegistry.clear();
    }
 
-   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 +51,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 +61,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..0732a2521 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
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..e3e15cb20 100644
--- a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactoryTest.java
+++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactoryTest.java
@@ -3,12 +3,16 @@
 import com.zaxxer.hikari.mocks.StubPoolStats;
 import io.prometheus.client.Collector;
 import io.prometheus.client.CollectorRegistry;
+import io.prometheus.metrics.model.registry.PrometheusRegistry;
+import io.prometheus.metrics.model.snapshots.MetricSnapshot;
+import io.prometheus.metrics.model.snapshots.MetricSnapshots;
 import org.junit.After;
 import org.junit.Test;
 
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -19,16 +23,16 @@ public class PrometheusMetricsTrackerFactoryTest
    @After
    public void clearCollectorRegistry()
    {
-      CollectorRegistry.defaultRegistry.clear();
+//      PrometheusRegistry.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);
+      assertHikariMetricsAreNotPresent(PrometheusRegistry.defaultRegistry);
       assertHikariMetricsArePresent(collectorRegistry);
    }
 
@@ -37,12 +41,12 @@ public void registersToDefaultCollectorRegistry()
    {
       PrometheusMetricsTrackerFactory factory = new PrometheusMetricsTrackerFactory();
       factory.create("testpool-2", new StubPoolStats(0));
-      assertHikariMetricsArePresent(CollectorRegistry.defaultRegistry);
+      assertHikariMetricsArePresent(PrometheusRegistry.defaultRegistry);
    }
 
-   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 +55,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 +66,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..de5fcca35 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