Skip to content

Commit

Permalink
Test with a few stork services configured and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
aureamunoz committed Sep 26, 2023
1 parent 95c6a3d commit 531532c
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,7 +28,6 @@
import io.smallrye.mutiny.Uni;
import io.smallrye.stork.api.observability.ObservationPoints;

@DisabledOnOs(OS.WINDOWS)
public class StorkMetricsServiceDiscoveryFailTest {

@RegisterExtension
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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<Meter> collect = registry.getMeters().stream().filter(meter -> meter.getId().getTags().contains()).collect(Collectors.toList());
//
// Optional<Meter> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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!");
}
Expand Down
Loading

0 comments on commit 531532c

Please sign in to comment.