Skip to content

Commit

Permalink
Rename "name" tags to be more distinguishing
Browse files Browse the repository at this point in the history
  • Loading branch information
eager-signal committed Feb 26, 2024
1 parent 60814d1 commit a7c28fe
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public CardinalityEstimator(final FaultTolerantRedisCluster redisCluster, final
this.period = period;
Metrics.gauge(
MetricsUtil.name(getClass(), "unique"),
Tags.of("name", name),
Tags.of("metricName", name),
this,
obj -> obj.uniqueElementCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public StaticRateLimiter(
this.validateScript = requireNonNull(validateScript);
this.cacheCluster = requireNonNull(cacheCluster);
this.clock = requireNonNull(clock);
this.counter = Metrics.counter(MetricsUtil.name(getClass(), "exceeded"), "name", name);
this.counter = Metrics.counter(MetricsUtil.name(getClass(), "exceeded"), "rateLimiterName", name);
this.dynamicConfigurationManager = dynamicConfigurationManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@

package org.whispersystems.textsecuregcm.metrics;

import static com.codahale.metrics.MetricRegistry.name;

import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;

import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
import java.util.List;

import static com.codahale.metrics.MetricRegistry.name;

public class BufferPoolGauges {

private BufferPoolGauges() {}

public static void registerMetrics() {
for (final BufferPoolMXBean bufferPoolMXBean : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
final List<Tag> tags = List.of(Tag.of("name", bufferPoolMXBean.getName()));
final List<Tag> tags = List.of(Tag.of("bufferPoolName", bufferPoolMXBean.getName()));

Metrics.gauge(name(BufferPoolGauges.class, "count"), tags, bufferPoolMXBean, BufferPoolMXBean::getCount);
Metrics.gauge(name(BufferPoolGauges.class, "memory_used"), tags, bufferPoolMXBean, BufferPoolMXBean::getMemoryUsed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@

package org.whispersystems.textsecuregcm.metrics;

import static com.codahale.metrics.MetricRegistry.name;

import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.util.List;

import static com.codahale.metrics.MetricRegistry.name;

public class GarbageCollectionGauges {

private GarbageCollectionGauges() {}

public static void registerMetrics() {
for (final GarbageCollectorMXBean garbageCollectorMXBean : ManagementFactory.getGarbageCollectorMXBeans()) {
final List<Tag> tags = List.of(Tag.of("name", garbageCollectorMXBean.getName()));
final List<Tag> tags = List.of(Tag.of("memoryManagerName", garbageCollectorMXBean.getName()));

Metrics.gauge(name(GarbageCollectionGauges.class, "collection_count"), tags, garbageCollectorMXBean, GarbageCollectorMXBean::getCollectionCount);
Metrics.gauge(name(GarbageCollectionGauges.class, "collection_time"), tags, garbageCollectorMXBean, GarbageCollectorMXBean::getCollectionTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public FaultTolerantPubSubConnection(final String name,

this.pubSubConnection.setNodeMessagePropagation(true);

this.executeTimer = Metrics.timer(name(getClass(), "execute"), "name", name + "-pubsub");
this.executeTimer = Metrics.timer(name(getClass(), "execute"), "clusterName", name + "-pubsub");

CircuitBreakerUtil.registerMetrics(circuitBreaker, FaultTolerantPubSubConnection.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ public class CircuitBreakerUtil {
private static final String CIRCUIT_BREAKER_STATE_GAUGE_NAME = name(CircuitBreakerUtil.class, "breaker", "state");
private static final String RETRY_CALL_COUNTER_NAME = name(CircuitBreakerUtil.class, "retry", "call");

private static final String NAME_TAG_NAME = "name";
private static final String BREAKER_NAME_TAG_NAME = "breakerName";
private static final String OUTCOME_TAG_NAME = "outcome";

public static void registerMetrics(CircuitBreaker circuitBreaker, Class<?> clazz) {
final String breakerName = clazz.getSimpleName() + "/" + circuitBreaker.getName();

final Counter successCounter = Metrics.counter(CIRCUIT_BREAKER_CALL_COUNTER_NAME,
NAME_TAG_NAME, breakerName,
BREAKER_NAME_TAG_NAME, breakerName,
OUTCOME_TAG_NAME, "success");

final Counter failureCounter = Metrics.counter(CIRCUIT_BREAKER_CALL_COUNTER_NAME,
NAME_TAG_NAME, breakerName,
BREAKER_NAME_TAG_NAME, breakerName,
OUTCOME_TAG_NAME, "failure");

final Counter unpermittedCounter = Metrics.counter(CIRCUIT_BREAKER_CALL_COUNTER_NAME,
NAME_TAG_NAME, breakerName,
BREAKER_NAME_TAG_NAME, breakerName,
OUTCOME_TAG_NAME, "unpermitted");

circuitBreaker.getEventPublisher().onSuccess(event -> {
Expand All @@ -51,27 +51,27 @@ public static void registerMetrics(CircuitBreaker circuitBreaker, Class<?> clazz
});

Metrics.gauge(CIRCUIT_BREAKER_STATE_GAUGE_NAME,
Tags.of(Tag.of(NAME_TAG_NAME, circuitBreaker.getName())),
Tags.of(Tag.of(BREAKER_NAME_TAG_NAME, circuitBreaker.getName())),
circuitBreaker, breaker -> breaker.getState().getOrder());
}

public static void registerMetrics(Retry retry, Class<?> clazz) {
final String retryName = clazz.getSimpleName() + "/" + retry.getName();

final Counter successCounter = Metrics.counter(RETRY_CALL_COUNTER_NAME,
NAME_TAG_NAME, retryName,
BREAKER_NAME_TAG_NAME, retryName,
OUTCOME_TAG_NAME, "success");

final Counter retryCounter = Metrics.counter(RETRY_CALL_COUNTER_NAME,
NAME_TAG_NAME, retryName,
BREAKER_NAME_TAG_NAME, retryName,
OUTCOME_TAG_NAME, "retry");

final Counter errorCounter = Metrics.counter(RETRY_CALL_COUNTER_NAME,
NAME_TAG_NAME, retryName,
BREAKER_NAME_TAG_NAME, retryName,
OUTCOME_TAG_NAME, "error");

final Counter ignoredErrorCounter = Metrics.counter(RETRY_CALL_COUNTER_NAME,
NAME_TAG_NAME, retryName,
BREAKER_NAME_TAG_NAME, retryName,
OUTCOME_TAG_NAME, "ignored_error");

retry.getEventPublisher().onSuccess(event -> {
Expand Down

0 comments on commit a7c28fe

Please sign in to comment.