pkuzmickas opened a new pull request, #41587:
URL: https://github.com/apache/beam/pull/41587

   ## Summary
   
   Expose total unread record counts from `UnboundedSource.UnboundedReader` as 
Flink's standardized FLIP-33 `pendingRecords` source metric, and add an opt-in 
Cloud Monitoring backlog query in `PubsubUnboundedSource` so Flink's autoscaler 
can see Pub/Sub subscription lag and compute catch-up capacity.
   
   ## Changes
   
   - `UnboundedSource.UnboundedReader`: add `getTotalBacklogRecords()` (default 
`BACKLOG_UNKNOWN`), parallel to `getTotalBacklogBytes()`.
   - `FlinkUnboundedSourceReader`: on subtask 0 only (so Flink does not 
duplicate subscription-wide backlog when summing `pendingRecords` across 
subtasks), periodically poll `getTotalBacklogRecords()` on a background daemon 
thread every 60s and lazily register 
`SourceReaderMetricGroup.setPendingRecordsGauge` on the first non-negative 
reading. Sources that return `BACKLOG_UNKNOWN` never register the gauge.
   - `PubsubOptions`: add opt-in `--pubsubBacklogReportingEnabled` (default 
`false`; requires `monitoring.timeSeries.list` on the subscription project).
   - `PubsubClient.SubscriptionPath`: expose `getProjectId()`.
   - `PubsubUnboundedSource.PubsubReader`: implement `getTotalBacklogRecords()` 
using Cloud Monitoring REST v3 
(`pubsub.googleapis.com/subscription/num_undelivered_messages`, 5-minute 
lookback, 10s timeouts, zero new dependencies). Transient failures log a 
warning and return `BACKLOG_UNKNOWN`, preserving the last good gauge reading.
   
   ## Verification
   
   - Spotless & Checkstyle pass on `:sdks:java:core`, 
`:sdks:java:io:google-cloud-platform`, and `:runners:flink:2.0`.
   - `:runners:flink:1.19:compileJava` passes.
   - Existing tests pass (`FlinkUnboundedSourceReaderTest` 17/17, 
`PubsubUnboundedSourceTest`).


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