diff --git a/build.gradle b/build.gradle index d6ebe09..744de2d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ group 'su.nlq' -version '3.5.4' +version '3.6.0' ext { - vertxVersion = '3.5.4' + vertxVersion = '3.6.0' prometheusVersion = '0.5.0' } @@ -106,5 +106,6 @@ artifacts { } signing { + required { gradle.taskGraph.hasTask("uploadArchives") } sign configurations.archives } \ No newline at end of file diff --git a/src/main/java/io/vertx/ext/prometheus/VertxPrometheusMetrics.java b/src/main/java/io/vertx/ext/prometheus/VertxPrometheusMetrics.java index 628262e..f6ca690 100644 --- a/src/main/java/io/vertx/ext/prometheus/VertxPrometheusMetrics.java +++ b/src/main/java/io/vertx/ext/prometheus/VertxPrometheusMetrics.java @@ -5,12 +5,8 @@ import io.vertx.core.Closeable; import io.vertx.core.Verticle; import io.vertx.core.Vertx; -import io.vertx.core.datagram.DatagramSocket; import io.vertx.core.datagram.DatagramSocketOptions; -import io.vertx.core.eventbus.EventBus; -import io.vertx.core.http.HttpClient; import io.vertx.core.http.HttpClientOptions; -import io.vertx.core.http.HttpServer; import io.vertx.core.http.HttpServerOptions; import io.vertx.core.metrics.impl.DummyVertxMetrics; import io.vertx.core.net.NetClientOptions; @@ -28,7 +24,6 @@ import static io.vertx.ext.prometheus.MetricsType.*; public final class VertxPrometheusMetrics extends DummyVertxMetrics { - private final @NotNull Vertx vertx; private final @NotNull VertxPrometheusOptions options; private final @NotNull VerticleMetrics verticleMetrics; private final @NotNull TimerMetrics timerMetrics; @@ -38,8 +33,7 @@ public final class VertxPrometheusMetrics extends DummyVertxMetrics { private @Nullable Closeable server; - public VertxPrometheusMetrics(@NotNull Vertx vertx, @NotNull VertxPrometheusOptions options) { - this.vertx = vertx; + public VertxPrometheusMetrics(@NotNull VertxPrometheusOptions options) { this.options = options; this.verticleMetrics = options.isEnabled(Verticles) ? new VerticlePrometheusMetrics(options.getRegistry()) : new VerticleDummyMetrics(); this.timerMetrics = options.isEnabled(Timers) ? new TimerPrometheusMetrics(options.getRegistry()) : new TimerDummyMetrics(); @@ -49,7 +43,7 @@ public VertxPrometheusMetrics(@NotNull Vertx vertx, @NotNull VertxPrometheusOpti } @Override - public void eventBusInitialized(@NotNull EventBus bus) { + public void vertxCreated(@NotNull Vertx vertx) { if (options.isEmbeddedServerEnabled()) { server = MetricsServer .create(vertx) @@ -79,61 +73,56 @@ public void timerEnded(long id, boolean cancelled) { } @Override - public @NotNull EventBusMetrics createMetrics(@NotNull EventBus eventBus) { + public @NotNull EventBusMetrics createEventBusMetrics() { return options.isEnabled(EventBus) ? new EventBusPrometheusMetrics(options.getRegistry()) - : super.createMetrics(eventBus); + : super.createEventBusMetrics(); } @Override - public @NotNull HttpServerMetrics createMetrics(@NotNull HttpServer httpServer, @NotNull SocketAddress localAddress, @NotNull HttpServerOptions httpServerOptions) { - return options.isEnabled(HTTPServer) - ? new HTTPServerPrometheusMetrics(options.getRegistry(), localAddress, gauges, counters, histograms) - : super.createMetrics(httpServer, localAddress, httpServerOptions); - } - - @Override - public @NotNull HttpClientMetrics createMetrics(@NotNull HttpClient client, @NotNull HttpClientOptions httpClientOptions) { + public @NotNull HttpClientMetrics createHttpClientMetrics(@NotNull HttpClientOptions httpClientOptions) { return options.isEnabled(HTTPClient) ? new HTTPClientPrometheusMetrics(options.getRegistry(), getLocalAddress(httpClientOptions.getLocalAddress()), gauges, counters, histograms) - : super.createMetrics(client, httpClientOptions); + : super.createHttpClientMetrics(httpClientOptions); } @Override - public @NotNull TCPMetrics createMetrics(@NotNull SocketAddress localAddress, @NotNull NetServerOptions netServerOptions) { - return options.isEnabled(NetServer) - ? new NetServerPrometheusMetrics(options.getRegistry(), localAddress, gauges, counters) - : super.createMetrics(localAddress, netServerOptions); + public @NotNull DatagramSocketMetrics createDatagramSocketMetrics(@NotNull DatagramSocketOptions datagramSocketOptions) { + return options.isEnabled(DatagramSocket) + ? new DatagramSocketPrometheusMetrics(options.getRegistry(), counters) + : super.createDatagramSocketMetrics(datagramSocketOptions); } @Override - public @NotNull TCPMetrics createMetrics(@NotNull NetClientOptions netClientOptions) { - return options.isEnabled(NetClient) - ? new NetClientPrometheusMetrics(options.getRegistry(), getLocalAddress(netClientOptions.getLocalAddress()), gauges, counters) - : super.createMetrics(netClientOptions); + public @NotNull HttpServerMetrics createHttpServerMetrics(@NotNull HttpServerOptions httpServerOptions, @NotNull SocketAddress localAddress) { + return options.isEnabled(HTTPServer) + ? new HTTPServerPrometheusMetrics(options.getRegistry(), localAddress, gauges, counters, histograms) + : super.createHttpServerMetrics(httpServerOptions, localAddress); } @Override - public @NotNull DatagramSocketMetrics createMetrics(@NotNull DatagramSocket socket, @NotNull DatagramSocketOptions datagramSocketOptions) { - return options.isEnabled(DatagramSocket) - ? new DatagramSocketPrometheusMetrics(options.getRegistry(), counters) - : super.createMetrics(socket, datagramSocketOptions); + public @NotNull PoolMetrics createPoolMetrics(@NotNull String poolType, @NotNull String poolName, int maxPoolSize) { + return options.isEnabled(Pools) + ? new PoolPrometheusMetrics(options.getRegistry(), poolType, poolName, maxPoolSize) + : super.createPoolMetrics(poolType, poolName, maxPoolSize); } @Override - public @NotNull

PoolMetrics createMetrics(@NotNull P pool, @NotNull String poolType, @NotNull String poolName, int maxPoolSize) { - return options.isEnabled(Pools) - ? new PoolPrometheusMetrics(options.getRegistry(), poolType, poolName, maxPoolSize) - : super.createMetrics(pool, poolType, poolName, maxPoolSize); + public @NotNull TCPMetrics createNetClientMetrics(@NotNull NetClientOptions netClientOptions) { + return options.isEnabled(HTTPClient) + ? new NetClientPrometheusMetrics(options.getRegistry(), getLocalAddress(netClientOptions.getLocalAddress()), gauges, counters) + : super.createNetClientMetrics(netClientOptions); } @Override - public boolean isMetricsEnabled() { - return true; + public @NotNull TCPMetrics createNetServerMetrics(@NotNull NetServerOptions netServerOptions, @NotNull SocketAddress localAddress) { + return options.isEnabled(NetServer) + ? new NetServerPrometheusMetrics(options.getRegistry(), localAddress, gauges, counters) + : super.createNetServerMetrics(netServerOptions, localAddress); } @Override - public boolean isEnabled() { + public boolean isMetricsEnabled() { return true; } diff --git a/src/main/java/io/vertx/ext/prometheus/VertxPrometheusMetricsFactory.java b/src/main/java/io/vertx/ext/prometheus/VertxPrometheusMetricsFactory.java index 636cfd2..3e6e3f9 100644 --- a/src/main/java/io/vertx/ext/prometheus/VertxPrometheusMetricsFactory.java +++ b/src/main/java/io/vertx/ext/prometheus/VertxPrometheusMetricsFactory.java @@ -1,7 +1,7 @@ package io.vertx.ext.prometheus; -import io.vertx.core.Vertx; import io.vertx.core.VertxOptions; +import io.vertx.core.json.JsonObject; import io.vertx.core.metrics.MetricsOptions; import io.vertx.core.spi.VertxMetricsFactory; import io.vertx.core.spi.metrics.VertxMetrics; @@ -9,9 +9,10 @@ public final class VertxPrometheusMetricsFactory implements VertxMetricsFactory { + @Override - public @NotNull VertxMetrics metrics(@NotNull Vertx vertx, @NotNull VertxOptions vertxOptions) { - return new VertxPrometheusMetrics(vertx, asPrometheusOptions(vertxOptions)); + public VertxMetrics metrics(@NotNull VertxOptions vertxOptions) { + return new VertxPrometheusMetrics( asPrometheusOptions(vertxOptions)); } @Override @@ -19,6 +20,11 @@ public final class VertxPrometheusMetricsFactory implements VertxMetricsFactory return new VertxPrometheusOptions(); } + @Override + public MetricsOptions newOptions(JsonObject jsonObject) { + return new VertxPrometheusOptions(jsonObject); + } + private static @NotNull VertxPrometheusOptions asPrometheusOptions(@NotNull VertxOptions vertxOptions) { final MetricsOptions metricsOptions = vertxOptions.getMetricsOptions(); return metricsOptions instanceof VertxPrometheusOptions diff --git a/src/main/java/io/vertx/ext/prometheus/metrics/HTTPServerPrometheusMetrics.java b/src/main/java/io/vertx/ext/prometheus/metrics/HTTPServerPrometheusMetrics.java index c765c93..f9a5cb2 100644 --- a/src/main/java/io/vertx/ext/prometheus/metrics/HTTPServerPrometheusMetrics.java +++ b/src/main/java/io/vertx/ext/prometheus/metrics/HTTPServerPrometheusMetrics.java @@ -48,13 +48,7 @@ public void responseEnd(@NotNull HTTPRequestMetrics.Metric metric, @NotNull Http } @Override - public @Nullable Void upgrade(@NotNull HTTPRequestMetrics.Metric metric, @NotNull ServerWebSocket serverWebSocket) { - requests.upgrade(metric); - return null; - } - - @Override - public @Nullable Void connected(@Nullable Void metric, @NotNull ServerWebSocket serverWebSocket) { + public @Nullable Void connected(@Nullable Void metric, @Nullable HTTPRequestMetrics.Metric requestMetric, ServerWebSocket serverWebSocket) { websockets.increment(); return metric; } diff --git a/src/main/java/io/vertx/ext/prometheus/metrics/PrometheusMetrics.java b/src/main/java/io/vertx/ext/prometheus/metrics/PrometheusMetrics.java index cd258a1..7dfd4c0 100644 --- a/src/main/java/io/vertx/ext/prometheus/metrics/PrometheusMetrics.java +++ b/src/main/java/io/vertx/ext/prometheus/metrics/PrometheusMetrics.java @@ -16,11 +16,6 @@ protected PrometheusMetrics(@NotNull CollectorRegistry registry) { this.registry = registry; } - @Override - public final boolean isEnabled() { - return !collectors.isEmpty(); - } - @Override public final void close() { collectors.forEach(registry::unregister); diff --git a/src/main/java/io/vertx/ext/prometheus/server/MetricsServer.java b/src/main/java/io/vertx/ext/prometheus/server/MetricsServer.java index 1d455bb..0c4b27b 100644 --- a/src/main/java/io/vertx/ext/prometheus/server/MetricsServer.java +++ b/src/main/java/io/vertx/ext/prometheus/server/MetricsServer.java @@ -27,7 +27,7 @@ public enum MetricsServer { return (registry, format) -> { router.route(METRICS_PATH).handler(format.handler(registry)); return address -> { - server.requestHandler(router::accept).listen(address.port(), address.host()); + server.requestHandler(router).listen(address.port(), address.host()); log.info("Prometheus metrics server started at " + address); return server::close; }; diff --git a/src/test/java/io/vertx/ext/prometheus/ExternalServerTest.java b/src/test/java/io/vertx/ext/prometheus/ExternalServerTest.java index 480c4e2..e66d5fd 100644 --- a/src/test/java/io/vertx/ext/prometheus/ExternalServerTest.java +++ b/src/test/java/io/vertx/ext/prometheus/ExternalServerTest.java @@ -10,6 +10,10 @@ public final class ExternalServerTest extends PrometheusMetricsTestCase { + public ExternalServerTest() { + super(o -> o.setEmbeddedServerEnabled(false)); + } + @Test public void test() { MetricsServer