-
Notifications
You must be signed in to change notification settings - Fork 620
[flink] Support pendingRecords metric for Fluss source. #4250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| import org.apache.fluss.flink.source.reader.FlinkSourceReader; | ||
|
|
||
| import org.apache.flink.metrics.Gauge; | ||
| import org.apache.flink.metrics.groups.SourceReaderMetricGroup; | ||
| import org.apache.flink.runtime.metrics.MetricNames; | ||
|
|
||
|
|
@@ -33,6 +34,8 @@ public class FlinkSourceReaderMetrics { | |
| // For currentFetchEventTimeLag metric | ||
| private volatile long currentFetchEventTimeLag = UNINITIALIZED; | ||
|
|
||
| private volatile boolean pendingRecordsGaugeRegistered; | ||
|
|
||
| public FlinkSourceReaderMetrics(SourceReaderMetricGroup sourceReaderMetricGroup) { | ||
| this.sourceReaderMetricGroup = sourceReaderMetricGroup; | ||
| } | ||
|
|
@@ -50,6 +53,18 @@ public void reportRecordEventTime(long lag) { | |
| currentFetchEventTimeLag = lag; | ||
| } | ||
|
|
||
| /** | ||
| * Registers the gauge reporting the number of log records that have not been fetched yet, which | ||
| * backs the standard Flink pendingRecords metric. Only the first registration takes effect, so | ||
| * that re-created split readers won't register the metric again. | ||
| */ | ||
| public void registerPendingRecordsGauge(Gauge<Long> pendingRecordsGauge) { | ||
| if (!pendingRecordsGaugeRegistered) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we update the backing gauge when a split reader is recreated? The current guard keeps pendingRecords bound to the old scanner, so it may remain at 0 even when the new scanner has a backlog.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With periodic partition discovery enabled, removing all of a subtask's splits after partition deletion can cause Flink to close its idle fetcher without closing the outer source reader. A later partition assignment creates a new split reader that shares the existing FlinkSourceReaderMetrics. This guard then ignores the new scanner's gauge, leaving pendingRecords bound to the old scanner. Could we register the metric once but update its delegate when a new split reader is created, and add a regression test for this lifecycle?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for this comment |
||
| sourceReaderMetricGroup.setPendingRecordsGauge(pendingRecordsGauge); | ||
| pendingRecordsGaugeRegistered = true; | ||
| } | ||
| } | ||
|
|
||
| public SourceReaderMetricGroup getSourceReaderMetricGroup() { | ||
| return sourceReaderMetricGroup; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we extend
testPendingRecordsMetricto cover multiple buckets and remove this separate test? That would verify lag aggregation through actual fetching and metric registration rather than manually updating scanner state. We should also preserve the coverage for excluding unassigned buckets from the total lag.