Commit 1af9bd7
authored
Add metrics to
## Which issue does this PR close?
- Closes #22135
## Rationale for this change
`FFI_ExecutionPlan` exposes most of the `ExecutionPlan` trait but does
not
expose `metrics()`. As a result, `ForeignExecutionPlan::metrics()` falls
through to the trait default (`None`), so anything downstream of an FFI
boundary loses metrics. The most visible breakage is `EXPLAIN ANALYZE`,
which renders empty metric blocks for foreign plans; anything calling
`DisplayableExecutionPlan::with_metrics(...)` on a plan tree containing
foreign nodes is similarly affected.
This PR makes foreign plans behave the same as local plans for metric
reporting. Metrics are passed as a snapshot, and all atomic-backed
counters/gauges/timers are read into plain integer fields at marshal
time.
Correct because none of the in-tree consumers (`AnalyzeExec`,
`DisplayableExecutionPlan`) poll metrics
during streaming.
## What changes are included in this PR?
- New module `datafusion/ffi/src/metrics.rs` with FFI-stable mirrors of
`MetricsSet`, `Metric`, `MetricValue` (all 16 variants), `Label`,
`MetricType`, `MetricCategory`, `PruningMetrics`, `RatioMetrics`, and
`RatioMergeStrategy`, plus bidirectional `From` conversions.
- `MetricValue::Custom { value: Arc<dyn CustomMetricValue> }` is
marshalled
as `(name, Display output, as_usize())`. On the consumer side it is
reconstructed as a small `FfiCustomMetricValue` shim that preserves
`Display` and `as_usize()`. `aggregate` becomes a no-op (snapshots are
not mergeable) and `as_any` only downcasts to the shim — this is the
documented compromise.
- `FFI_ExecutionPlan` gains a new `metrics` function pointer (appended
after `repartitioned`). `ForeignExecutionPlan::metrics()` is implemented
to call through it.
- Two trivial accessors added to `RatioMetrics`: `merge_strategy()` and
`display_raw_values()` — needed to marshal these otherwise-private
fields.
- `chrono` added as a direct dependency of `datafusion-ffi` (used for
`Timestamp` ↔ unix-nanos conversion).
## Are these changes tested?
Yes. New tests, all passing:
- 7 unit tests in `datafusion/ffi/src/metrics.rs` round-trip every
`MetricValue` variant individually, plus a full `Metric`
(value + labels + partition + type + category) and a `MetricsSet`.
- `test_ffi_execution_plan_metrics_round_trip` in
`datafusion/ffi/src/execution_plan.rs` exercises the full FFI path:
builds an `ExecutionPlan` with a `MetricsSet`, wraps it in
`FFI_ExecutionPlan`, retrieves metrics via
`ForeignExecutionPlan::metrics()`
through `mock_foreign_marker_id`, and asserts the aggregated value
matches.
- `EmptyExec` test helper extended with `with_metrics(MetricsSet)`.
Existing test suites still pass: `cargo test -p datafusion-ffi
--all-features` and `cargo test -p datafusion-ffi --features
integration-tests`.
## Are there any user-facing changes?
Yes — this PR adds public API and makes a binary-incompatible change to
`FFI_ExecutionPlan`. Please add the `api change` label.
- **New public types** in `datafusion_ffi::metrics`: `FFI_MetricsSet`,
`FFI_Metric`, `FFI_MetricValue`, `FFI_Label`, `FFI_MetricType`,
`FFI_MetricCategory`, `FFI_PruningMetrics`, `FFI_RatioMetrics`,
`FFI_RatioMergeStrategy`, and `FfiCustomMetricValue`.
- **ABI break for `FFI_ExecutionPlan`**: a new `metrics` function
pointer
field is appended. Producers and consumers must be rebuilt together, as
is already enforced by the major-version check via
`datafusion_ffi::version()`.
- **New public accessors** on `RatioMetrics`: `merge_strategy()` and
`display_raw_values()`. Non-breaking additions.
- **`MetricValue::Custom` across FFI is lossy by design**: the
underlying
`dyn CustomMetricValue` is not preserved; only its `Display` output and
`as_usize()` snapshot survive. Documented on `FfiCustomMetricValue`.FFI_ExecutionPlan (#22136)1 parent 4fac70d commit 1af9bd7
6 files changed
Lines changed: 889 additions & 0 deletions
File tree
- datafusion
- ffi
- src
- physical_expr
- physical-expr-common/src/metrics
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
71 | 77 | | |
72 | 78 | | |
73 | 79 | | |
| |||
179 | 185 | | |
180 | 186 | | |
181 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
182 | 198 | | |
183 | 199 | | |
184 | 200 | | |
| |||
270 | 286 | | |
271 | 287 | | |
272 | 288 | | |
| 289 | + | |
273 | 290 | | |
274 | 291 | | |
275 | 292 | | |
| |||
431 | 448 | | |
432 | 449 | | |
433 | 450 | | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
434 | 457 | | |
435 | 458 | | |
436 | 459 | | |
| |||
444 | 467 | | |
445 | 468 | | |
446 | 469 | | |
| 470 | + | |
447 | 471 | | |
448 | 472 | | |
449 | 473 | | |
| |||
456 | 480 | | |
457 | 481 | | |
458 | 482 | | |
| 483 | + | |
459 | 484 | | |
460 | 485 | | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
461 | 491 | | |
462 | 492 | | |
463 | 493 | | |
| |||
490 | 520 | | |
491 | 521 | | |
492 | 522 | | |
| 523 | + | |
493 | 524 | | |
494 | 525 | | |
495 | 526 | | |
| |||
501 | 532 | | |
502 | 533 | | |
503 | 534 | | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
504 | 539 | | |
505 | 540 | | |
506 | 541 | | |
| |||
587 | 622 | | |
588 | 623 | | |
589 | 624 | | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
590 | 662 | | |
591 | 663 | | |
592 | 664 | | |
| |||
0 commit comments