Skip to content

Commit

Permalink
Adjust StorkMetricsTest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcruzdev committed Jun 20, 2024
1 parent 0b5d623 commit 25cebef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ public void shouldGetStorkMetricsForTwoServicesWhenEverythingSucceded() {
}

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();
Counter serviceDiscoveryFailures = registry.counter("stork.service-discovery.failures", "service-name", serviceName);
Counter loadBalancerFailures = registry.counter("stork.service-selection.failures", "service-name", serviceName);

Util.assertTags(Tag.of("service-name", serviceName), instanceCounter, serviceDiscoveryDuration,
serviceSelectionDuration);
Expand All @@ -81,6 +80,7 @@ private void assertStorkMetricsInMicrometerRegistry(String serviceName) {
public static void assertStorkMetrics(String serviceName) {
StorkObservation metrics = StorkObservationCollectorBean.STORK_METRICS
.get(serviceName + StorkObservationCollectorBean.METRICS_SUFFIX);

Assertions.assertThat(metrics.getDiscoveredInstancesCount()).isEqualTo(1);
Assertions.assertThat(metrics.getServiceName()).isEqualTo(serviceName);
Assertions.assertThat(metrics.isDone()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,25 @@ public class StorkObservationCollectorBean implements ObservationCollector, Stor

public static final String METRICS_SUFFIX = "-metrics";
final MeterRegistry registry = Metrics.globalRegistry;
private final Meter.MeterProvider<Timer> serviceDiscoveryTimer;
public final static Map<String, StorkObservation> STORK_METRICS = new ConcurrentHashMap<>();
private final Meter.MeterProvider<Counter> instanceCounter;
private final Meter.MeterProvider<Timer> serviceDiscoveryTimer;
private final Meter.MeterProvider<Timer> serviceSelectionTimer;
private final Meter.MeterProvider<Counter> serviceDiscoveryFailures;
private final Meter.MeterProvider<Counter> serviceSelectionFailures;

public StorkObservationCollectorBean() {
this.serviceDiscoveryTimer = Timer
.builder("stork.service-discovery.duration")
.description("The duration of the discovery operation")
.withRegistry(registry);

this.instanceCounter = Counter
.builder("stork.service-discovery.instances.count")
.description("The number of service instances discovered")
.withRegistry(registry);

this.serviceDiscoveryTimer = Timer
.builder("stork.service-discovery.duration")
.description("The duration of the discovery operation")
.withRegistry(registry);

this.serviceSelectionTimer = Timer
.builder("stork.service-selection.duration")
.description("The duration of the selection operation ")
Expand Down Expand Up @@ -78,9 +79,9 @@ public void complete(StorkObservation observation) {

if (observation.failure() != null) {
if (observation.isServiceDiscoverySuccessful()) {
this.serviceSelectionFailures.withTags().increment();
this.serviceSelectionFailures.withTags(tags).increment();
} else {// SD failure
this.serviceDiscoveryFailures.withTags().increment();
this.serviceDiscoveryFailures.withTags(tags).increment();
}
}

Expand Down

0 comments on commit 25cebef

Please sign in to comment.