Skip to content

Commit

Permalink
Merge pull request #438 from zalando/feature/metrics
Browse files Browse the repository at this point in the history
Introduced Metrics factory for starter
  • Loading branch information
whiskeysierra authored Jul 13, 2018
2 parents c80025b + 9f57970 commit 26ec5f4
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
@API(status = EXPERIMENTAL)
public final class MetricsCircuitBreakerListener implements CircuitBreakerListener {

public static final String METRIC_NAME = "http.client.circuit-breakers";

private final MeterRegistry registry;
private final String metricName;
private final ImmutableList<Tag> defaultTags;
Expand All @@ -32,7 +30,7 @@ public final class MetricsCircuitBreakerListener implements CircuitBreakerListen
private final AtomicReference<Sample> sample;

public MetricsCircuitBreakerListener(final MeterRegistry registry) {
this(registry, METRIC_NAME, ImmutableList.of());
this(registry, "http.client.circuit-breakers", ImmutableList.of());
}

@API(status = INTERNAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
@API(status = EXPERIMENTAL)
public final class MetricsRetryListener implements RetryListener {

public static final String METRIC_NAME = "http.client.retries";

private final MeterRegistry registry;
private final String metricName;
private final ImmutableList<Tag> defaultTags;
private final TagGenerator generator = new DefaultTagGenerator();

public MetricsRetryListener(final MeterRegistry registry) {
this(registry, METRIC_NAME, ImmutableList.of());
this(registry, "http.client.retries", ImmutableList.of());
}

private MetricsRetryListener(final MeterRegistry registry, final String metricName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
@API(status = EXPERIMENTAL)
public final class MetricsPlugin implements Plugin {

public static final String METRIC_NAME = "http.client.requests";

private final MeterRegistry registry;
private final String metricName;
private final ImmutableList<Tag> defaultTags;
private final Clock clock;
private final TagGenerator generator = new DefaultTagGenerator();

public MetricsPlugin(final MeterRegistry registry) {
this(registry, METRIC_NAME, ImmutableList.of());
this(registry, "http.client.requests", ImmutableList.of());
}

private MetricsPlugin(final MeterRegistry registry, final String metricName, final ImmutableList<Tag> defaultTags) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import org.zalando.riptide.metrics.MetricsPlugin;
import org.zalando.riptide.spring.RiptideProperties.Client;
import org.zalando.riptide.spring.RiptideProperties.Client.Keystore;
import org.zalando.riptide.failsafe.metrics.MetricsCircuitBreakerListener;
import org.zalando.riptide.failsafe.metrics.MetricsRetryListener;
import org.zalando.riptide.stream.Streams;
import org.zalando.riptide.timeout.TimeoutPlugin;
import org.zalando.stups.oauth2.httpcomponents.AccessTokensRequestInterceptor;
Expand Down Expand Up @@ -223,9 +221,9 @@ private List<String> registerPlugins(final String id, final Client client) {
if (client.getRecordMetrics()) {
log.debug("Client [{}]: Registering [{}]", id, MetricsPlugin.class.getSimpleName());
plugins.add(registry.registerIfAbsent(id, MetricsPlugin.class, () ->
genericBeanDefinition(MetricsPlugin.class)
genericBeanDefinition(Metrics.class)
.setFactoryMethod("createMetricsPlugin")
.addConstructorArgReference("meterRegistry")
.addConstructorArgValue(MetricsPlugin.METRIC_NAME)
.addConstructorArgValue(ImmutableList.of(clientId(id)))));
}

Expand Down Expand Up @@ -339,13 +337,13 @@ private String registerCircuitBreaker(final String id, final Client client) {
circuitBreaker.addPropertyReference("listener",
registry.registerIfAbsent(id, CircuitBreakerListener.class, () -> {
if (client.getRecordMetrics()) {
return genericBeanDefinition(MetricsCircuitBreakerListener.class)
return genericBeanDefinition(Metrics.class)
.setFactoryMethod("createCircuitBreakerListener")
.addConstructorArgReference("meterRegistry")
.addConstructorArgValue(MetricsCircuitBreakerListener.METRIC_NAME)
.addConstructorArgValue(ImmutableList.of(clientId(id), clientName(id, client)));
} else {
return genericBeanDefinition(CircuitBreakerListeners.class)
.setFactoryMethod("getDefault");
return genericBeanDefinition(Metrics.class)
.setFactoryMethod("getDefaultCircuitBreakerListener");
}
}));
}
Expand All @@ -357,13 +355,13 @@ private String registerCircuitBreaker(final String id, final Client client) {
private String registerRetryListener(final String id, final Client client) {
return registry.registerIfAbsent(id, RetryListener.class, () -> {
if (client.getRecordMetrics()) {
return genericBeanDefinition(MetricsRetryListener.class)
return genericBeanDefinition(Metrics.class)
.setFactoryMethod("createRetryListener")
.addConstructorArgReference("meterRegistry")
.addConstructorArgValue(MetricsRetryListener.METRIC_NAME)
.addConstructorArgValue(ImmutableList.of(clientId(id)));
} else {
return genericBeanDefinition(RetryListeners.class)
.setFactoryMethod("getDefault");
return genericBeanDefinition(Metrics.class)
.setFactoryMethod("getDefaultRetryListener");
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.zalando.riptide.spring;

import com.google.common.collect.ImmutableList;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import org.zalando.riptide.Plugin;
import org.zalando.riptide.failsafe.CircuitBreakerListener;
import org.zalando.riptide.failsafe.RetryListener;
import org.zalando.riptide.failsafe.metrics.MetricsCircuitBreakerListener;
import org.zalando.riptide.failsafe.metrics.MetricsRetryListener;
import org.zalando.riptide.metrics.MetricsPlugin;

final class Metrics {

private Metrics() {

}

public static Plugin createMetricsPlugin(final MeterRegistry registry,
final ImmutableList<Tag> tags) {
return new MetricsPlugin(registry).withDefaultTags(tags);
}

public static CircuitBreakerListener createCircuitBreakerListener(final MeterRegistry registry,
final ImmutableList<Tag> defaultTags) {
return new MetricsCircuitBreakerListener(registry).withDefaultTags(defaultTags);
}

public static CircuitBreakerListener getDefaultCircuitBreakerListener() {
return CircuitBreakerListener.DEFAULT;
}

public static RetryListener createRetryListener(final MeterRegistry registry,
final ImmutableList<Tag> defaultTags) {
return new MetricsRetryListener(registry).withDefaultTags(defaultTags);
}

public static RetryListener getDefaultRetryListener() {
return RetryListener.DEFAULT;
}
}

This file was deleted.

0 comments on commit 26ec5f4

Please sign in to comment.