From 531532c068e89ad8fa3e5c7ca330c36eebcefa9a Mon Sep 17 00:00:00 2001 From: Auri Munoz Date: Tue, 26 Sep 2023 18:51:42 +0200 Subject: [PATCH] Test with a few stork services configured and refactor --- .../StorkMetricsLoadBalancerFailTest.java | 4 +- .../StorkMetricsServiceDiscoveryFailTest.java | 9 +- .../deployment/binder/StorkMetricsTest.java | 91 +++------ .../micrometer/test/GreetingResource.java | 4 +- .../stork/StorkObservationCollectorBean.java | 176 +++++++++--------- .../rest-client-reactive-stork/pom.xml | 27 --- .../stork/RestClientReactiveStorkTest.java | 48 ----- 7 files changed, 115 insertions(+), 244 deletions(-) diff --git a/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsLoadBalancerFailTest.java b/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsLoadBalancerFailTest.java index a817f8da19ebbd..97c5da7ef6afe3 100644 --- a/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsLoadBalancerFailTest.java +++ b/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsLoadBalancerFailTest.java @@ -72,7 +72,6 @@ public void shouldGetStorkMetricsWhenServiceSelectorFails() { Util.assertTags(Tag.of("service-name", "pingpong-service"), instanceCounter, serviceDiscoveryDuration, serviceSelectionDuration, overallDuration); - assertThat(StorkObservationCollectorBean.STORK_METRICS.failure()).isNotNull(); assertThat(instanceCounter.count()).isEqualTo(1); assertThat(serviceDiscoveryFailures.value()).isEqualTo(0); assertThat(loadBalancerFailures.value()).isEqualTo(1); @@ -83,7 +82,8 @@ public void shouldGetStorkMetricsWhenServiceSelectorFails() { } private static void assertStorkMetrics() { - ObservationPoints.StorkResolutionEvent metrics = StorkObservationCollectorBean.STORK_METRICS; + ObservationPoints.StorkResolutionEvent metrics = StorkObservationCollectorBean.STORK_METRICS + .get("pingpong-service" + StorkObservationCollectorBean.METRICS_SUFIX); Assertions.assertThat(metrics.getDiscoveredInstancesCount()).isEqualTo(1); Assertions.assertThat(metrics.getSelectedInstanceId()).isEqualTo(-1); Assertions.assertThat(metrics.getServiceName()).isEqualTo("pingpong-service"); diff --git a/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsServiceDiscoveryFailTest.java b/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsServiceDiscoveryFailTest.java index acca8469b044d9..5d663bd2baac0a 100644 --- a/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsServiceDiscoveryFailTest.java +++ b/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsServiceDiscoveryFailTest.java @@ -9,8 +9,6 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnOs; -import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.Mockito; @@ -30,7 +28,6 @@ import io.smallrye.mutiny.Uni; import io.smallrye.stork.api.observability.ObservationPoints; -@DisabledOnOs(OS.WINDOWS) public class StorkMetricsServiceDiscoveryFailTest { @RegisterExtension @@ -71,7 +68,6 @@ public void shouldGetStorkMetricsWhenServiceDiscoveryFails() { Util.assertTags(Tag.of("service-name", "pingpong-service"), instanceCounter, serviceDiscoveryDuration, serviceSelectionDuration, overallDuration); - assertThat(StorkObservationCollectorBean.STORK_METRICS.failure()).isNotNull(); assertThat(instanceCounter.count()).isEqualTo(0); assertThat(serviceDiscoveryFailures.value()).isEqualTo(1); assertThat(loadBalancerFailures.value()).isEqualTo(0); @@ -82,8 +78,9 @@ public void shouldGetStorkMetricsWhenServiceDiscoveryFails() { } private static void assertStorkMetrics() { - ObservationPoints.StorkResolutionEvent metrics = StorkObservationCollectorBean.STORK_METRICS; - Assertions.assertThat(metrics.getDiscoveredInstancesCount()).isEqualTo(0); + ObservationPoints.StorkResolutionEvent metrics = StorkObservationCollectorBean.STORK_METRICS + .get("pingpong-service" + StorkObservationCollectorBean.METRICS_SUFIX); + Assertions.assertThat(metrics.getDiscoveredInstancesCount()).isNegative(); Assertions.assertThat(metrics.getSelectedInstanceId()).isEqualTo(-1); Assertions.assertThat(metrics.getServiceName()).isEqualTo("pingpong-service"); Assertions.assertThat(metrics.isDone()).isTrue(); diff --git a/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsTest.java b/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsTest.java index 58e1882f90e149..80eba2968436f9 100644 --- a/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsTest.java +++ b/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsTest.java @@ -9,7 +9,6 @@ import jakarta.inject.Inject; import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -27,26 +26,13 @@ public class StorkMetricsTest { - // quarkus.stork.hello-service.service-discovery.type=my - // quarkus.stork.hello-service.load-balancer.type=least-response-time - // hello/mp-rest/url=stork://hello-service/hello - // # slow-service and fast-service come from Slow- and FastWiremockServer - // quarkus.stork.hello-service.service-discovery.address-list=${slow-service},${fast-service} - // quarkus.stork.hello-service.service-discovery.secure=true - // quarkus.tls.trust-all=true - @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() .withConfigurationResource("test-logging.properties") - .overrideConfigKey("quarkus.micrometer.binder.stork.enabled", "true") + .overrideConfigKey("pingpong/mp-rest/url", "stork://pingpong-service") .overrideConfigKey("quarkus.stork.pingpong-service.service-discovery.type", "static") .overrideConfigKey("quarkus.stork.pingpong-service.service-discovery.address-list", "${test.url}") - .overrideConfigKey("pingpong/mp-rest/url", "stork://pingpong-service") - - // .overrideConfigKey("hello/mp-rest/url", "stork://hello-service/hello") - // .overrideConfigKey("quarkus.stork.hello-service.service-discovery.type", "static") - // .overrideConfigKey("quarkus.stork.hello-service.service-discovery.address-list", "${test.url}") - .overrideConfigKey("greeting/mp-rest/url", "stork://greeting-service") + .overrideConfigKey("greeting/mp-rest/url", "stork://greeting-service/greeting") .overrideConfigKey("quarkus.stork.greeting-service.service-discovery.type", "static") .overrideConfigKey("quarkus.stork.greeting-service.service-discovery.address-list", "${test.url}") .withApplicationRoot((jar) -> jar @@ -57,75 +43,46 @@ public class StorkMetricsTest { MeterRegistry registry; @Test - @Disabled - public void shouldGetStorkMetricsWhenEverythingSucceded() { + public void shouldGetStorkMetricsForTwoServicesWhenEverythingSucceded() { when().get("/ping/one").then().statusCode(200); + when().get("greeting/hola").then().statusCode(200); //Stork metrics assertStorkMetrics("pingpong-service"); + assertStorkMetrics("greeting-service"); // Stork metrics exposed to Micrometer - Counter instanceCounter = registry.get("stork.instances.count").counter(); - Timer serviceDiscoveryDuration = registry.get("stork.service-discovery.duration").timer(); - Timer serviceSelectionDuration = registry.get("stork.service-selection.duration").timer(); - Timer overallDuration = registry.get("stork.overall.duration").timer(); - Gauge serviceDiscoveryFailures = registry.get("stork.service-discovery.failures").gauge(); - Gauge loadBalancerFailures = registry.get("stork.load-balancer.failures").gauge(); - - Util.assertTags(Tag.of("service-name", "pingpong-service"), instanceCounter, serviceDiscoveryDuration, - serviceSelectionDuration, overallDuration); - - Assertions.assertThat(instanceCounter.count()).isEqualTo(1); - Assertions.assertThat(serviceDiscoveryFailures.value()).isEqualTo(0); - Assertions.assertThat(loadBalancerFailures.value()).isEqualTo(0); - Assertions.assertThat(serviceDiscoveryDuration.totalTime(TimeUnit.NANOSECONDS)).isGreaterThan(0); - Assertions.assertThat(serviceSelectionDuration.totalTime(TimeUnit.NANOSECONDS)).isGreaterThan(0); - Assertions.assertThat(overallDuration.totalTime(TimeUnit.NANOSECONDS)).isGreaterThan(0); + assertStorkMetricsInMicrometerRegistry("pingpong-service"); + assertStorkMetricsInMicrometerRegistry("greeting-service"); } - @Test - public void shouldGetStorkMetricsWhenEverythingSuccededRef() { - // when().get("/ping/one").then().statusCode(200); - when().get("greeting/hola").then().statusCode(200); - - //Stork metrics - assertStorkMetrics("pingpong-service"); - assertStorkMetrics("greeting-service"); - - // Tag pingpongTag = Tag.of("service-name", "pingpong-service"); - // - // List collect = registry.getMeters().stream().filter(meter -> meter.getId().getTags().contains()).collect(Collectors.toList()); - // - // Optional counterMeter = collect.stream().filter(meter -> meter.getId().getName().equals("stork.instances.count")).findFirst(); - // - // assertThat(counterMeter).isPresent(); - - // Stork metrics exposed to Micrometer - Counter instanceCounter = registry.get("stork.instances.count").counter(); - Counter instanceCounter2 = registry.counter("stork.instances.count", "pingpong-service"); - Timer serviceDiscoveryDuration = registry.get("stork.service-discovery.duration").timer(); - Timer serviceSelectionDuration = registry.get("stork.service-selection.duration").timer(); - Timer overallDuration = registry.get("stork.overall.duration").timer(); - Gauge serviceDiscoveryFailures = registry.get("stork.service-discovery.failures").gauge(); - Gauge loadBalancerFailures = registry.get("stork.load-balancer.failures").gauge(); - - Util.assertTags(Tag.of("service-name", "pingpong-service"), instanceCounter, serviceDiscoveryDuration, + public void assertStorkMetricsInMicrometerRegistry(String serviceName) { + Counter instanceCounter = registry.counter("stork.instances.count", "service-name", serviceName); + Timer serviceDiscoveryDuration = registry.timer("stork.service-discovery.duration", "service-name", serviceName); + Timer serviceSelectionDuration = registry.timer("stork.service-selection.duration", "service-name", serviceName); + Timer overallDuration = registry.timer("stork.overall.duration", "service-name", serviceName); + Gauge serviceDiscoveryFailures = registry.get("stork.service-discovery.failures") + .tags("service-name", serviceName).gauge(); + Gauge loadBalancerFailures = registry.get("stork.load-balancer.failures").tags("service-name", serviceName) + .gauge(); + + Util.assertTags(Tag.of("service-name", serviceName), instanceCounter, serviceDiscoveryDuration, serviceSelectionDuration, overallDuration); Assertions.assertThat(instanceCounter.count()).isEqualTo(1); - Assertions.assertThat(serviceDiscoveryFailures.value()).isEqualTo(0); - Assertions.assertThat(loadBalancerFailures.value()).isEqualTo(0); Assertions.assertThat(serviceDiscoveryDuration.totalTime(TimeUnit.NANOSECONDS)).isGreaterThan(0); Assertions.assertThat(serviceSelectionDuration.totalTime(TimeUnit.NANOSECONDS)).isGreaterThan(0); Assertions.assertThat(overallDuration.totalTime(TimeUnit.NANOSECONDS)).isGreaterThan(0); - + Assertions.assertThat(serviceDiscoveryFailures.value()).isEqualTo(0); + Assertions.assertThat(loadBalancerFailures.value()).isEqualTo(0); } - private static void assertStorkMetrics(String serviceName) { - ObservationPoints.StorkResolutionEvent metrics = StorkObservationCollectorBean.STORK_METRICS; + public static void assertStorkMetrics(String serviceName) { + ObservationPoints.StorkResolutionEvent metrics = StorkObservationCollectorBean.STORK_METRICS + .get(serviceName + StorkObservationCollectorBean.METRICS_SUFIX); Assertions.assertThat(metrics.getDiscoveredInstancesCount()).isEqualTo(1); - Assertions.assertThat(metrics.getSelectedInstanceId()).isEqualTo(0); + Assertions.assertThat(metrics.getSelectedInstanceId()).isNotNegative(); Assertions.assertThat(metrics.getServiceName()).isEqualTo(serviceName); Assertions.assertThat(metrics.isDone()).isTrue(); Assertions.assertThat(metrics.failure()).isNull(); diff --git a/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/test/GreetingResource.java b/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/test/GreetingResource.java index 7832966ce6f0e3..e78a85dfc8ef4c 100644 --- a/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/test/GreetingResource.java +++ b/extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/test/GreetingResource.java @@ -11,7 +11,7 @@ import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; import org.eclipse.microprofile.rest.client.inject.RestClient; -@Path("/") +@Path("/greeting") @ApplicationScoped public class GreetingResource { @@ -27,7 +27,7 @@ public interface GreetingRestClient { GreetingRestClient greetingRestClient; @GET - @Path("greeting/{message}") + @Path("/{message}") public String passThrough(@PathParam("message") String message) { return greetingRestClient.echo(message + " World!"); } diff --git a/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/binder/stork/StorkObservationCollectorBean.java b/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/binder/stork/StorkObservationCollectorBean.java index 8657c0b3215f2d..fdd814202eab7b 100644 --- a/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/binder/stork/StorkObservationCollectorBean.java +++ b/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/binder/stork/StorkObservationCollectorBean.java @@ -1,7 +1,9 @@ package io.quarkus.micrometer.runtime.binder.stork; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import jakarta.enterprise.context.ApplicationScoped; @@ -22,107 +24,97 @@ @Typed(ObservationCollector.class) public class StorkObservationCollectorBean implements ObservationCollector { + public static final String METRICS_SUFIX = "-metrics"; final MeterRegistry registry = Metrics.globalRegistry; private final EventCompletionHandler STORK_HANDLER = ev -> { //TODO }; - public static ObservationPoints.StorkResolutionEvent STORK_METRICS; + public final static Map STORK_METRICS = new HashMap<>(); @Override public ObservationPoints.StorkResolutionEvent create(String serviceName, String serviceDiscoveryType, String serviceSelectionType) { - STORK_METRICS = new ObservationPoints.StorkResolutionEvent(serviceName, serviceDiscoveryType, serviceSelectionType, - STORK_HANDLER) { - - private final Tags tags = Tags.of(Tag.of("service-name", getServiceName()));; - private final Counter instanceCounter = Counter.builder("stork.instances.count") - .description("The number of service instances discovered") - .tags(tags) - .register(registry);; - - private final Timer serviceDiscoveryTimer = Timer.builder("stork.service-discovery.duration") - .description("The duration of the discovery operation") - .tags(tags) - .register(registry); - - private final Timer serviceSelectionTimer = Timer.builder("stork.service-selection.duration") - .description("The duration of the selection operation ") - .tags(tags) - .register(registry); - - private final Timer overallTimer = Timer.builder("stork.overall.duration") - .description("The total duration of the Stork service discovery and selection operations") - .tags(tags) - .register(registry); - - private List serviceDiscoveryExceptions = new ArrayList<>(); - - private final Gauge serviceDiscoveryFailures = Gauge - .builder("stork.service-discovery.failures", serviceDiscoveryExceptions, List::size) - .description("The number of failures during service discovery").tags(tags) - .register(registry); - - private List serviceSelectionExceptions = new ArrayList<>(); - - private final Gauge serviceSelectionFailures = Gauge - .builder("stork.load-balancer.failures", serviceSelectionExceptions, List::size) - .description("The number of failures during service selection.").tags(tags) - .register(registry); - - @Override - public void onServiceDiscoverySuccess(List instances) { - endOfServiceDiscovery = System.nanoTime(); - serviceDiscoveryDone = true; - if (instances != null) { - instanceCounter.increment(); - } - serviceDiscoveryTimer.record(getServiceDiscoveryDuration().getNano(), TimeUnit.NANOSECONDS); - - } - - @Override - public int getDiscoveredInstancesCount() { - return (int) instanceCounter.count(); - } - - @Override - public void onServiceDiscoveryFailure(Throwable throwable) { - endOfServiceDiscovery = System.nanoTime(); - serviceDiscoveryDone = true; - failure = throwable; - serviceDiscoveryExceptions.add(throwable); - handler.complete(this); - serviceDiscoveryTimer.record(getServiceDiscoveryDuration().getNano(), TimeUnit.NANOSECONDS); - overallTimer.record(getServiceDiscoveryDuration().getNano(), TimeUnit.NANOSECONDS); - - } - - @Override - public void onServiceSelectionSuccess(long id) { - endOfServiceSelection = System.nanoTime(); - selectedInstanceId = id; - done = true; - handler.complete(this); - serviceSelectionTimer.record(getServiceSelectionDuration().getNano(), TimeUnit.NANOSECONDS); - overallTimer.record(getOverallDuration().getNano(), TimeUnit.NANOSECONDS); - - } - - @Override - public void onServiceSelectionFailure(Throwable throwable) { - endOfServiceSelection = System.nanoTime(); - if (failure != throwable) { //if SD fails we don't know count the error as a LB error - failure = throwable; - serviceSelectionExceptions.add(throwable); - } - handler.complete(this); - serviceSelectionTimer.record(getServiceSelectionDuration().getNano(), TimeUnit.NANOSECONDS); - overallTimer.record(getServiceSelectionDuration().getNano(), TimeUnit.NANOSECONDS); - } - - }; - return STORK_METRICS; + return STORK_METRICS.computeIfAbsent(serviceName + METRICS_SUFIX, + key -> new ObservationPoints.StorkResolutionEvent(serviceName, serviceDiscoveryType, serviceSelectionType, + STORK_HANDLER) { + + private final Tags tags = Tags.of(Tag.of("service-name", getServiceName()));; + private final Counter instanceCounter = Counter.builder("stork.instances.count") + .description("The number of service instances discovered") + .tags(tags) + .register(registry);; + + private final Timer serviceDiscoveryTimer = Timer + .builder("stork.service-discovery.duration") + .description("The duration of the discovery operation") + .tags(tags) + .register(registry); + + private final Timer serviceSelectionTimer = Timer + .builder("stork.service-selection.duration") + .description("The duration of the selection operation ") + .tags(tags) + .register(registry); + + private final Timer overallTimer = Timer.builder("stork.overall.duration") + .description("The total duration of the Stork service discovery and selection operations") + .tags(tags) + .register(registry); + + private List serviceDiscoveryExceptions = new ArrayList<>(); + + private final Gauge serviceDiscoveryFailures = Gauge + .builder("stork.service-discovery.failures", serviceDiscoveryExceptions, + List::size) + .description("The number of failures during service discovery").tags(tags) + .register(registry); + + private List serviceSelectionExceptions = new ArrayList<>(); + + private final Gauge serviceSelectionFailures = Gauge + .builder("stork.load-balancer.failures", serviceSelectionExceptions, List::size) + .description("The number of failures during service selection.").tags(tags) + .register(registry); + + @Override + public void onServiceDiscoverySuccess(List instances) { + super.onServiceDiscoverySuccess(instances); + if (instances != null) { + instanceCounter.increment(); + } + serviceDiscoveryTimer.record(getServiceDiscoveryDuration().getNano(), TimeUnit.NANOSECONDS); + + } + + @Override + public void onServiceDiscoveryFailure(Throwable throwable) { + super.onServiceDiscoveryFailure(throwable); + serviceDiscoveryExceptions.add(throwable); + serviceDiscoveryTimer.record(getServiceDiscoveryDuration().getNano(), TimeUnit.NANOSECONDS); + overallTimer.record(getServiceDiscoveryDuration().getNano(), TimeUnit.NANOSECONDS); + + } + + @Override + public void onServiceSelectionSuccess(long id) { + super.onServiceSelectionSuccess(id); + serviceSelectionTimer.record(getServiceSelectionDuration().getNano(), TimeUnit.NANOSECONDS); + overallTimer.record(getOverallDuration().getNano(), TimeUnit.NANOSECONDS); + + } + + @Override + public void onServiceSelectionFailure(Throwable throwable) { + if (failure != throwable) { //if SD fails we don't know count the error as a LB error + serviceSelectionExceptions.add(throwable); + } + super.onServiceSelectionFailure(throwable); + serviceSelectionTimer.record(getServiceSelectionDuration().getNano(), TimeUnit.NANOSECONDS); + overallTimer.record(getServiceSelectionDuration().getNano(), TimeUnit.NANOSECONDS); + } + + }); } } diff --git a/integration-tests/rest-client-reactive-stork/pom.xml b/integration-tests/rest-client-reactive-stork/pom.xml index 4a2387d3b96412..90f50aadf71f57 100644 --- a/integration-tests/rest-client-reactive-stork/pom.xml +++ b/integration-tests/rest-client-reactive-stork/pom.xml @@ -65,10 +65,6 @@ rest-assured test - - org.mockito - mockito-core - org.awaitility awaitility @@ -115,29 +111,6 @@ - - io.quarkus - quarkus-micrometer-registry-prometheus - - - - - - - - io.quarkus - quarkus-micrometer-registry-prometheus-deployment - ${project.version} - pom - test - - - * - * - - - - diff --git a/integration-tests/rest-client-reactive-stork/src/test/java/io/quarkus/it/rest/reactive/stork/RestClientReactiveStorkTest.java b/integration-tests/rest-client-reactive-stork/src/test/java/io/quarkus/it/rest/reactive/stork/RestClientReactiveStorkTest.java index 6587f6d5c0279e..5adb6924ee71bd 100644 --- a/integration-tests/rest-client-reactive-stork/src/test/java/io/quarkus/it/rest/reactive/stork/RestClientReactiveStorkTest.java +++ b/integration-tests/rest-client-reactive-stork/src/test/java/io/quarkus/it/rest/reactive/stork/RestClientReactiveStorkTest.java @@ -7,25 +7,15 @@ import java.util.HashSet; import java.util.Set; -import java.util.concurrent.TimeUnit; -import jakarta.inject.Inject; - -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import io.micrometer.core.instrument.Counter; -import io.micrometer.core.instrument.Gauge; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Timer; import io.quarkus.arc.Arc; import io.quarkus.it.rest.client.reactive.stork.MyServiceDiscoveryProvider; -import io.quarkus.micrometer.runtime.binder.stork.StorkObservationCollectorBean; import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.DisabledOnIntegrationTest; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.Response; -import io.smallrye.stork.api.observability.ObservationPoints; import io.vertx.core.Vertx; @QuarkusTest @@ -33,9 +23,6 @@ @QuarkusTestResource(FastWiremockServer.class) public class RestClientReactiveStorkTest { - @Inject - MeterRegistry registry; - @Test @DisabledOnIntegrationTest void shouldUseQuarkusVertxInstance() { @@ -56,10 +43,6 @@ void shouldUseFasterService() { assertThat(responses).contains(FAST_RESPONSE, SLOW_RESPONSE); - //Check metrics - assertStorkMetrics(); - assertStorkMetricsOnMicrometerRegistry(); - responses.clear(); for (int i = 0; i < 3; i++) { @@ -71,35 +54,4 @@ void shouldUseFasterService() { // after hitting the slow endpoint, we should only use the fast one: assertThat(responses).containsOnly(FAST_RESPONSE, FAST_RESPONSE, FAST_RESPONSE); } - - private void assertStorkMetricsOnMicrometerRegistry() { - // Stork metrics exposed to Micrometer - Counter instanceCounter = registry.get("stork.instances.count").counter(); - Timer serviceDiscoveryDuration = registry.get("stork.service-discovery.duration").timer(); - Timer serviceSelectionDuration = registry.get("stork.service-selection.duration").timer(); - Timer overallDuration = registry.get("stork.overall.duration").timer(); - Gauge serviceDiscoveryFailures = registry.get("stork.service-discovery.failures").gauge(); - Gauge loadBalancerFailures = registry.get("stork.load-balancer.failures").gauge(); - - Assertions.assertThat(instanceCounter.count()).isEqualTo(2); - Assertions.assertThat(serviceDiscoveryFailures.value()).isEqualTo(0); - Assertions.assertThat(loadBalancerFailures.value()).isEqualTo(0); - Assertions.assertThat(serviceDiscoveryDuration.totalTime(TimeUnit.NANOSECONDS)).isGreaterThan(0); - Assertions.assertThat(serviceSelectionDuration.totalTime(TimeUnit.NANOSECONDS)).isGreaterThan(0); - Assertions.assertThat(overallDuration.totalTime(TimeUnit.NANOSECONDS)).isGreaterThan(0); - } - - private static void assertStorkMetrics() { - ObservationPoints.StorkResolutionEvent metrics = StorkObservationCollectorBean.STORK_METRICS; - assertThat(metrics.getDiscoveredInstancesCount()).isEqualTo(2); - assertThat(metrics.getSelectedInstanceId()).isNotNegative(); - assertThat(metrics.getServiceName()).isEqualTo("hello-service"); - assertThat(metrics.isDone()).isTrue(); - assertThat(metrics.failure()).isNull(); - assertThat(metrics.getOverallDuration()).isNotNull(); - assertThat(metrics.getServiceDiscoveryType()).isEqualTo("my"); - assertThat(metrics.getServiceSelectionType()).isEqualTo("least-response-time"); - assertThat(metrics.getServiceDiscoveryDuration()).isNotNull(); - assertThat(metrics.getServiceSelectionDuration()).isNotNull(); - } }