From dc4165ffe38d3b68827c6e0a42156a34a30c4a87 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 30 Aug 2019 15:24:41 +0200 Subject: [PATCH] Not fails the context startup when web is disabled; fixes gh-1435 --- pom.xml | 5 ++ spring-cloud-sleuth-core/pom.xml | 12 +++-- .../web/TraceHttpAutoConfiguration.java | 2 +- .../web/TraceWebClientDisabledTests.java | 46 +++++++++++++++++++ .../instrument/web/TraceWebDisabledTests.java | 2 +- .../client/integration/WebClientTests.java | 28 ----------- .../spring-cloud-sleuth-sample-feign/pom.xml | 5 ++ 7 files changed, 67 insertions(+), 33 deletions(-) create mode 100644 spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceWebClientDisabledTests.java diff --git a/pom.xml b/pom.xml index 6654569ba..7f8b06872 100644 --- a/pom.xml +++ b/pom.xml @@ -274,6 +274,11 @@ true + + 3.10.0 + 3.10.0 + 20.0 + 1.7.1 diff --git a/spring-cloud-sleuth-core/pom.xml b/spring-cloud-sleuth-core/pom.xml index b0d30634b..f99ff7849 100644 --- a/spring-cloud-sleuth-core/pom.xml +++ b/spring-cloud-sleuth-core/pom.xml @@ -142,6 +142,11 @@ feign-core true + + io.github.openfeign.form + feign-form-spring + true + com.netflix.zuul zuul-core @@ -161,6 +166,7 @@ com.squareup.okhttp3 okhttp + ${okhttp.version} true @@ -273,7 +279,7 @@ com.squareup.okhttp3 mockwebserver - 3.5.0 + ${mockwebserver.version} test @@ -325,7 +331,7 @@ javax.resource javax.resource-api - 1.7.1 + ${javax.resource-api.version} test @@ -337,7 +343,7 @@ com.google.guava guava - 20.0 + ${guava.version} test diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceHttpAutoConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceHttpAutoConfiguration.java index 77bdcf8fe..87840de2c 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceHttpAutoConfiguration.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceHttpAutoConfiguration.java @@ -42,7 +42,7 @@ import org.springframework.lang.Nullable; * @since 2.0.0 */ @Configuration -@ConditionalOnBean(Tracing.class) +@ConditionalOnBean(TraceWebAutoConfiguration.class) @ConditionalOnProperty(name = "spring.sleuth.http.enabled", havingValue = "true", matchIfMissing = true) @AutoConfigureAfter(TraceWebAutoConfiguration.class) @EnableConfigurationProperties({ TraceKeys.class, SleuthHttpLegacyProperties.class }) diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceWebClientDisabledTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceWebClientDisabledTests.java new file mode 100644 index 000000000..f9443f3f8 --- /dev/null +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceWebClientDisabledTests.java @@ -0,0 +1,46 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.sleuth.instrument.web; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author Marcin Grzejszczak + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { TraceWebClientDisabledTests.Config.class }, properties = { + "spring.sleuth.web.enabled=true", "spring.sleuth.web.client.enabled=false" }) +public class TraceWebClientDisabledTests { + + @Test + public void should_load_context() { + + } + + @Configuration + @EnableAutoConfiguration + public static class Config { + + } + +} diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceWebDisabledTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceWebDisabledTests.java index 5063aba66..aae33b632 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceWebDisabledTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceWebDisabledTests.java @@ -29,7 +29,7 @@ import org.springframework.test.context.junit4.SpringRunner; */ @RunWith(SpringRunner.class) @SpringBootTest(classes = { TraceWebDisabledTests.Config.class }, properties = { - "spring.sleuth.web.enabled=true", "spring.sleuth.web.client.enabled=false" }) + "spring.sleuth.web.enabled=false" }) public class TraceWebDisabledTests { @Test diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/integration/WebClientTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/integration/WebClientTests.java index 5c1091c32..1d4ae877d 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/integration/WebClientTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/integration/WebClientTests.java @@ -16,7 +16,6 @@ package org.springframework.cloud.sleuth.instrument.web.client.integration; -import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -53,7 +52,6 @@ import org.awaitility.Awaitility; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -393,32 +391,6 @@ public class WebClientTests { then(this.tracer.currentSpan()).isNull(); } - @Test - @Ignore("Flakey on CI") - public void shouldReportTraceForCancelledRequestViaWebClient() { - Span span = this.tracer.nextSpan().name("foo").start(); - - try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) { - this.webClient.get().uri("http://localhost:" + this.port + "/noresponse") - .retrieve().bodyToMono(String.class).timeout(Duration.ofMillis(0)) - .block(); - } - catch (Exception e) { - - } - finally { - span.finish(); - } - - Awaitility.await().untilAsserted(() -> { - System.out.println("Found spans " + this.reporter.getSpans()); - final Optional clientSpan = this.reporter.getSpans().stream() - .filter(s -> s.kind() == zipkin2.Span.Kind.CLIENT).findFirst(); - then(clientSpan).isPresent(); - then(clientSpan.get().tags()).containsEntry("error", "CANCELLED"); - }); - } - Object[] parametersForShouldAttachTraceIdWhenCallingAnotherService() { return new Object[] { (ResponseEntityProvider) (tests) -> tests.testFeignInterface.headers(), diff --git a/spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-feign/pom.xml b/spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-feign/pom.xml index faac49150..848c93027 100644 --- a/spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-feign/pom.xml +++ b/spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-feign/pom.xml @@ -86,6 +86,11 @@ org.springframework.boot spring-boot-starter-actuator + + io.github.openfeign.form + feign-form-spring + true + org.springframework.boot spring-boot-starter-test