Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Quarkus 2.0.0.Final #1490

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.opentracing.log.Fields;
import io.opentracing.propagation.Format.Builtin;
import io.opentracing.propagation.TextMap;
import io.opentracing.propagation.TextMapInjectAdapter;
import io.opentracing.propagation.TextMapAdapter;
import io.opentracing.tag.Tags;
import io.opentracing.util.GlobalTracer;
import java.io.IOException;
Expand Down Expand Up @@ -104,16 +104,14 @@ private static void addTracing(HttpClient httpClient) {
context -> {
Span span = tracer.activeSpan();
if (span != null) {
Scope scope = tracer.buildSpan("Nessie-HTTP").startActive(true);
Span inner = tracer.buildSpan("Nessie-HTTP").start();
Scope scope = tracer.activateSpan(inner);
context.addResponseCallback(
(responseContext, exception) -> {
if (responseContext != null) {
try {
scope
.span()
.setTag(
"http.status_code",
responseContext.getResponseCode().getCode());
inner.setTag(
"http.status_code", responseContext.getResponseCode().getCode());
} catch (IOException e) {
// There's not much we can (and probably should) do here.
}
Expand All @@ -122,19 +120,18 @@ private static void addTracing(HttpClient httpClient) {
Map<String, String> log = new HashMap<>();
log.put(Fields.EVENT, Tags.ERROR.getKey());
log.put(Fields.ERROR_OBJECT, exception.toString());
Tags.ERROR.set(scope.span().log(log), true);
Tags.ERROR.set(inner.log(log), true);
}
scope.close();
});

scope
.span()
inner
.setTag("http.uri", context.getUri().toString())
.setTag("http.method", context.getMethod().name());

HashMap<String, String> headerMap = new HashMap<>();
TextMap httpHeadersCarrier = new TextMapInjectAdapter(headerMap);
tracer.inject(scope.span().context(), Builtin.HTTP_HEADERS, httpHeadersCarrier);
TextMap httpHeadersCarrier = new TextMapAdapter(headerMap);
tracer.inject(inner.context(), Builtin.HTTP_HEADERS, httpHeadersCarrier);
headerMap.forEach(context::putHeader);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ void testTracing() throws Exception {
try (TestServer server = new TestServer(handlerForHeaderTest("Uber-trace-id", traceId))) {
NessieClient client =
NessieClient.builder().withUri(server.getUri()).withTracing(true).build();
try (Scope ignore = GlobalTracer.get().buildSpan("testOpenTracing").startActive(true)) {
try (Scope ignore =
GlobalTracer.get()
.activateSpan(GlobalTracer.get().buildSpan("testOpenTracing").start())) {
client.getConfigApi().getConfig();
}
}
Expand All @@ -96,7 +98,9 @@ void testTracingNotEnabled() throws Exception {
try (TestServer server = new TestServer(handlerForHeaderTest("Uber-trace-id", traceId))) {
NessieClient client =
NessieClient.builder().withUri(server.getUri()).withTracing(false).build();
try (Scope ignore = GlobalTracer.get().buildSpan("testOpenTracing").startActive(true)) {
try (Scope ignore =
GlobalTracer.get()
.activateSpan(GlobalTracer.get().buildSpan("testOpenTracing").start())) {
client.getConfigApi().getConfig();
}
}
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@
<junit.version>5.7.2</junit.version>
<logback.version>1.2.3</logback.version>
<mockito.version>3.11.2</mockito.version>
<openapi.version>1.1.2</openapi.version>
<openapi.version>2.0</openapi.version>
<prometheus.version>0.9.0</prometheus.version>
<protobuf.version>3.17.3</protobuf.version>
<quarkus.version>1.13.7.Final</quarkus.version>
<quarkus.version>2.0.0.Final</quarkus.version>
<reactor.version>2020.0.8</reactor.version>
<scala2.12.version>2.12.13</scala2.12.version>
<scala2.13.version>2.13.6</scala2.13.version>
Expand Down
8 changes: 8 additions & 0 deletions servers/quarkus-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jgit</artifactId>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
Expand Down Expand Up @@ -93,6 +97,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-apache-httpclient</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.projectnessie.quarkus.gradle;

import static io.quarkus.bootstrap.resolver.maven.DeploymentInjectingDependencyVisitor.toArtifact;
import static io.quarkus.bootstrap.util.DependencyNodeUtils.toArtifact;
import static org.projectnessie.quarkus.gradle.QuarkusAppPlugin.APP_CONFIG_NAME;
import static org.projectnessie.quarkus.gradle.QuarkusAppPlugin.LAUNCH_CONFIG_NAME;
import static org.projectnessie.quarkus.gradle.QuarkusAppPlugin.RUNTIME_CONFIG_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import org.eclipse.microprofile.config.spi.ConfigSource;

/** A config source to override default application when using apprunner. */
Expand All @@ -35,6 +37,11 @@ public Map<String, String> getProperties() {
return map;
}

@Override
public Set<String> getPropertyNames() {
return properties.keySet().stream().map(String.class::cast).collect(Collectors.toSet());
}

@Override
public String getValue(String propertyName) {
Object obj = properties.get(propertyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.projectnessie.versioned;

import com.google.common.collect.ImmutableMap;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.log.Fields;
import io.opentracing.tag.Tags;
import java.util.Collection;
Expand All @@ -39,17 +39,14 @@ public static int safeSize(Collection<?> collection) {
/**
* Set {@link Tags#ERROR} with {@link Fields#EVENT} + {@link Fields#ERROR_OBJECT}.
*
* @param scope trace-scope
* @param span trace-span
* @param e exception to trace
* @return returns {@code e}
*/
public static RuntimeException traceError(Scope scope, RuntimeException e) {
public static RuntimeException traceError(Span span, RuntimeException e) {
Tags.ERROR.set(
scope
.span()
.log(
ImmutableMap.of(
Fields.EVENT, Tags.ERROR.getKey(), Fields.ERROR_OBJECT, e.toString())),
span.log(
ImmutableMap.of(Fields.EVENT, Tags.ERROR.getKey(), Fields.ERROR_OBJECT, e.toString())),
true);
return e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.common.annotations.VisibleForTesting;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.Tracer.SpanBuilder;
import io.opentracing.util.GlobalTracer;
Expand Down Expand Up @@ -200,13 +201,18 @@ public Collector collectGarbage() {
return call("CollectGarbage", b -> {}, delegate::collectGarbage);
}

private Scope createActiveScope(String name, Consumer<SpanBuilder> spanBuilder) {
private Span createSpan(String name, Consumer<SpanBuilder> spanBuilder) {
Tracer tracer = GlobalTracer.get();
String spanName = makeSpanName(name);
SpanBuilder builder =
tracer.buildSpan(spanName).asChildOf(tracer.activeSpan()).withTag(TAG_OPERATION, name);
spanBuilder.accept(builder);
return builder.startActive(true);
return builder.start();
}

private Scope activeScope(Span span) {
Tracer tracer = GlobalTracer.get();
return tracer.activateSpan(span);
}

@VisibleForTesting
Expand All @@ -216,7 +222,8 @@ static String makeSpanName(String name) {

private <R> Stream<R> callStream(
String spanName, Consumer<SpanBuilder> spanBuilder, Invoker<Stream<R>> invoker) {
Scope scope = createActiveScope(spanName, spanBuilder);
Span span = createSpan(spanName, spanBuilder);
Scope scope = activeScope(span);
Stream<R> result = null;
try {
result = invoker.handle().onClose(scope::close);
Expand All @@ -225,7 +232,7 @@ private <R> Stream<R> callStream(
// IllegalArgumentException is a special kind of exception that indicates a user-error.
throw e;
} catch (RuntimeException e) {
throw traceError(scope, e);
throw traceError(span, e);
} finally {
// See below (callStreamWithOneException)
if (result == null) {
Expand All @@ -239,7 +246,8 @@ private <R, E1 extends VersionStoreException> Stream<R> callStreamWithOneExcepti
Consumer<SpanBuilder> spanBuilder,
InvokerWithOneException<Stream<R>, E1> invoker)
throws E1 {
Scope scope = createActiveScope(spanName, spanBuilder);
Span span = createSpan(spanName, spanBuilder);
Scope scope = activeScope(span);
Stream<R> result = null;
try {
result = invoker.handle().onClose(scope::close);
Expand All @@ -248,7 +256,7 @@ private <R, E1 extends VersionStoreException> Stream<R> callStreamWithOneExcepti
// IllegalArgumentException is a special kind of exception that indicates a user-error.
throw e;
} catch (RuntimeException e) {
throw traceError(scope, e);
throw traceError(span, e);
} finally {
// We cannot `catch (E1 e)`, so assume that the delegate threw an exception, when result==null
// and then close the trace-scope.
Expand All @@ -259,29 +267,31 @@ private <R, E1 extends VersionStoreException> Stream<R> callStreamWithOneExcepti
}

private <R> R call(String spanName, Consumer<SpanBuilder> spanBuilder, Invoker<R> invoker) {
try (Scope scope = createActiveScope(spanName, spanBuilder)) {
Span span = createSpan(spanName, spanBuilder);
try (Scope scope = activeScope(span)) {
try {
return invoker.handle();
} catch (IllegalArgumentException e) {
// IllegalArgumentException is a special kind of exception that indicates a user-error.
throw e;
} catch (RuntimeException e) {
throw traceError(scope, e);
throw traceError(span, e);
}
}
}

private <R, E1 extends VersionStoreException> R callWithOneException(
String spanName, Consumer<SpanBuilder> spanBuilder, InvokerWithOneException<R, E1> invoker)
throws E1 {
try (Scope scope = createActiveScope(spanName, spanBuilder)) {
Span span = createSpan(spanName, spanBuilder);
try (Scope scope = activeScope(span)) {
try {
return invoker.handle();
} catch (IllegalArgumentException e) {
// IllegalArgumentException is a special kind of exception that indicates a user-error.
throw e;
} catch (RuntimeException e) {
throw traceError(scope, e);
throw traceError(span, e);
}
}
}
Expand All @@ -292,14 +302,15 @@ void callWithTwoExceptions(
Consumer<SpanBuilder> spanBuilder,
InvokerWithTwoExceptions<E1, E2> invoker)
throws E1, E2 {
try (Scope scope = createActiveScope(spanName, spanBuilder)) {
Span span = createSpan(spanName, spanBuilder);
try (Scope scope = activeScope(span)) {
try {
invoker.handle();
} catch (IllegalArgumentException e) {
// IllegalArgumentException is a special kind of exception that indicates a user-error.
throw e;
} catch (RuntimeException e) {
throw traceError(scope, e);
throw traceError(span, e);
}
}
}
Expand All @@ -310,14 +321,15 @@ R callWithTwoExceptions(
Consumer<SpanBuilder> spanBuilder,
InvokerWithTwoExceptionsR<R, E1, E2> invoker)
throws E1, E2 {
try (Scope scope = createActiveScope(spanName, spanBuilder)) {
Span span = createSpan(spanName, spanBuilder);
try (Scope scope = activeScope(span)) {
try {
return invoker.handle();
} catch (IllegalArgumentException e) {
// IllegalArgumentException is a special kind of exception that indicates a user-error.
throw e;
} catch (RuntimeException e) {
throw traceError(scope, e);
throw traceError(span, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
import io.opentracing.tag.Tag;
import io.opentracing.util.GlobalTracer;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
Expand Down Expand Up @@ -87,6 +88,15 @@ public Span activeSpan() {
return activeSpan;
}

@Override
public Scope activateSpan(Span span) {
activeSpan = (TestSpan) span;
return () -> {
assertFalse(closed);
closed = true;
};
}

@Override
public SpanBuilder buildSpan(String operationName) {
opName = operationName;
Expand All @@ -113,21 +123,8 @@ public SpanBuilder withTag(String key, Number value) {
}

@Override
public Scope startActive(boolean finishSpanOnClose) {
activeSpan = new TestSpan(tags);

return new Scope() {
@Override
public void close() {
assertFalse(closed);
closed = true;
}

@Override
public Span span() {
return activeSpan;
}
};
public <T> SpanBuilder withTag(Tag<T> tag, T t) {
throw new UnsupportedOperationException();
}

@Override
Expand Down Expand Up @@ -158,14 +155,10 @@ public SpanBuilder withStartTimestamp(long microseconds) {
throw new UnsupportedOperationException();
}

@Override
public Span startManual() {
throw new UnsupportedOperationException();
}

@Override
public Span start() {
throw new UnsupportedOperationException();
activeSpan = new TestSpan(tags);
return activeSpan;
}
};
}
Expand All @@ -180,6 +173,9 @@ public <C> SpanContext extract(Format<C> format, C carrier) {
throw new UnsupportedOperationException();
}

@Override
public void close() {}

public class TestSpan implements Span {

private final Map<String, Object> tags = new HashMap<>();
Expand Down Expand Up @@ -220,6 +216,11 @@ public Span setTag(String key, Number value) {
return this;
}

@Override
public <T> Span setTag(Tag<T> tag, T t) {
throw new UnsupportedOperationException();
}

@Override
public Span log(Map<String, ?> fields) {
logs.add(fields);
Expand Down
Loading