From 80eca6489d741f564cd8fed077885183d77c6b3e Mon Sep 17 00:00:00 2001 From: Viktor Somogyi-Vass Date: Fri, 2 Oct 2026 14:43:02 +0200 Subject: [PATCH 1/2] fix(inkless:consolidation): exclude consolidation from ConsumerLag [KC-546] ConsolidationFetcherThread inherits AbstractFetcherThread lag tracking, so its diskless-to-local backlog was registered under FetcherLagMetrics.ConsumerLag alongside classic replica lag. Dashboards and scrapers that sum that metric then treat consolidation backlog as replica catch-up. Skip only the ConsumerLag JMX gauge for consolidation fetchers while keeping in-memory fetcherLagStats for MaxLag. ConsolidationLocalLag remains the external first-hop lag signal. Test plan - :core:test AbstractFetcherThreadTest, ReplicaFetcherThreadTest, ConsolidationFetcherThreadTest - spotlessCheck; vale on the added prose Assisted-by: Composer --- INKLESS_OWNERSHIP | 1 + .../ConsolidationFetcherThread.scala | 4 ++++ .../kafka/server/AbstractFetcherThread.scala | 22 ++++++++++++++----- .../ConsolidationFetcherThreadTest.scala | 19 ++++++++++++++++ docs/inkless/DISKLESS_CONSOLIDATION.md | 2 ++ 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/INKLESS_OWNERSHIP b/INKLESS_OWNERSHIP index 31d2168076..53f45a4821 100644 --- a/INKLESS_OWNERSHIP +++ b/INKLESS_OWNERSHIP @@ -61,3 +61,4 @@ core/src/main/scala/kafka/server/DelayedFetch.scala @aiven/inkless @apach core/src/main/scala/kafka/server/DynamicBrokerConfig.scala @aiven/inkless @apache/kafka # dynamic inkless config reconfig core/src/main/scala/kafka/server/ConfigHandler.scala @aiven/inkless @apache/kafka # topic-config propagation core/src/main/scala/kafka/server/ControllerServer.scala @aiven/inkless @apache/kafka # controller-side diskless wiring +core/src/main/scala/kafka/server/AbstractFetcherThread.scala @aiven/inkless @apache/kafka # consolidation fetcher skips ConsumerLag JMX registration diff --git a/core/src/main/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThread.scala b/core/src/main/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThread.scala index 3acce25109..328e2a139f 100644 --- a/core/src/main/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThread.scala +++ b/core/src/main/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThread.scala @@ -50,6 +50,10 @@ class ConsolidationFetcherThread(name: String, override protected def shouldRecordReplicationBytesIn: Boolean = false + // ConsolidationLocalLag is the external first-hop lag signal. Keep updating + // fetcherLagStats for MaxLag, but do not register the generic ConsumerLag JMX gauge. + override protected def registerFetcherConsumerLagMetrics: Boolean = false + override def processPartitionData( topicPartition: TopicPartition, fetchOffset: Long, diff --git a/core/src/main/scala/kafka/server/AbstractFetcherThread.scala b/core/src/main/scala/kafka/server/AbstractFetcherThread.scala index 48b5e48cec..011277503d 100755 --- a/core/src/main/scala/kafka/server/AbstractFetcherThread.scala +++ b/core/src/main/scala/kafka/server/AbstractFetcherThread.scala @@ -72,7 +72,12 @@ abstract class AbstractFetcherThread(name: String, private val metricId = new ClientIdAndBroker(clientId, leader.brokerEndPoint().host, leader.brokerEndPoint().port) val fetcherStats = new FetcherStats(metricId) - val fetcherLagStats = new FetcherLagStats(metricId) + val fetcherLagStats = new FetcherLagStats(metricId, registerFetcherConsumerLagMetrics) + + // When false, keep updating in-memory fetcherLagStats for MaxLag but skip the + // kafka.server:FetcherLagMetrics/ConsumerLag JMX gauge. ConsolidationFetcherThread + // overrides this so ConsolidationLocalLag is the external consolidation lag signal. + protected def registerFetcherConsumerLagMetrics: Boolean = true /* callbacks to be defined in subclass */ @@ -923,7 +928,7 @@ object FetcherMetrics { val BytesPerSec = "BytesPerSec" } -class FetcherLagMetrics(metricId: ClientIdTopicPartition) { +class FetcherLagMetrics(metricId: ClientIdTopicPartition, registerConsumerLag: Boolean = true) { // Changing the package or class name may cause incompatibility with existing code and metrics configuration private val metricsPackage = "kafka.server" private val metricsClassName = "FetcherLagMetrics" @@ -935,7 +940,9 @@ class FetcherLagMetrics(metricId: ClientIdTopicPartition) { "topic" -> metricId.topicPartition.topic, "partition" -> metricId.topicPartition.partition.toString).asJava - metricsGroup.newGauge(FetcherMetrics.ConsumerLag, () => lagVal.get, tags) + if (registerConsumerLag) { + metricsGroup.newGauge(FetcherMetrics.ConsumerLag, () => lagVal.get, tags) + } def lag_=(newLag: Long): Unit = { lagVal.set(newLag) @@ -944,15 +951,18 @@ class FetcherLagMetrics(metricId: ClientIdTopicPartition) { def lag: Long = lagVal.get def unregister(): Unit = { - metricsGroup.removeMetric(FetcherMetrics.ConsumerLag, tags) + if (registerConsumerLag) { + metricsGroup.removeMetric(FetcherMetrics.ConsumerLag, tags) + } } } -class FetcherLagStats(metricId: ClientIdAndBroker) { +class FetcherLagStats(metricId: ClientIdAndBroker, registerConsumerLag: Boolean = true) { val stats = new ConcurrentHashMap[TopicPartition, FetcherLagMetrics] def getAndMaybePut(topicPartition: TopicPartition): FetcherLagMetrics = { - stats.computeIfAbsent(topicPartition, k => new FetcherLagMetrics(ClientIdTopicPartition(metricId.clientId, k))) + stats.computeIfAbsent(topicPartition, k => + new FetcherLagMetrics(ClientIdTopicPartition(metricId.clientId, k), registerConsumerLag)) } def unregister(topicPartition: TopicPartition): Unit = { diff --git a/core/src/test/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThreadTest.scala b/core/src/test/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThreadTest.scala index 07cbfdac51..f884084fa3 100644 --- a/core/src/test/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThreadTest.scala +++ b/core/src/test/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThreadTest.scala @@ -408,6 +408,25 @@ class ConsolidationFetcherThreadTest { assertEquals(50L, findGaugeValue("ConsolidationDeletableMessages", topicPartition)) } + @Test + def testTracksFetcherLagWithoutRegisteringConsumerLag(): Unit = { + val partition = mockPartitionWithLog(80L, 60L) + val replicaManager = mockReplicaManager(partition) + val thread = createConsolidationFetcherThread(replicaManager, Some(metrics)) + + val lagMetrics = thread.fetcherLagStats.getAndMaybePut(topicPartition) + lagMetrics.lag = 42L + + assertEquals(42L, thread.fetcherLagStats.stats.get(topicPartition).lag) + assertFalse( + KafkaYammerMetrics.defaultRegistry.allMetrics.asScala.keys.exists { metricName => + metricName.getGroup == "kafka.server" && + metricName.getType == "FetcherLagMetrics" && + metricName.getName == FetcherMetrics.ConsumerLag + }, + "ConsolidationFetcherThread must not register the generic FetcherLagMetrics.ConsumerLag JMX gauge") + } + @Test def testRecordsConsolidationFetchBytesInAndSkipsReplicationBytesIn(): Unit = { val validBytes = 512 diff --git a/docs/inkless/DISKLESS_CONSOLIDATION.md b/docs/inkless/DISKLESS_CONSOLIDATION.md index e939743cc0..ff98c3f361 100644 --- a/docs/inkless/DISKLESS_CONSOLIDATION.md +++ b/docs/inkless/DISKLESS_CONSOLIDATION.md @@ -373,6 +373,8 @@ The broker registers these under the `io.aiven.inkless.consolidation` group. The | `io.aiven.inkless.cache:type=CrossTierLogStartCache` | `CacheHits` / `CacheMisses` / `CacheSize` | Cross-tier earliest-offset cache. | | controller | `DisklessWithoutRemoteStorageCount` | Diskless topics where `remote.storage.enable` is `false` or unset, including born-diskless topics that never enter the `Failed` reconciler state. | +Consolidation fetchers report first-hop lag through `ConsolidationLocalLag`. They do not contribute to Kafka's generic `kafka.server:type=FetcherLagMetrics,name=ConsumerLag` metric, so replica catch-up dashboards that sum that metric exclude consolidation backlog. + ## Compatibility - **Produce / consume / replication**: Standard Kafka client APIs. A consolidated topic behaves like a tiered topic for clients. From af0657fb6b9f56edfe5537ebd69da035207a73a9 Mon Sep 17 00:00:00 2001 From: Viktor Somogyi-Vass Date: Fri, 2 Oct 2026 15:39:45 +0200 Subject: [PATCH 2/2] Refine comments in ConsolidationFetcherThread Updated comments for clarity and consistency. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../inkless/consolidation/ConsolidationFetcherThread.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThread.scala b/core/src/main/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThread.scala index 328e2a139f..db32557a1e 100644 --- a/core/src/main/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThread.scala +++ b/core/src/main/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThread.scala @@ -50,8 +50,8 @@ class ConsolidationFetcherThread(name: String, override protected def shouldRecordReplicationBytesIn: Boolean = false - // ConsolidationLocalLag is the external first-hop lag signal. Keep updating - // fetcherLagStats for MaxLag, but do not register the generic ConsumerLag JMX gauge. + // `ConsolidationLocalLag` is the external first-hop lag signal. Keep updating + // `fetcherLagStats` for `MaxLag`, but don't register the generic `ConsumerLag` JMX gauge. override protected def registerFetcherConsumerLagMetrics: Boolean = false override def processPartitionData(