Skip to content

Commit

Permalink
register gauge based on state object
Browse files Browse the repository at this point in the history
  • Loading branch information
moscicky committed Aug 6, 2024
1 parent 8508771 commit cd1d2e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

import io.micrometer.core.instrument.MeterRegistry;

import java.util.function.ToDoubleFunction;


public class ConsistencyMetrics {
private final MeterRegistry meterRegistry;

ConsistencyMetrics(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;

}

public <T> void registerStorageConsistencyGauge(boolean isStorageConsistent) {
double value = isStorageConsistent ? 1 : 0;
meterRegistry.gauge("storage.consistency", value);
public <T> void registerStorageConsistencyGauge(T stateObject, ToDoubleFunction<T> valueFunction) {
meterRegistry.gauge("storage.consistency", stateObject, valueFunction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;

import static java.util.Collections.emptyList;
Expand All @@ -52,7 +53,7 @@ public class DcConsistencyService {
private final List<DatacenterBoundRepositoryHolder<TopicRepository>> topicRepositories;
private final List<DatacenterBoundRepositoryHolder<SubscriptionRepository>> subscriptionRepositories;
private final ObjectMapper objectMapper;
private final MetricsFacade metricsFacade;
private final AtomicBoolean isStorageConsistent = new AtomicBoolean(true);

public DcConsistencyService(RepositoryManager repositoryManager,
ObjectMapper objectMapper,
Expand All @@ -62,7 +63,6 @@ public DcConsistencyService(RepositoryManager repositoryManager,
this.topicRepositories = repositoryManager.getRepositories(TopicRepository.class);
this.subscriptionRepositories = repositoryManager.getRepositories(SubscriptionRepository.class);
this.objectMapper = objectMapper;
this.metricsFacade = metricsFacade;
this.executor = Executors.newFixedThreadPool(
properties.getThreadPoolSize(),
new ThreadFactoryBuilder()
Expand All @@ -79,6 +79,7 @@ public DcConsistencyService(RepositoryManager repositoryManager,
properties.getInitialRefreshDelay().getSeconds(),
properties.getRefreshInterval().getSeconds(),
TimeUnit.SECONDS);
metricsFacade.consistency().registerStorageConsistencyGauge(isStorageConsistent, isConsistent -> isConsistent.get() ? 1 : 0);
}
}

Expand All @@ -94,7 +95,7 @@ private void reportConsistency() {
List<InconsistentGroup> inconsistentGroups = listInconsistentGroups(groups);
long durationSeconds = (System.currentTimeMillis() - start) / 1000;
logger.info("Consistency check finished in {}s, number of inconsistent groups: {}", durationSeconds, inconsistentGroups.size());
metricsFacade.consistency().registerStorageConsistencyGauge(inconsistentGroups.isEmpty());
isStorageConsistent.set(inconsistentGroups.isEmpty());
}

public List<InconsistentGroup> listInconsistentGroups(Set<String> groupNames) {
Expand Down

0 comments on commit cd1d2e5

Please sign in to comment.