[FLINK-38071][table] Add opt-in UDF metrics (FLIP-485)#28692
Draft
weiqingy wants to merge 5 commits into
Draft
Conversation
Collaborator
….udf-metric.sample-interval options 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). No behavior is wired yet; subsequent commits register and populate the metrics when enabled.
Reusable per-(operator, UDF) helper that registers udfProcessingTime
(DescriptiveStatisticsHistogram) and udfExceptionCount (ThreadSafeSimpleCounter)
under an addGroup("udf", udfName) scope, and implements FLINK-21736-style
counter-based sampling. Not yet wired into code generation.
…ls with metrics 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 UDF metrics to asynchronous scalar and table user-defined functions. The UdfMetrics handle is built once in the generated fetcher's open() and carried on the per-invocation delegating future. The sampling decision and start time are captured at dispatch on the task thread; udfProcessingTime (full dispatch-to-completion span) and udfExceptionCount are recorded at completion on the callback thread, touching only the synchronized histogram and thread-safe counter. Instrumentation is emitted only when table.exec.udf-metric-enabled is true; the generated code is byte-identical when disabled.
Add a UDF Metrics section to the metrics documentation describing udfProcessingTime and udfExceptionCount, their operator-scoped naming (<operator>.udf.<udf_name>.<metric>), the table.exec.udf-metric-enabled and table.exec.udf-metric.sample-interval options, and the covered function kinds. Also add an integration test asserting udfProcessingTime reflects a real UDF invocation delay.
7787f6d to
154a637
Compare
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.
What is the purpose of the change
This pull request is a reference implementation of FLIP-485: Add UDF Metrics (FLINK-38071). It adds opt-in, per-operator observability for SQL/Table user-defined functions so operators can see inside UDF "black boxes" when debugging latency, throughput, or errors — and feed a reliable "the problem is in user code" signal to autoscaling.
Two metrics are registered on the executing operator's
OperatorMetricGroup, scoped as<operator_name>.udf.<udf_name>.<metric>:udfProcessingTime— a Histogram of per-invocation UDF time (for async UDFs, the full dispatch-to-completion span).udfExceptionCount— a Counter of exceptions escaping the UDF (synchronous exceptions propagating out ofeval, and asynchronous exceptional completions).The feature is off by default (
table.exec.udf-metric-enabled = false) with zero overhead when disabled — the instrumentation is emitted at code generation only when enabled, so the generated operator is byte-identical to today when off. When enabled, it uses the same counter-based sampling as state latency tracking (FLINK-21736): only every Nth invocation is timed (table.exec.udf-metric.sample-interval, default 100), while exceptions are counted on every invocation.It is opened as a draft to validate the FLIP design against master and give the DISCUSS/VOTE thread a concrete reference; it is not intended to presume the vote outcome.
Brief change log
@PublicEvolvingoptions toExecutionConfigOptions:table.exec.udf-metric-enabled(default false) andtable.exec.udf-metric.sample-interval(default 100), plus generated config docs.UdfMetricshelper (flink-table-runtime) that registers the two metrics underaddGroup("udf", udfName), owns the FLINK-21736 sampling decision, brackets timing, and counts exceptions. The processing-time histogram is aDescriptiveStatisticsHistogramand the exception counter is aThreadSafeSimpleCounter.BridgingFunctionGenUtil), sharing one handle per(operator, udf name). Only user functions on the modernBridgingSqlFunctionstack are metered.udfProcessingTimeandudfExceptionCountare recorded at completion on the callback thread, touching only the synchronized histogram and the thread-safe counter.docs/…/ops/metrics.md.Not metered (out of scope of this FLIP): Process Table Functions (
PROCESS_TABLE), aggregate functions, and functions registered via the deprecatedregisterFunctionAPI.Verifying this change
This change added tests and can be verified as follows:
UdfMetricsTest(unit) — the sampling decision (including thesample-interval = 1"every call" case and the reset boundary), timing, and exception counting.UdfMetricsITCase(integration,InMemoryReporter) — 12 cases covering sync scalar and table, async scalar and table, metric naming/scope, values (a delayed UDF whoseudfProcessingTimereflects the delay), exception counting, the enabled/disabled gate, the one-handle-per-(operator, udf)sharing, and — for async — an exceptional completion that incrementsudfExceptionCountwhile the job still finishes.ConfigOptionsDocsCompletenessITCaseand the regenerated config docs verify the two new options are documented.flink-benchmarks.Does this pull request potentially affect one of the following parts:
@Public(Evolving): yes — two new@PublicEvolvingConfigOptions inExecutionConfigOptions.Documentation
docs/content/docs/ops/metrics.mdand the Chinese copy) and JavaDocs.Was generative AI tooling used to co-author this PR?