[FLINK-40294][table-planner] Instrument async scalar and table UDF calls with metrics - #29007
Draft
weiqingy wants to merge 2 commits into
Draft
[FLINK-40294][table-planner] Instrument async scalar and table UDF calls with metrics#29007weiqingy wants to merge 2 commits into
weiqingy wants to merge 2 commits into
Conversation
…c scalar and table UDF calls Introduce two opt-in configuration options for FLIP-485 UDF metrics: table.exec.udf-metric-enabled (default false) and table.exec.udf-metric.sample-interval (default 100). Wrap the generated eval call site for sync scalar and table user-defined functions (via the BridgingSqlFunction stack) with sampled udfProcessingTime timing and udfExceptionCount counting, using the UdfMetrics helper registered on the operator metric group under udf.<udfName>. Instrumentation is emitted only when table.exec.udf-metric-enabled is true; the generated operator is byte-identical when disabled. One shared handle is registered per (operator, udfName). Lookup-join, ML-predict, vector-search, legacy CallGens, and PROCESS_TABLE functions are not metered.
…lls with metrics Extend the FLIP-485 UDF metrics to async scalar and table user-defined functions. The sampling decision and the start timestamp are captured at dispatch on the task thread; the elapsed time and any exceptional completion are recorded at completion on the callback thread, in the per-invocation DelegatingAsyncResultFuture and DelegatingAsyncTableResultFuture. Both writes happen before the completion callback is registered, establishing a happens-before edge to the callback thread; the histogram is synchronized and the exception counter is thread-safe. udfProcessingTime for an async function therefore spans the full dispatch to completion, not just the synchronous hand-off. As on the sync path, the instrumentation is emitted at code generation only when table.exec.udf-metric-enabled is true.
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the third PR of the FLIP-485 implementation, split into a stack of small, independently reviewable PRs under the umbrella issue FLINK-38071. Landing order:
UdfMetricshelper: registration, sampling, timing, exception counting (#28878)Stacked on #28879 and kept as a draft until that merges, so the diff here currently also shows PR-2's commit. It will collapse to this step's changes once PR-2 lands.
What is the purpose of the change
Extends the FLIP-485 UDF metrics to asynchronous scalar and table functions, so
udfProcessingTimeandudfExceptionCountcover the async paths as well as the synchronous ones.An async invocation does not begin and end on the same thread, so the instrumentation is split. At dispatch, on the task thread, the sampling decision is taken and the start timestamp captured. At completion, on the callback thread, the elapsed time is recorded and an exceptional completion increments the counter.
udfProcessingTimetherefore measures the full dispatch-to-completion span, not just the synchronous hand-off.Brief change log
AsyncCodeGeneratorandBridgingFunctionGenUtil.DelegatingAsyncResultFuture(async scalar) andDelegatingAsyncTableResultFuture(async table).CodeGeneratorContextso the generated fetcher resolves the sharedUdfMetricshandle.As on the synchronous path, the instrumentation is emitted at code generation only when
table.exec.udf-metric-enabledis true, so the generated code is unchanged when the feature is disabled.Known limitation: an async scalar call whose arguments are all null short-circuits but still flows through the future, so with metrics enabled it records one near-zero histogram entry. This is a bounded skew in the timing distribution, not a correctness issue; avoiding it cleanly needs a separate dispatch path for the short-circuit case.
Verifying this change
This change added tests and can be verified as follows:
UdfMetricsITCase: async scalar and async table metrics, naming and scope, and an exceptional completion that incrementsudfExceptionCountwhile the job still finishes.AsyncCalcITCaseandAsyncCorrelateITCasesuites guard the async paths against regressions.Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation
metrics.mdsection lands in PR-4.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Anthropic Claude Opus 4.8 and Claude Opus 5)