Skip to content

Commit

Permalink
add cycle start time and end time to consumer metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
workeatsleep committed Jul 23, 2024
1 parent 63d369b commit 3f6629f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3f6629f

Please sign in to comment.