Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicLong;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.hypertrace.core.documentstore.Datastore;
import org.hypertrace.core.documentstore.metric.DocStoreMetric;
import org.hypertrace.core.documentstore.metric.DocStoreMetricProvider;
import org.hypertrace.core.serviceframework.metrics.Measurement;
import org.hypertrace.core.serviceframework.metrics.PlatformMetricsRegistry;
import org.hypertrace.core.serviceframework.metrics.ResizeableGauge;
import org.hypertrace.core.serviceframework.spi.PlatformServiceLifecycle;

Expand Down Expand Up @@ -97,7 +95,6 @@ public void monitor() {

addShutdownHook();

new StandardDocStoreMetricsRegistry().monitor();
monitorCustomMetrics();
}

Expand Down Expand Up @@ -158,36 +155,4 @@ private void report(
log.warn("Unable to report custom database metric for config: {}", reportingConfig, e);
}
}

private class StandardDocStoreMetricsRegistry {
private final AtomicLong connectionCount;

public StandardDocStoreMetricsRegistry() {
this.connectionCount = registerConnectionCountMetric();
}

private void monitor() {
executor.scheduleAtFixedRate(
this::queryDocStoreAndSetMetricValues,
INITIAL_DELAY_SECONDS,
standardMetricsReportingInterval.toSeconds(),
SECONDS);
}

private AtomicLong registerConnectionCountMetric() {
final DocStoreMetric docStoreMetric = metricProvider.getConnectionCountMetric();
return PlatformMetricsRegistry.registerGauge(
docStoreMetric.name(),
docStoreMetric.labels(),
new AtomicLong(castToLong(docStoreMetric.value())));
}

private void queryDocStoreAndSetMetricValues() {
connectionCount.set(castToLong(metricProvider.getConnectionCountMetric().value()));
}

private long castToLong(final double value) {
return Double.valueOf(value).longValue();
}
}
}
Loading