diff --git a/hollow/src/main/java/com/netflix/hollow/api/producer/AbstractHollowProducer.java b/hollow/src/main/java/com/netflix/hollow/api/producer/AbstractHollowProducer.java index e3127b645b..35f33e8889 100644 --- a/hollow/src/main/java/com/netflix/hollow/api/producer/AbstractHollowProducer.java +++ b/hollow/src/main/java/com/netflix/hollow/api/producer/AbstractHollowProducer.java @@ -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 } } } diff --git a/hollow/src/main/java/com/netflix/hollow/api/producer/metrics/AbstractProducerMetricsListener.java b/hollow/src/main/java/com/netflix/hollow/api/producer/metrics/AbstractProducerMetricsListener.java index 33c6430a8b..8dce80ad63 100644 --- a/hollow/src/main/java/com/netflix/hollow/api/producer/metrics/AbstractProducerMetricsListener.java +++ b/hollow/src/main/java/com/netflix/hollow/api/producer/metrics/AbstractProducerMetricsListener.java @@ -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; @@ -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()); } diff --git a/hollow/src/main/java/com/netflix/hollow/api/producer/metrics/AnnouncementMetrics.java b/hollow/src/main/java/com/netflix/hollow/api/producer/metrics/AnnouncementMetrics.java index 4441509b97..644384e891 100644 --- a/hollow/src/main/java/com/netflix/hollow/api/producer/metrics/AnnouncementMetrics.java +++ b/hollow/src/main/java/com/netflix/hollow/api/producer/metrics/AnnouncementMetrics.java @@ -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; @@ -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; @@ -55,6 +59,7 @@ 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 { @@ -62,11 +67,13 @@ public static final class Builder { private long announcementDurationMillis; private boolean isAnnouncementSuccess; private OptionalLong lastAnnouncementSuccessTimeNano; + private OptionalLong deltaChainVersionCounter; private Map numShardsPerType; private Map shardSizePerType; public Builder() { lastAnnouncementSuccessTimeNano = OptionalLong.empty(); + deltaChainVersionCounter = OptionalLong.empty(); } public Builder setDataSizeBytes(long dataSizeBytes) { @@ -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); diff --git a/hollow/src/test/java/com/netflix/hollow/api/producer/metrics/AbstractProducerMetricsListenerTest.java b/hollow/src/test/java/com/netflix/hollow/api/producer/metrics/AbstractProducerMetricsListenerTest.java index 87d8060036..0d9cef4b9a 100644 --- a/hollow/src/test/java/com/netflix/hollow/api/producer/metrics/AbstractProducerMetricsListenerTest.java +++ b/hollow/src/test/java/com/netflix/hollow/api/producer/metrics/AbstractProducerMetricsListenerTest.java @@ -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; @@ -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) { @@ -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()); } } @@ -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()); } }