-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a90d6d5
commit ca9e2f7
Showing
23 changed files
with
919 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...eployment/src/main/java/io/quarkus/micrometer/deployment/binder/StorkBinderProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.micrometer.deployment.binder; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
import io.quarkus.arc.deployment.AdditionalBeanBuildItem; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.micrometer.runtime.MicrometerRecorder; | ||
import io.quarkus.micrometer.runtime.config.MicrometerConfig; | ||
|
||
public class StorkBinderProcessor { | ||
|
||
static final String OBSERVABLE_CLIENT = "io.smallrye.stork.api.Service"; | ||
static final String METRICS_BEAN_CLASS = "io.quarkus.micrometer.runtime.binder.stork.StorkObservationCollectorBean"; | ||
|
||
static final Class<?> OBSERVABLE_CLIENT_CLASS = MicrometerRecorder.getClassForName(OBSERVABLE_CLIENT); | ||
|
||
static class StorkMetricsSupportEnabled implements BooleanSupplier { | ||
MicrometerConfig mConfig; | ||
|
||
public boolean getAsBoolean() { | ||
return OBSERVABLE_CLIENT_CLASS != null && mConfig.checkBinderEnabledWithDefault(mConfig.binder.stork); | ||
} | ||
} | ||
|
||
@BuildStep(onlyIf = StorkMetricsSupportEnabled.class) | ||
AdditionalBeanBuildItem addStorkObservationCollector() { | ||
return AdditionalBeanBuildItem.unremovableOf(METRICS_BEAN_CLASS); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...yment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsDisabledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.quarkus.micrometer.deployment.binder; | ||
Check failure on line 1 in extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsDisabledTest.java quarkus-bot / Build summary for ca9e2f7d22b4291a508d31bd0a70228d1a2a6ad9JVM Tests - JDK 17 Windows
Raw output
|
||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.stork.api.observability.ObservationCollector; | ||
|
||
public class StorkMetricsDisabledTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withConfigurationResource("test-logging.properties") | ||
.overrideConfigKey("quarkus.micrometer.binder.stork.enabled", "false") | ||
.overrideConfigKey("quarkus.micrometer.binder-enabled-default", "false") | ||
.overrideConfigKey("quarkus.micrometer.registry-enabled-default", "false") | ||
.withEmptyApplication(); | ||
|
||
@Inject | ||
Instance<ObservationCollector> bean; | ||
|
||
@Test | ||
void testNoInstancePresentIfNoRedisClientsClass() { | ||
assertTrue(bean.isUnsatisfied(), | ||
"No Stork metrics bean"); | ||
} | ||
|
||
} |
111 changes: 111 additions & 0 deletions
111
...c/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsLoadBalancerFailTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
|
||
package io.quarkus.micrometer.deployment.binder; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
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; | ||
|
||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Tag; | ||
import io.micrometer.core.instrument.Timer; | ||
import io.quarkus.micrometer.runtime.binder.stork.StorkObservationCollectorBean; | ||
import io.quarkus.micrometer.test.GreetingResource; | ||
import io.quarkus.micrometer.test.MockServiceSelectorConfiguration; | ||
import io.quarkus.micrometer.test.MockServiceSelectorProvider; | ||
import io.quarkus.micrometer.test.MockServiceSelectorProviderLoader; | ||
import io.quarkus.micrometer.test.PingPongResource; | ||
import io.quarkus.micrometer.test.Util; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
import io.smallrye.stork.api.observability.StorkObservation; | ||
|
||
@DisabledOnOs(OS.WINDOWS) | ||
public class StorkMetricsLoadBalancerFailTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withConfigurationResource("test-logging.properties") | ||
.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("quarkus.stork.pingpong-service.load-balancer.type", "mock") | ||
.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}") | ||
.overrideConfigKey("quarkus.stork.greeting-service.load-balancer.type", "mock") | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(PingPongResource.class, PingPongResource.PingPongRestClient.class, | ||
MockServiceSelectorProvider.class, MockServiceSelectorConfiguration.class, | ||
MockServiceSelectorProviderLoader.class, GreetingResource.class, | ||
GreetingResource.GreetingRestClient.class, Util.class)); | ||
|
||
@Inject | ||
MeterRegistry registry; | ||
|
||
@Inject | ||
MockServiceSelectorProvider provider; | ||
|
||
@Test | ||
public void shouldGetStorkMetricsWhenServiceSelectorFails() { | ||
|
||
Mockito.when(provider.getLoadBalancer().selectServiceInstance(Mockito.anyCollection())) | ||
.thenThrow(new RuntimeException("Load Balancer induced failure")); | ||
RestAssured.when().get("/ping/one").then().statusCode(500); | ||
RestAssured.when().get("/greeting/hola").then().statusCode(500); | ||
|
||
//Stork metrics | ||
assertStorkMetrics("pingpong-service"); | ||
assertStorkMetrics("greeting-service"); | ||
|
||
// Stork metrics exposed to Micrometer | ||
assertStorkMetricsInMicrometerRegistry("pingpong-service"); | ||
assertStorkMetricsInMicrometerRegistry("greeting-service"); | ||
|
||
} | ||
|
||
private static void assertStorkMetrics(String serviceName) { | ||
StorkObservation metrics = StorkObservationCollectorBean.STORK_METRICS | ||
.get(serviceName + StorkObservationCollectorBean.METRICS_SUFIX); | ||
Assertions.assertThat(metrics.getDiscoveredInstancesCount()).isEqualTo(1); | ||
Assertions.assertThat(metrics.getServiceName()).isEqualTo(serviceName); | ||
Assertions.assertThat(metrics.isDone()).isTrue(); | ||
Assertions.assertThat(metrics.isServiceDiscoverySuccessful()).isTrue(); | ||
Assertions.assertThat(metrics.failure().getMessage()) | ||
.isEqualTo("Load Balancer induced failure"); | ||
Assertions.assertThat(metrics.getOverallDuration()).isNotNull(); | ||
Assertions.assertThat(metrics.getServiceDiscoveryType()).isEqualTo("static"); | ||
Assertions.assertThat(metrics.getServiceSelectionType()).isEqualTo("mock"); | ||
Assertions.assertThat(metrics.getServiceDiscoveryDuration()).isNotNull(); | ||
Assertions.assertThat(metrics.getServiceSelectionDuration()).isNotNull(); | ||
} | ||
|
||
private void assertStorkMetricsInMicrometerRegistry(String serviceName) { | ||
Counter instanceCounter = registry.counter("stork.service-discovery.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); | ||
Counter serviceDiscoveryFailures = registry.get("stork.service-discovery.failures") | ||
.tags("service-name", serviceName).counter(); | ||
Counter loadBalancerFailures = registry.get("stork.service-selection.failures").tags("service-name", serviceName) | ||
.counter(); | ||
|
||
Util.assertTags(Tag.of("service-name", serviceName), instanceCounter, serviceDiscoveryDuration, | ||
serviceSelectionDuration); | ||
|
||
Assertions.assertThat(instanceCounter.count()).isEqualTo(1); | ||
Assertions.assertThat(loadBalancerFailures.count()).isEqualTo(1); | ||
Assertions.assertThat(serviceDiscoveryFailures.count()).isEqualTo(0); | ||
Assertions.assertThat(serviceDiscoveryDuration.totalTime(TimeUnit.NANOSECONDS)).isGreaterThan(0); | ||
Assertions.assertThat(serviceSelectionDuration.totalTime(TimeUnit.NANOSECONDS)).isGreaterThan(0); | ||
} | ||
|
||
} |
Oops, something went wrong.