[DATAFLINT-4425] - duration instrumentation on all nodes#58
Draft
[DATAFLINT-4425] - duration instrumentation on all nodes#58
Conversation
Replace 19 per-type DataFlint*Exec subclasses (spark3 + spark4) with a
single TimedExec wrapper that adds a `duration` metric to any SparkPlan
while preserving all child metrics automatically.
- TimedExec.children = child.children (transparent wrapper — one node in
Spark plan graph, no double-node in native SQL UI or DataFlint UI)
- nodeName = "DataFlint" + child.nodeName
- Instrumentation enabled globally or per node type via existing config flags
- Exchange nodes never wrapped
- Version-specific classes (PythonMapInArrowExec, ArrowWindowPythonExec)
matched by simple class name string — no NoClassDefFoundError on older
Spark versions
- TimedExec and MetricsUtils moved to plugin/ (shared by spark3 + spark4)
…kage removed unused packages
joins codeGen instrumentation doesnt work - cancelling codegen for these.
Move duration computation and stage assignment from the frontend (TypeScript)
to the backend (Scala), using SparkPlanGraph + metric values from the status
store. This works for both live execution and history server.
Backend (GraphDurationAttribution):
- Compute stage groups from graph topology (Exchange boundaries) — deterministic,
no Spark stage data needed
- Resolve plan-stage IDs to actual Spark stage IDs using metric-based extraction
with process-of-elimination fallback
- Compute per-node exclusive durations via pipelined subtraction model:
- Native exclusive metrics (sortTime, aggTime, buildTime) used directly
- Python UDF nodes (WindowInPandas, BatchEvalPython, etc.) treated as blocking
(independent timers)
- findTimedChild returns max timing among descendants (not first found)
- Codegen pipelineTime fallback for non-instrumented nodes inside codegen
- Auto-detection: attribution mode when instrumented, classic mode otherwise
- Normalize per-stage durations to match executorRunTime
- Exchange write/read durations from shuffle metrics
- Stage metadata (status, numTasks, executorRunTime) included in response
- Shared API case classes moved to plugin module (DurationApi.scala)
Frontend (simplified SQLNodeStageReducer):
- Reduced from ~650 lines to ~130 lines
- Uses backend-provided ResolvedStageGroup for stage assignment (no guessing)
- Uses backend-provided NodeDurationData for durations (no TS-side computation)
- Exchange write/read durations from backend
- Removed PlanDurationAttribution.ts entirely
- Null-safe metric value handling
API changes:
- /dataflint/sqlplan enriched with stageGroups + nodeDurations for all SQLs
- /dataflint/sqlmetrics enriched with stageGroups + nodeDurations for running SQLs
- Metric allowlists updated: added "duration" to input/output/join/sort types
Tests:
- GraphStageGroupSpec: topology-based stage grouping (4 tests)
- GraphDurationAttributionSpec: durations, exchange metrics, normalization (4 tests)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dd5f26c to
e3dabdd
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.
Summary
Adds server-side duration attribution and topology-based stage grouping to the DataFlint Spark plugin. Duration computation and stage assignment move from the frontend (TypeScript) to the backend (Scala), operating on
SparkPlanGraph+ metric values from the status store — works for both live execution and history server.GraphDurationAttributioncomputes stage groups from graph topology (Exchange boundaries) and per-node exclusive durations via pipelined subtraction/dataflint/sqlplanand/dataflint/sqlmetricsendpoints enriched withstageGroups,nodeDurations, andexchangeDurationsDurationApi.scala(no more duplication between Spark 3/4 modules)GraphStageGroupSpec(topology) +GraphDurationAttributionSpec(durations, exchanges, normalization)Changed files
GraphDurationAttribution.scalaDurationApi.scalaResolvedStageGroup,NodeDurationData,ExchangeDurationData, etc.)PlanDurationAttribution.scalaGraphDurationAttributionDataflintSQLPlanPage.scala(v3/v4)stageGroups+nodeDurationsfor all SQLsDataflintSQLMetricsPage.scala(v3/v4)stageGroups+nodeDurationsfor running SQLsapi.scala(v3/v4)SqlEnrichedDataincludes stage groups + durations; duplicates moved to shared moduleTimedExec.scalaDataFlintRDDUtils.scalaSQLNodeStageReducer.tsResolvedStageGroupfor stages, backend durations for displayPlanDurationAttribution.tsSqlReducer.tsAppStore.tsResolvedStageGroup,NodeDurationData,ExchangeBoundarySqlReducerUtils.ts"duration"to input/output/join/sort metric allowlistsSparkApi.tsxSQLMetricsWithDuration, guards against empty responsesGraphStageGroupSpec.scalaGraphDurationAttributionSpec.scalaAttribution Model
Stage Grouping
Topology-based (deterministic, no metrics needed):
Exchange Duration Split
Each exchange node provides:
writeDurationMs= shuffle write time (belongs to write stage)readDurationMs= fetch wait time + remote durations (belongs to read stage)