Skip to content

Commit

Permalink
Update to vertx builder changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Nov 20, 2023
1 parent 0c94b20 commit 91104e8
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 126 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<stack.version>5.0.0-SNAPSHOT</stack.version>
<doc.skip>true</doc.skip>
<jar.manifest>${project.basedir}/src/main/resources/META-INF/MANIFEST.MF</jar.manifest>
<testcontainers.version>1.15.2</testcontainers.version>
<testcontainers.version>1.17.6</testcontainers.version>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Scope;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import io.vertx.core.spi.tracing.VertxTracer;
Expand All @@ -26,16 +25,13 @@ public class OpenTelemetryOptions extends TracingOptions {

public OpenTelemetryOptions(OpenTelemetry openTelemetry) {
this.openTelemetry = openTelemetry;
this.setFactory(OpenTelemetryTracingFactory.INSTANCE);
}

public OpenTelemetryOptions() {
this.setFactory(OpenTelemetryTracingFactory.INSTANCE);
}

public OpenTelemetryOptions(JsonObject json) {
super(json);
this.setFactory(OpenTelemetryTracingFactory.INSTANCE);
}

VertxTracer<Span, Span> buildTracer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.vertx.core.tracing.TracingPolicy;
import io.vertx.docgen.Source;
import io.vertx.tracing.opentracing.OpenTracingOptions;
import io.vertx.tracing.opentracing.OpenTracingTracer;
import io.vertx.tracing.opentracing.OpenTracingUtil;

@Source
Expand All @@ -26,11 +27,10 @@ public void ex1() {
}

public void ex2(Tracer tracer) {
Vertx vertx = Vertx.vertx(new VertxOptions()
.setTracingOptions(
new OpenTracingOptions(tracer)
)
);
Vertx vertx = Vertx
.builder()
.withTracer(o -> new OpenTracingTracer(false, tracer))
.build();
}

public void ex3(Vertx vertx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,26 @@
*/
package io.vertx.tracing.opentracing;

import io.opentracing.Tracer;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import io.vertx.core.tracing.TracingOptions;

@DataObject
public class OpenTracingOptions extends TracingOptions {

private Tracer tracer;

public OpenTracingOptions() {
this.setFactory(OpenTracingTracerFactory.INSTANCE);
}

public OpenTracingOptions(Tracer tracer) {
this.tracer = tracer;
this.setFactory(OpenTracingTracerFactory.INSTANCE);
}

public OpenTracingOptions(OpenTracingOptions other) {
tracer = other.tracer;
this.setFactory(OpenTracingTracerFactory.INSTANCE);
super(other);
}

public OpenTracingOptions(JsonObject json) {
super(json);
this.setFactory(OpenTracingTracerFactory.INSTANCE);
}

@Override
public OpenTracingOptions copy() {
return new OpenTracingOptions(this);
}

// Visible for testing
Tracer getTracer() {
return tracer;
}

io.vertx.core.spi.tracing.VertxTracer<?, ?> buildTracer() {
if (tracer != null) {
return new OpenTracingTracer(false, tracer);
} else {
return new OpenTracingTracer(true, OpenTracingTracer.createDefaultTracer());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,31 @@
*/
package io.vertx.tracing.opentracing;

import io.opentracing.Tracer;
import io.vertx.core.json.JsonObject;
import io.vertx.core.spi.VertxTracerFactory;
import io.vertx.core.spi.tracing.VertxTracer;
import io.vertx.core.tracing.TracingOptions;

public class OpenTracingTracerFactory implements VertxTracerFactory {

static final OpenTracingTracerFactory INSTANCE = new OpenTracingTracerFactory();
private final Tracer tracer;

public OpenTracingTracerFactory() {
this(null);
}

public OpenTracingTracerFactory(Tracer tracer) {
this.tracer = tracer;
}

@Override
public VertxTracer tracer(TracingOptions options) {
OpenTracingOptions openTracingOptions;
if (options instanceof OpenTracingOptions) {
openTracingOptions = (OpenTracingOptions) options;
if (tracer != null) {
return new OpenTracingTracer(false, tracer);
} else {
openTracingOptions = new OpenTracingOptions(options.toJson());
return new OpenTracingTracer(true, OpenTracingTracer.createDefaultTracer());
}
return openTracingOptions.buildTracer();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class EventBusTest {
@Before
public void before() {
tracer = new MockTracer();
vertx = Vertx.vertx(new VertxOptions().setTracingOptions(new OpenTracingOptions(tracer)));
vertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build();
client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class HttpTest {
@Before
public void before() {
tracer = new MockTracer();
vertx = Vertx.vertx(new VertxOptions().setTracingOptions(new OpenTracingOptions(tracer)));
vertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build();
}

@After
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.tracing.TracingOptions;
import io.vertx.core.tracing.TracingPolicy;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
Expand All @@ -47,7 +48,7 @@ public class OpenTracingTest {
@Before
public void before() {
tracer = new MockTracer();
vertx = Vertx.vertx(new VertxOptions().setTracingOptions(new OpenTracingOptions(tracer)));
vertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build();
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class OpenTracingUtilTest {
@Before
public void before() {
tracer = new MockTracer();
vertx = Vertx.vertx(new VertxOptions().setTracingOptions(new OpenTracingOptions(tracer)));
vertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build();
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void stopDB() {
@Before
public void before() {
tracer = new MockTracer();
vertx = Vertx.vertx(new VertxOptions().setTracingOptions(new OpenTracingOptions(tracer)));
vertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build();
pool = PgBuilder.pool().connectingTo(connectOptions).using(vertx).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
import io.vertx.tracing.opentracing.OpenTracingOptions;
import io.vertx.tracing.opentracing.OpenTracingTracerFactory;
import io.vertx.tracing.opentracing.it.jaegercontainer.JaegerContainerAllIn;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -50,10 +51,7 @@ public static void deploy(VertxTestContext context) {
tracer = JAEGER_ALL_IN_ONE.createTracer(JAEGER_SERVICE_NAME);
deployCheck.flag();

tracedVertx = Vertx.vertx(
new VertxOptions().setTracingOptions(
new OpenTracingOptions(tracer))
);
tracedVertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build();
HttpClient client = tracedVertx.createHttpClient();
tracedVertx.deployVerticle(ServerVerticle.class.getName()).onComplete(context.succeeding(id -> {
client.request(HttpMethod.GET, 8080,"localhost","/health")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
import io.vertx.tracing.opentracing.OpenTracingOptions;
import io.vertx.tracing.opentracing.OpenTracingTracerFactory;
import io.vertx.tracing.opentracing.OpenTracingUtil;
import io.vertx.tracing.opentracing.it.jaegercontainer.JaegerContainerAllIn;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -58,10 +59,7 @@ public static void deploy(VertxTestContext context) {
JAEGER_ALL_IN_ONE.start();
tracer = JAEGER_ALL_IN_ONE.createTracer(JAEGER_SERVICE_NAME);
deployCheck.flag();
tracedVertx = Vertx.vertx(
new VertxOptions().setTracingOptions(
new OpenTracingOptions(tracer))
);
tracedVertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build();
HttpClient client = tracedVertx.createHttpClient();
tracedVertx.deployVerticle(ServerVerticle.class.getName()).onComplete(context.succeeding(id -> {
client.request(HttpMethod.GET, 8080,"localhost","/health")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class VertxSender extends Sender {
public VertxSender(HttpSenderOptions options) {
this.options = new HttpSenderOptions(options);
this.endpoint = options.getSenderEndpoint();
this.vertx = Vertx.vertx(new VertxOptions().setTracingOptions(new TracingOptions().setFactory(VertxTracerFactory.NOOP)));
this.vertx = Vertx.builder().withTracer(VertxTracerFactory.NOOP).build();
this.client = vertx.createHttpClient(options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ public class ZipkinTracingOptions extends TracingOptions {

public ZipkinTracingOptions(HttpTracing httpTracing) {
this.httpTracing = httpTracing;
this.setFactory(ZipkinTracerFactory.INSTANCE);
}

public ZipkinTracingOptions(Tracing tracing) {
this.httpTracing = HttpTracing.newBuilder(tracing).build();
this.setFactory(ZipkinTracerFactory.INSTANCE);
}

public ZipkinTracingOptions() {
this.setFactory(ZipkinTracerFactory.INSTANCE);
}

public ZipkinTracingOptions(ZipkinTracingOptions other) {
Expand All @@ -52,13 +49,11 @@ public ZipkinTracingOptions(ZipkinTracingOptions other) {
this.supportsJoin = other.supportsJoin;
this.senderOptions = other.senderOptions == null ? null : new HttpSenderOptions(other.senderOptions);
this.httpTracing = other.httpTracing == null ? null : other.httpTracing.toBuilder().build();
this.setFactory(ZipkinTracerFactory.INSTANCE);
}

public ZipkinTracingOptions(JsonObject json) {
super(json);
ZipkinTracingOptionsConverter.fromJson(json, this);
this.setFactory(ZipkinTracerFactory.INSTANCE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,4 @@ public void testBuildFromJsonOptions() {
VertxSender sender = tracer.sender();
assertEquals(senderOptions.toJson(), sender.options().toJson());
}

@Test
public void testDefaultFactory() {
TracingOptions options = new ZipkinTracingOptions();
assertNotNull(options.getFactory());
assertEquals(ZipkinTracerFactory.INSTANCE, options.getFactory());
}

@Test
public void testFactory() {
TracingOptions options = new ZipkinTracingOptions().setFactory(VertxTracerFactory.NOOP);
assertNotNull(options.getFactory());
assertNotEquals(ZipkinTracerFactory.INSTANCE, options.getFactory());
assertEquals(VertxTracerFactory.NOOP, options.getFactory());
}
}

0 comments on commit 91104e8

Please sign in to comment.