Skip to content

Commit

Permalink
Producer- report metric for delta chain version counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunjeet committed Nov 5, 2024
1 parent dd2db6a commit 66d570c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ private void updateHeaderTags(HollowWriteStateEngine writeEngine, long toVersion
try {
prevDeltaChainVersionCounter = Long.valueOf(str);
} catch (NumberFormatException e) {
prevDeltaChainVersionCounter = 0;
// ignore, prevDeltaChainVersionCounter remains 0
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.netflix.hollow.api.producer.AbstractHollowProducerListener;
import com.netflix.hollow.api.producer.HollowProducer;
import com.netflix.hollow.core.HollowStateEngine;
import com.netflix.hollow.core.read.engine.HollowReadStateEngine;
import java.time.Duration;
import java.util.Map;
Expand Down Expand Up @@ -99,6 +100,15 @@ public void onAnnouncementComplete(com.netflix.hollow.api.producer.Status status
.setAnnouncementDurationMillis(elapsed.toMillis());
lastAnnouncementSuccessTimeNanoOptional.ifPresent(announcementMetricsBuilder::setLastAnnouncementSuccessTimeNano);

if (stateEngine.getHeaderTag(HollowStateEngine.HEADER_TAG_DELTA_CHAIN_VERSION_COUNTER) != null) {
try {
long deltaChainVersionCounter = Long.parseLong(stateEngine.getHeaderTag(HollowStateEngine.HEADER_TAG_DELTA_CHAIN_VERSION_COUNTER));
announcementMetricsBuilder.setDeltaChainVersionCounter(deltaChainVersionCounter);
} catch (NumberFormatException e) {
// ignore
}
}

announcementMetricsReporting(announcementMetricsBuilder.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AnnouncementMetrics {
private long announcementDurationMillis; // Announcement duration in ms, only applicable to completed cycles (skipped cycles dont announce)
private boolean isAnnouncementSuccess; // true if announcement was successful, false if announcement failed
private OptionalLong lastAnnouncementSuccessTimeNano; // monotonic time of last successful announcement (no relation to wall clock), N/A until first successful announcement

private OptionalLong deltaChainVersionCounter;

public long getDataSizeBytes() {
return dataSizeBytes;
Expand All @@ -47,6 +47,10 @@ public boolean getIsAnnouncementSuccess() {
public OptionalLong getLastAnnouncementSuccessTimeNano() {
return lastAnnouncementSuccessTimeNano;
}
public OptionalLong getDeltaChainVersionCounter() {
return deltaChainVersionCounter;
}


private AnnouncementMetrics(Builder builder) {
this.dataSizeBytes = builder.dataSizeBytes;
Expand All @@ -55,18 +59,21 @@ private AnnouncementMetrics(Builder builder) {
this.announcementDurationMillis = builder.announcementDurationMillis;
this.isAnnouncementSuccess = builder.isAnnouncementSuccess;
this.lastAnnouncementSuccessTimeNano = builder.lastAnnouncementSuccessTimeNano;
this.deltaChainVersionCounter = builder.deltaChainVersionCounter;
}

public static final class Builder {
private long dataSizeBytes;
private long announcementDurationMillis;
private boolean isAnnouncementSuccess;
private OptionalLong lastAnnouncementSuccessTimeNano;
private OptionalLong deltaChainVersionCounter;
private Map<String, Integer> numShardsPerType;
private Map<String, Long> shardSizePerType;

public Builder() {
lastAnnouncementSuccessTimeNano = OptionalLong.empty();
deltaChainVersionCounter = OptionalLong.empty();
}

public Builder setDataSizeBytes(long dataSizeBytes) {
Expand All @@ -93,6 +100,10 @@ public Builder setLastAnnouncementSuccessTimeNano(long lastAnnouncementSuccessTi
this.lastAnnouncementSuccessTimeNano = OptionalLong.of(lastAnnouncementSuccessTimeNano);
return this;
}
public Builder setDeltaChainVersionCounter(long deltaChainVersionCounter) {
this.deltaChainVersionCounter = OptionalLong.of(deltaChainVersionCounter);
return this;
}

public AnnouncementMetrics build() {
return new AnnouncementMetrics(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.netflix.hollow.api.producer.metrics;

import static com.netflix.hollow.core.HollowStateEngine.HEADER_TAG_DELTA_CHAIN_VERSION_COUNTER;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

import com.netflix.hollow.api.producer.HollowProducer;
Expand Down Expand Up @@ -114,6 +116,7 @@ public void cycleMetricsReporting(CycleMetrics cycleMetrics) {

@Test
public void testAnnouncementCompleteWithSuccess() {
when(mockStateEngine.getHeaderTag(eq(HEADER_TAG_DELTA_CHAIN_VERSION_COUNTER))).thenReturn("1");
final class TestProducerMetricsListener extends AbstractProducerMetricsListener {
@Override
public void announcementMetricsReporting(AnnouncementMetrics announcementMetrics) {
Expand All @@ -124,6 +127,8 @@ public void announcementMetricsReporting(AnnouncementMetrics announcementMetrics
announcementMetrics.getAnnouncementDurationMillis());
Assert.assertNotEquals(OptionalLong.of(TEST_LAST_ANNOUNCEMENT_NANOS),
announcementMetrics.getLastAnnouncementSuccessTimeNano());
Assert.assertEquals(OptionalLong.of(1l),
announcementMetrics.getDeltaChainVersionCounter());
}
}

Expand All @@ -146,6 +151,8 @@ public void announcementMetricsReporting(AnnouncementMetrics announcementMetrics
announcementMetrics.getAnnouncementDurationMillis());
Assert.assertEquals(OptionalLong.of(TEST_LAST_ANNOUNCEMENT_NANOS),
announcementMetrics.getLastAnnouncementSuccessTimeNano());
Assert.assertEquals(OptionalLong.empty(),
announcementMetrics.getDeltaChainVersionCounter());
}
}

Expand Down

0 comments on commit 66d570c

Please sign in to comment.