Skip to content

[VL] Refactor Velox metrics transport to use JSON payloads#12126

Merged
rui-mo merged 2 commits into
apache:mainfrom
rui-mo:wip_metrics_refactor
Jul 10, 2026
Merged

[VL] Refactor Velox metrics transport to use JSON payloads#12126
rui-mo merged 2 commits into
apache:mainfrom
rui-mo:wip_metrics_refactor

Conversation

@rui-mo

@rui-mo rui-mo commented May 22, 2026

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

  • Refactors Velox metrics transport away from fragile JNI long-array plumbing to a structured JSON payload decoded on the Scala side.
    Replace the long Metrics JNI constructor with a stable metricsJson, numMetrics, veloxToArrow, and taskStats payload.
    Move native metric field mapping and custom runtime metric extraction into MetricsUtil.scala.
    Making future metric additions mostly Scala-side changes.
    Keep C++ responsible only for exporting ordered Velox operator stats and task stats metadata.

  • Adds MetricsFramework.md documentation.

How was this patch tested?

Was this patch authored or co-authored using generative AI tooling?

@github-actions github-actions Bot added the VELOX label May 22, 2026
@rui-mo rui-mo force-pushed the wip_metrics_refactor branch from 8755a20 to f05b72a Compare May 22, 2026 06:03
@github-actions github-actions Bot added the DOCS label May 22, 2026
@rui-mo rui-mo marked this pull request as ready for review May 22, 2026 06:08
@rui-mo rui-mo force-pushed the wip_metrics_refactor branch 3 times, most recently from 465e90e to a5fa3be Compare May 27, 2026 03:34
@rui-mo rui-mo force-pushed the wip_metrics_refactor branch from a5fa3be to fbf2b67 Compare July 2, 2026 14:56
Copilot AI review requested due to automatic review settings July 2, 2026 14:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Velox backend’s metrics transport across the JNI boundary from large long[] arrays to a structured JSON payload, shifting most metric-field mapping and interpretation logic into Scala for better extensibility and stability.

Changes:

  • Replace JNI long-array metrics plumbing with a JSON payload (metricsJson) plus metadata (numMetrics, veloxToArrow, taskStats).
  • Serialize ordered Velox plan/operator stats to JSON in native code and decode/flatten into OperatorMetrics on the Scala side.
  • Add developer documentation describing the end-to-end Velox→Spark metrics mapping workflow.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
mkdocs.yml Adds the new Metrics Framework doc to the developer navigation.
docs/developers/MetricsFramework.md Documents the ordered-node + JSON + Spark-updater-tree mapping contract.
cpp/velox/tests/RuntimeTest.cc Updates dummy metrics construction to the new JSON-based API.
cpp/velox/compute/WholeStageResultIterator.h Removes the old runtime-metric helper declaration no longer needed with JSON transport.
cpp/velox/compute/WholeStageResultIterator.cc Serializes Velox plan/task stats into a JSON payload and constructs Metrics(numMetrics, json).
cpp/core/utils/Metrics.h Refactors native Metrics to carry json (and optional stats) instead of a typed long-array buffer.
cpp/core/jni/JniWrapper.cc Updates org.apache.gluten.metrics.Metrics JNI constructor signature and passes JSON + metadata.
backends-velox/src/main/scala/org/apache/gluten/metrics/MetricsUtil.scala Adds JSON parsing + flattening to OperatorMetrics and updates the updater traversal to consume flattened suites.
backends-velox/src/main/java/org/apache/gluten/metrics/OperatorMetrics.java Adds a no-arg constructor for placeholder/empty metrics suites.
backends-velox/src/main/java/org/apache/gluten/metrics/Metrics.java Replaces the wide long-array-based representation with metricsJson, numMetrics, and SingleMetric.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +132 to +136
val loadLazyVectorMetricsIdx = orderedNodeIds.size() - 1
if (loadLazyVectorMetricsIdx >= 0 && loadLazyVectorMetricsIdx < operatorMetrics.size()) {
operatorMetrics.get(loadLazyVectorMetricsIdx).loadLazyVectorTime =
root.path("loadLazyVectorTime").asLong(0L)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@zhouyuan

zhouyuan commented Jul 2, 2026

Copy link
Copy Markdown
Member

related: #12127

@rui-mo rui-mo force-pushed the wip_metrics_refactor branch from fbf2b67 to 2f70973 Compare July 6, 2026 10:35

@zhouyuan zhouyuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@rui-mo rui-mo merged commit 5ecef3c into apache:main Jul 10, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants