From 3f6629fae8f41fdf8c24b6ddd752b8cae7f74a74 Mon Sep 17 00:00:00 2001 From: Xiaodan Date: Tue, 23 Jul 2024 14:33:17 -0700 Subject: [PATCH] add cycle start time and end time to consumer metrics --- .../api/client/HollowClientUpdater.java | 3 +++ .../api/metrics/HollowConsumerMetrics.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/hollow/src/main/java/com/netflix/hollow/api/client/HollowClientUpdater.java b/hollow/src/main/java/com/netflix/hollow/api/client/HollowClientUpdater.java index c70ce519d9..82590dd3f4 100644 --- a/hollow/src/main/java/com/netflix/hollow/api/client/HollowClientUpdater.java +++ b/hollow/src/main/java/com/netflix/hollow/api/client/HollowClientUpdater.java @@ -117,6 +117,7 @@ public synchronized boolean updateTo(long requestedVersion) throws Throwable { return updateTo(new HollowConsumer.VersionInfo(requestedVersion)); } public synchronized boolean updateTo(HollowConsumer.VersionInfo requestedVersionInfo) throws Throwable { + metrics.setLastRefreshStartNs(System.nanoTime()); long requestedVersion = requestedVersionInfo.getVersion(); if (requestedVersion == getCurrentVersionId()) { if (requestedVersion == HollowConstants.VERSION_NONE && hollowDataHolderVolatile == null) { @@ -205,6 +206,7 @@ public synchronized boolean updateTo(HollowConsumer.VersionInfo requestedVersion metricsCollector.collect(metrics); initialLoad.complete(getCurrentVersionId()); // only set the first time + metrics.setLastRefreshEndNs(System.nanoTime()); return getCurrentVersionId() == requestedVersion; } catch(Throwable th) { forceDoubleSnapshotNextUpdate(); @@ -216,6 +218,7 @@ public synchronized boolean updateTo(HollowConsumer.VersionInfo requestedVersion // intentionally omitting a call to initialLoad.completeExceptionally(th), for producers // that write often a consumer has a chance to try another snapshot that might succeed + metrics.setLastRefreshEndNs(System.nanoTime()); throw th; } diff --git a/hollow/src/main/java/com/netflix/hollow/api/metrics/HollowConsumerMetrics.java b/hollow/src/main/java/com/netflix/hollow/api/metrics/HollowConsumerMetrics.java index 4cc2cb1da0..e63d993636 100644 --- a/hollow/src/main/java/com/netflix/hollow/api/metrics/HollowConsumerMetrics.java +++ b/hollow/src/main/java/com/netflix/hollow/api/metrics/HollowConsumerMetrics.java @@ -18,9 +18,31 @@ import com.netflix.hollow.core.read.engine.HollowReadStateEngine; +import java.util.concurrent.atomic.AtomicLong; + public class HollowConsumerMetrics extends HollowMetrics { private int refreshFailed; // TODO: Move these metrics over to com.netflix.hollow.api.consumer.metrics.AbstractRefreshMetricsListener private int refreshSucceeded; + private final AtomicLong lastRefreshStartNs = new AtomicLong(); //last time a refresh started + private final AtomicLong lastRefreshEndNs = new AtomicLong(); + + public void setLastRefreshStartNs(long startNs) { + lastRefreshStartNs.set(startNs); + } + + public AtomicLong getLastRefreshStartNs() { + return lastRefreshStartNs; + } + + public void setLastRefreshEndNs(long endNs) { + lastRefreshEndNs.set(endNs); + } + + public AtomicLong getLastRefreshEndNs() { + return lastRefreshEndNs; + } + + /** * Updates the consumer metrics: