Skip to content
This repository has been archived by the owner on Mar 23, 2019. It is now read-only.

Commit

Permalink
Support Vertx 3.6.0 (#23)
Browse files Browse the repository at this point in the history
* Allow for local build and fix External Server Test
* Update to 3.6.0 APIs
* Bump to version 3.6.0
  • Loading branch information
rmtmckenzie authored and nolequen committed Dec 2, 2018
1 parent b551649 commit c7bf03b
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 56 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}

Expand Down Expand Up @@ -106,5 +106,6 @@ artifacts {
}

signing {
required { gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
65 changes: 27 additions & 38 deletions src/main/java/io/vertx/ext/prometheus/VertxPrometheusMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -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 <P> 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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
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;
import org.jetbrains.annotations.NotNull;

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
public @NotNull MetricsOptions newOptions() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/io/vertx/ext/prometheus/ExternalServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

public final class ExternalServerTest extends PrometheusMetricsTestCase {

public ExternalServerTest() {
super(o -> o.setEmbeddedServerEnabled(false));
}

@Test
public void test() {
MetricsServer
Expand Down

0 comments on commit c7bf03b

Please sign in to comment.