Skip to content

feat(telemetry): add result stream metrics - #273

Closed
jay-xiao446 wants to merge 1 commit into
kernel-telemetry-phase-3from
jay-xiao446/stack/kernel-telemetry-phase-4
Closed

jay-xiao446 wants to merge 1 commit into
kernel-telemetry-phase-3from
jay-xiao446/stack/kernel-telemetry-phase-4

Conversation

@jay-xiao446

Copy link
Copy Markdown
Collaborator

Summary

  • defer successful statement telemetry until result streams are exhausted or dropped
  • record first-batch and consumption latency through ResultStream
  • preserve finalization through OwnedBatchIter
  • surface CloudFetch chunk metrics into statement telemetry

Flow

sequenceDiagram
    participant Statement
    participant Stream as ResultStream
    participant Telemetry as StatementTelemetry
    participant Exporter as TelemetryClient

    Statement->>Telemetry: on_statement_submitted
    Statement-->>Stream: attach telemetry
    Stream->>Telemetry: record first batch + rows
    loop batches
      Stream->>Telemetry: accumulate batch/row counts
    end
    Stream->>Telemetry: record consumed + chunk metrics
    Stream->>Exporter: finalize one terminal event
Loading

CloudFetch Metrics

flowchart LR
    CF[CloudFetch Provider] -->|download success| M[Chunk metrics]
    CF -->|chunk released| M
    M --> R[ResultReader::metrics]
    R --> S[ResultStream finalization]
    S --> T[Statement telemetry event]
Loading

Validation

  • cargo test telemetry --lib --locked
  • cargo test is_open_tests --lib --locked
  • cargo clippy --all-targets --locked -- -D warnings
  • cargo test --locked

Signed-off-by: Jay Xiao <jay.xiao@databricks.com>
@jay-xiao446

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #274, which uses the stack branch naming convention and is based on kernel-telemetry-phase-3.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 2 Low

Looks good overall — the telemetry-finalization refactor is sound: all four success paths (execute, execute_direct, await_result, fetch_result) now attach telemetry to the ResultStream and rely on ResultStreamTelemetry::finish/Drop, and the shared Arc-backed finalized AtomicBool guarantees exactly one terminal event across clones and repeated materialise_result calls. Test coverage (exhaustion, drop-unexhausted, CloudFetch chunk details) is appropriate. Two Low-severity semantic notes on chunk/consumption metric definitions are inline; neither blocks.


fn record_chunk_download(&self, elapsed: std::time::Duration) {
let millis = elapsed.as_millis().try_into().unwrap_or(i64::MAX);
let _ = self.initial_chunk_latency_ms.compare_exchange(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — initial_chunk_latency_ms is set by the first download to complete, not the latency of chunk 0. record_chunk_download runs inside the Ok(batches) arm of each concurrently-spawned download_chunk_with_retry task, and the compare_exchange(-1, millis) seats whichever task finishes first. Because chunk downloads run in parallel (spawned at streaming_provider.rs:647), the "first completed" chunk is frequently not chunk 0 — a small later chunk can win the race. If this metric is meant to mirror the reference drivers' notion of time-to-first-chunk (chunk 0 in result order), the value reported here can be misleading. Consider recording chunk 0's own download time specifically, or renaming the field to reflect "first-completed-download" semantics.

Comment thread src/result_stream.rs
sum_chunks_download_time: metrics.sum_chunks_download_time,
});
}
if !self.consumed_recorded {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — finish unconditionally calls record_result_consumed() (setting consumption_latency) even when invoked from ResultStreamTelemetry::drop on a stream that was never exhausted. A caller that consumes a few batches and drops the stream — or drops it without reading at all — will still report a result_set_consumption_latency_millis, indistinguishable in the emitted event from a fully-drained stream. This can skew aggregate consumption-latency metrics with abandoned/partial reads. If consumption latency is intended to mean "time to fully drain the result set," consider only recording it on the true exhaustion paths (Ok(None) in next_batch/OwnedBatchIter::next) and leaving it unset on the drop-without-exhaustion path.

This branch was previously deployed

1 inactive deployment
azure-prod — 9c29453c Deployed Aug 19, 2026 by jay-xiao446 via review #318
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant