chandrsoni opened a new pull request, #371:
URL: https://github.com/apache/flink-connector-kafka/pull/371

   ## What is the purpose of the change
   
   JIRA: [FLINK-41829](https://issues.apache.org/jira/browse/FLINK-41829)
   
   `pendingRecords` is one gauge per source reader: the sum of the Kafka 
consumer's `records-lag` metric over every partition the reader tracks. When a 
`KafkaSource` reads several topics, a reader usually holds partitions of more 
than one topic, so no Flink metric shows how far behind each topic or partition 
is. The consumer metrics under `KafkaSourceReader.KafkaConsumer` do not help: 
they are registered by name once, when the consumer is created, before any 
per-partition `records-lag` metric exists (FLINK-35404).
   
   This pull request adds a `recordsLag` gauge for each partition, next to 
`currentOffset` and `committedOffset`:
   
       <operator 
scope>.KafkaSourceReader.topic.<topic>.partition.<partition>.recordsLag
   
   ## Brief change log
   
     - `KafkaSourceReaderMetrics` registers a `recordsLag` gauge in each 
topic-partition group. It reads the same tracked `records-lag` metric as 
`pendingRecords`, with the same conversion, so the partition values of one 
reader add up to `pendingRecords`.
     - A partition reports 0 until the reader fetches records from it and after 
`removeRecordsLagMetric`: the partitions that `pendingRecords` leaves out.
     - `recordsLagMetrics` is now `volatile`: the gauges are registered when a 
split is added, before the fetcher thread creates the map, and the metric 
reporter thread reads them.
     - The name differs from `pendingRecords` on purpose: reporters that keep 
only the leaf name (for example DogStatsD) would otherwise merge the two.
     - Docs: a new row in the Kafka source metrics table.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - New `KafkaSourceReaderMetricsTest#testRecordsLagTracking`: the 
per-partition values, their sum against `pendingRecords`, the gauge following 
the live Kafka metric, and a removed partition reporting 0 and leaving the 
total.
     - Extended `KafkaPartitionSplitReaderTest#testPendingRecordsGauge`: 
against a broker, each partition's `recordsLag` follows `pendingRecords` as 
records are fetched, and a fully read partition reports 0.
     - `./mvnw clean verify -pl flink-connector-kafka` passes locally on JDK 17 
(596 unit tests, 341 integration tests).
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency, including 
`kafka.version` or `flink.version`): no
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)` or `@Experimental`, or are the Table options or the PyFlink 
wrappers changed: yes, a new constant `RECORDS_LAG_METRIC_GAUGE` in 
`@PublicEvolving` `KafkaSourceReaderMetrics`, and a new metric
     - Checkpointed state, its serializers, or exactly-once delivery (splits, 
enumerator state, writer state, committables, transactions): no
     - The per-record code paths (split reader, record emitter, writer, 
serialization schemas; performance sensitive): no; the split reader's calls are 
unchanged, and the new gauge is computed only when a reporter reads it
   
   ## Documentation
   
     - Does this pull request introduce a new feature? yes
     - If yes, how is the feature documented? docs
     - If the docs changed, are both `docs/content` and `docs/content.zh` 
updated? yes
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Opus 5.5 (omp)
   


-- 
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]

Reply via email to