dariuszseweryn opened a new pull request, #10934: URL: https://github.com/apache/nifi/pull/10934
<!-- Licensed to the Apache Software Foundation (ASF) under one or more --> <!-- contributor license agreements. See the NOTICE file distributed with --> <!-- this work for additional information regarding copyright ownership. --> <!-- The ASF licenses this file to You under the Apache License, Version 2.0 --> <!-- (the "License"); you may not use this file except in compliance with --> <!-- the License. You may obtain a copy of the License at --> <!-- http://www.apache.org/licenses/LICENSE-2.0 --> <!-- Unless required by applicable law or agreed to in writing, software --> <!-- distributed under the License is distributed on an "AS IS" BASIS, --> <!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --> <!-- See the License for the specific language governing permissions and --> <!-- limitations under the License. --> # Summary [NIFI-00000](https://issues.apache.org/jira/browse/NIFI-00000) As of NIFI-15545, the KafkaConsumerService exposes a currentLag(TopicPartitionSummary) method that returns the current consumer lag (in records) for a given topic-partition. However, this information is not currently utilized by the ConsumeKafka processor. This ticket adds gauge metric recording to ConsumeKafka so that per-partition consumer lag is reported through the NiFi metrics framework via ProcessSession.recordGauge(). This enables operators to monitor consumer lag through any configured ComponentMetricReporter (e.g., OpenTelemetry). ## Changes: - OffsetTracker: Added getTrackedPartitions() method to expose the set of TopicPartitionSummary keys accumulated during consumption. - ConsumeKafka: After the poll loop completes and before the session is committed, the processor queries KafkaConsumerService.currentLag() for each tracked topic-partition and records a gauge with CommitTiming.SESSION_COMMITTED. ## Gauge naming format: consumer.lag[topic="<topic>",partition="<partition>"] For example: consumer.lag[topic="orders",partition="3"] ## Behavior: One gauge is recorded per topic-partition that was consumed during the onTrigger invocation. Gauges are only emitted when currentLag returns a value (it may be unavailable in some Kafka client states). Gauges use SESSION_COMMITTED timing, meaning they are only reported when the session commits successfully. No gauges are recorded when no records are consumed (the processor returns early before reaching the gauge recording path). ## Testing: Unit tests added for OffsetTracker.getTrackedPartitions() covering empty, single, multi-partition, and deduplication scenarios. Integration-style tests added to ConsumeKafkaTest using mocked KafkaConsumerService verifying gauge recording for single partition, multiple partitions, unavailable lag, and no-records-consumed cases. ## Additional fix: MockProcessSession did not clear gauges recorded with SESSION_COMMITTED on Session commit. # Tracking Please complete the following tracking steps prior to pull request creation. ### Issue Tracking - [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created ### Pull Request Tracking - [x] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000` - [x] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000` - [x] Pull request contains [commits signed](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) with a registered key indicating `Verified` status ### Pull Request Formatting - [x] Pull Request based on current revision of the `main` branch - [x] Pull Request refers to a feature branch with one commit containing changes # Verification Please indicate the verification steps performed prior to pull request creation. ### Build - [x] Build completed using `./mvnw clean install -P contrib-check` - [x] JDK 21 - [ ] JDK 25 ### Licensing - [x] (no new) New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html) - [x] (no new) New dependencies are documented in applicable `LICENSE` and `NOTICE` files ### Documentation - [x] (no changes) Documentation formatting appears as expected in rendered files -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
