diff --git a/libraries.gradle b/libraries.gradle index 5d04020788..e6c32745c5 100644 --- a/libraries.gradle +++ b/libraries.gradle @@ -8,7 +8,7 @@ ext { slf4jVersion = '1.7.24' assertjVersion = '3.6.2' logbackVersion = '0.9.26' - mockitoVersion = '1.10.19' + mockitoVersion = '2.15.0' powermockVersion = '1.6.6' jcacheVersion = '1.0.0' awaitilityVersion = '1.7.0' @@ -38,7 +38,7 @@ ext { logback: "ch.qos.logback:logback-classic:${logbackVersion}", mockito: "org.mockito:mockito-core:${mockitoVersion}", powermock: "org.powermock:powermock:${powermockVersion}", - powermock_api_mockito: "org.powermock:powermock-api-mockito:${powermockVersion}", + powermock_api_mockito: "org.powermock:powermock-api-mockito2:${powermockVersion}", powermock_module_junit4: "org.powermock:powermock-module-junit4:${powermockVersion}", awaitility: "com.jayway.awaitility:awaitility:${awaitilityVersion}", reactor_test: "io.projectreactor:reactor-test:${reactorVersion}", diff --git a/resilience4j-spring-boot2/build.gradle b/resilience4j-spring-boot2/build.gradle index 14cbf5fb58..a53785c189 100644 --- a/resilience4j-spring-boot2/build.gradle +++ b/resilience4j-spring-boot2/build.gradle @@ -3,13 +3,9 @@ dependencies { compile ( libraries.spring_boot2_actuator ) compile ( libraries.spring_boot2_web ) compile ( libraries.spring_reactor ) + compile project(':resilience4j-micrometer') compile project(':resilience4j-circuitbreaker') compile project(':resilience4j-ratelimiter') compile project(':resilience4j-consumer') - compileOnly project(':resilience4j-prometheus') - compileOnly project(':resilience4j-metrics') testCompile ( libraries.spring_boot2_test ) - testCompile project(':resilience4j-prometheus') - testCompile project(':resilience4j-metrics') - testCompile ( libraries.prometheus_spring_boot ) } \ No newline at end of file diff --git a/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/circuitbreaker/autoconfigure/CircuitBreakerMetricsAutoConfiguration.java b/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/circuitbreaker/autoconfigure/CircuitBreakerMetricsAutoConfiguration.java index b462eaace1..82df3fc701 100644 --- a/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/circuitbreaker/autoconfigure/CircuitBreakerMetricsAutoConfiguration.java +++ b/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/circuitbreaker/autoconfigure/CircuitBreakerMetricsAutoConfiguration.java @@ -15,8 +15,6 @@ */ package io.github.resilience4j.circuitbreaker.autoconfigure; -import com.codahale.metrics.MetricRegistry; - import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -24,7 +22,7 @@ import org.springframework.context.annotation.Configuration; import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.metrics.CircuitBreakerMetrics; +import io.github.resilience4j.micrometer.CircuitBreakerMetrics; import io.micrometer.core.instrument.MeterRegistry; /** @@ -32,13 +30,14 @@ * Auto-configuration} for resilience4j-metrics. */ @Configuration -@ConditionalOnClass(MeterRegistry.class) +@ConditionalOnClass(MetricsAutoConfiguration.class) @AutoConfigureAfter(value = {CircuitBreakerAutoConfiguration.class, MetricsAutoConfiguration.class}) public class CircuitBreakerMetricsAutoConfiguration { + @Bean - public CircuitBreakerMetrics registerCircuitBreakerMetrics(CircuitBreakerRegistry circuitBreakerRegistry, MetricRegistry metricRegistry){ + public CircuitBreakerMetrics registerCircuitBreakerMetrics(CircuitBreakerRegistry circuitBreakerRegistry, MeterRegistry meterRegistry){ CircuitBreakerMetrics circuitBreakerMetrics = CircuitBreakerMetrics.ofCircuitBreakerRegistry(circuitBreakerRegistry); - metricRegistry.registerAll(circuitBreakerMetrics); + circuitBreakerMetrics.bindTo(meterRegistry); return circuitBreakerMetrics; } } diff --git a/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/circuitbreaker/autoconfigure/CircuitBreakerPrometheusAutoConfiguration.java b/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/circuitbreaker/autoconfigure/CircuitBreakerPrometheusAutoConfiguration.java deleted file mode 100644 index cd71f3be15..0000000000 --- a/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/circuitbreaker/autoconfigure/CircuitBreakerPrometheusAutoConfiguration.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2017 Robert Winkler - * - * 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 - * - * http://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 io.github.resilience4j.circuitbreaker.autoconfigure; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; -import io.github.resilience4j.prometheus.CircuitBreakerExports; - -/** - * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration - * Auto-configuration} for resilience4j-metrics. - */ -@Configuration -@AutoConfigureAfter(value = CircuitBreakerAutoConfiguration.class) -@ConditionalOnClass(CircuitBreakerExports.class) -public class CircuitBreakerPrometheusAutoConfiguration { - @Bean - public CircuitBreakerExports circuitBreakerPrometheusCollector(CircuitBreakerRegistry circuitBreakerRegistry){ - CircuitBreakerExports collector = CircuitBreakerExports.ofCircuitBreakerRegistry(circuitBreakerRegistry); - collector.register(); - return collector; - } -} diff --git a/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/ratelimiter/autoconfigure/RateLimiterMetricsAutoConfiguration.java b/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/ratelimiter/autoconfigure/RateLimiterMetricsAutoConfiguration.java index 3eec2f83dd..970c90c104 100644 --- a/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/ratelimiter/autoconfigure/RateLimiterMetricsAutoConfiguration.java +++ b/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/ratelimiter/autoconfigure/RateLimiterMetricsAutoConfiguration.java @@ -15,8 +15,6 @@ */ package io.github.resilience4j.ratelimiter.autoconfigure; -import com.codahale.metrics.MetricRegistry; - import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -24,7 +22,7 @@ import org.springframework.context.annotation.Configuration; import io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerAutoConfiguration; -import io.github.resilience4j.metrics.RateLimiterMetrics; +import io.github.resilience4j.micrometer.RateLimiterMetrics; import io.github.resilience4j.ratelimiter.RateLimiterRegistry; import io.micrometer.core.instrument.MeterRegistry; @@ -33,13 +31,13 @@ * Auto-configuration} for resilience4j-metrics. */ @Configuration -@ConditionalOnClass(MeterRegistry.class) +@ConditionalOnClass(MetricsAutoConfiguration.class) @AutoConfigureAfter(value = {CircuitBreakerAutoConfiguration.class, MetricsAutoConfiguration.class}) public class RateLimiterMetricsAutoConfiguration { @Bean - public RateLimiterMetrics registerRateLimiterMetrics(RateLimiterRegistry rateLimiterRegistry, MetricRegistry metricRegistry) { + public RateLimiterMetrics registerRateLimiterMetrics(RateLimiterRegistry rateLimiterRegistry, MeterRegistry meterRegistry) { RateLimiterMetrics rateLimiterMetrics = RateLimiterMetrics.ofRateLimiterRegistry(rateLimiterRegistry); - metricRegistry.registerAll(rateLimiterMetrics); + rateLimiterMetrics.bindTo(meterRegistry); return rateLimiterMetrics; } } diff --git a/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/ratelimiter/autoconfigure/RateLimiterPrometheusAutoConfiguration.java b/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/ratelimiter/autoconfigure/RateLimiterPrometheusAutoConfiguration.java deleted file mode 100644 index e1455ab12d..0000000000 --- a/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/ratelimiter/autoconfigure/RateLimiterPrometheusAutoConfiguration.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2017 Bohdan Storozhuk - * - * 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 - * - * http://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 io.github.resilience4j.ratelimiter.autoconfigure; - -import io.github.resilience4j.prometheus.RateLimiterExports; -import io.github.resilience4j.ratelimiter.RateLimiterRegistry; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration - * Auto-configuration} for resilience4j-metrics. - */ -@Configuration -@AutoConfigureAfter(value = RateLimiterAutoConfiguration.class) -@ConditionalOnClass(RateLimiterExports.class) -public class RateLimiterPrometheusAutoConfiguration { - @Bean - public RateLimiterExports rateLimiterPrometheusCollector(RateLimiterRegistry rateLimiterRegistry){ - RateLimiterExports collector = RateLimiterExports.ofRateLimiterRegistry(rateLimiterRegistry); - collector.register(); - return collector; - } -} diff --git a/resilience4j-spring-boot2/src/main/resources/META-INF/spring.factories b/resilience4j-spring-boot2/src/main/resources/META-INF/spring.factories index 8d732ecea5..f71c475f35 100644 --- a/resilience4j-spring-boot2/src/main/resources/META-INF/spring.factories +++ b/resilience4j-spring-boot2/src/main/resources/META-INF/spring.factories @@ -1,7 +1,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerAutoConfiguration,\ io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerMetricsAutoConfiguration,\ -io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerPrometheusAutoConfiguration,\ io.github.resilience4j.ratelimiter.autoconfigure.RateLimiterAutoConfiguration,\ -io.github.resilience4j.ratelimiter.autoconfigure.RateLimiterMetricsAutoConfiguration,\ -io.github.resilience4j.ratelimiter.autoconfigure.RateLimiterPrometheusAutoConfiguration +io.github.resilience4j.ratelimiter.autoconfigure.RateLimiterMetricsAutoConfiguration diff --git a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java index a19fa1e299..0e8e78e093 100644 --- a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java +++ b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java @@ -84,11 +84,11 @@ public void testCircuitBreakerAutoConfiguration() throws IOException { // Test Actuator endpoints - ResponseEntity circuitBreakerList = restTemplate.getForEntity("/circuitbreaker", CircuitBreakerEndpointResponse.class); + ResponseEntity circuitBreakerList = restTemplate.getForEntity("/actuator/circuitbreaker", CircuitBreakerEndpointResponse.class); assertThat(circuitBreakerList.getBody().getCircuitBreakers()).hasSize(2).containsExactly("backendA", "backendB"); - ResponseEntity circuitBreakerEventList = restTemplate.getForEntity("/circuitbreaker/events", CircuitBreakerEventsEndpointResponse.class); + ResponseEntity circuitBreakerEventList = restTemplate.getForEntity("/actuator/circuitbreaker/events", CircuitBreakerEventsEndpointResponse.class); assertThat(circuitBreakerEventList.getBody().getCircuitBreakerEvents()).hasSize(2); assertThat(circuitBreakerAspect.getOrder()).isEqualTo(400); diff --git a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterAutoConfigurationTest.java b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterAutoConfigurationTest.java index c026d8d942..0f9db341ad 100644 --- a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterAutoConfigurationTest.java +++ b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterAutoConfigurationTest.java @@ -93,7 +93,7 @@ public void testRateLimiterAutoConfiguration() throws IOException { // Test Actuator endpoints ResponseEntity rateLimiterList = restTemplate - .getForEntity("/ratelimiter", RateLimiterEndpointResponse.class); + .getForEntity("/actuator/ratelimiter", RateLimiterEndpointResponse.class); assertThat(rateLimiterList.getBody().getRateLimitersNames()).hasSize(2).containsExactly("backendA", "backendB"); @@ -106,7 +106,7 @@ public void testRateLimiterAutoConfiguration() throws IOException { } ResponseEntity rateLimiterEventList = restTemplate - .getForEntity("/ratelimiter/events", RateLimiterEventsEndpointResponse.class); + .getForEntity("/actuator/ratelimiter/events", RateLimiterEventsEndpointResponse.class); List eventsList = rateLimiterEventList.getBody().getEventsList(); assertThat(eventsList).isNotEmpty(); diff --git a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/service/test/TestApplication.java b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/service/test/TestApplication.java index 12b13b4e74..7dc3c897fd 100644 --- a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/service/test/TestApplication.java +++ b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/service/test/TestApplication.java @@ -3,15 +3,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import io.prometheus.client.spring.boot.EnablePrometheusEndpoint; -import io.prometheus.client.spring.boot.EnableSpringBootMetricsCollector; - /** * @author bstorozhuk */ @SpringBootApplication(scanBasePackages = "io.github.resilience4j") -@EnableSpringBootMetricsCollector -@EnablePrometheusEndpoint public class TestApplication { public static void main(String[] args) { SpringApplication.run(TestApplication.class, args);