Skip to content

fix(telemetry): report execution_result and statement_type on Thrift statements - #550

Merged
vuanhphung merged 8 commits into
mainfrom
fix/issue-454-thrift-execution-result
Nov 13, 2026
Merged

vuanhphung merged 8 commits into
mainfrom
fix/issue-454-thrift-execution-result

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Thrift statement telemetry never set sql_operation.execution_result or sql_operation.statement_type. SQLExecutionEvent.ExecutionResult was filled only from the result.format tag, and nothing produced that tag, so the backend could not tell inline Arrow results from CloudFetch (external links) delivery or classify the statement.

This maps the result format declared by the Thrift result-set metadata to the telemetry enum, using JDBC's mapping: ARROW_BASED_SET → INLINE_ARROW, URL_BASED_SET → EXTERNAL_LINKS, COLUMN_BASED_SET → COLUMNAR_INLINE. The value is written to the existing tag. Queries report it from Rows.Close, before the statement metric is finalized. The metadata comes from direct results or from the first row fetch. ExecContext reports it from the direct-results metadata or the metadata the staging check already fetched. The driver never adds a metadata RPC for telemetry, so a query closed before its first fetch, with no metadata in its direct results, omits the field (Node.js behaves the same way). Statements whose execution fails report no format. A failure after the metadata has arrived keeps the format, as JDBC does. That covers a fetch or staging error, and a result-setup error where QueryContext discards its Rows and reports the format itself. That format comes from the metadata those rows received inline or fetched. The format is still reported once per statement.

Decision: every Thrift statement reports statement_type = SQL. That covers queries, ExecContext, staging and failed statements. This matches the kernel, which hardcodes SQL for user SQL, so both Go backends report the same value. The tag is set when the statement metric starts, so it rides on the single EXECUTE_STATEMENT event. The kernel backend is unaffected because driver telemetry is off whenever the opened backend isn't Thrift, including after Reyden recovery.

Verified with:

  • Unit tests. Conn-level tests run the real telemetry interceptor, aggregator and exporter against an httptest /telemetry-ext endpoint. They cover inline Arrow, CloudFetch, a format known only after the first fetch, an unknown format, execution failure, failures after the metadata arrived (a fetch, staging or result-setup error), and ExecContext with direct-results metadata and with metadata from the staging check. Paired cases run the same metadata, inline or fetched, through a successful Results and a failing one. Each reports INLINE_ARROW on a single event. Each test asserts exactly one EXECUTE_STATEMENT event with statement_type = SQL, plus the metadata RPC count. Without this PR every case fails.
  • Repo checks. make test (1338 tests pass), make lint (0 issues) and go test -race on the touched packages all pass. The kernel-tagged suite passes too, except TestKernelCloudFetchDisabledPreservesUnsupportedServerError, which also fails on main with the prebuilt v1.4.0 bindings.
  • Live Thrift e2e. TestE2ETelemetryReportsExecutionResult passed 3 of 3 runs. It reports statement_type = SQL, with INLINE_ARROW for SELECT 1 and EXTERNAL_LINKS for a 2M-row CloudFetch result. On main both fields are empty. All 5 Thrift TestE2E* tests pass. On the kernel backend, 24 e2e tests pass. TestE2EKernelCloudFetchDisabledLargeResults and TestKernelE2EErrorTelemetryCategory fail the same way on main.
  • Coverage tests (databricks-driver-test #1389, run against this branch). TestSuccessfulStatementExecutionEmitsTerminalOperationEvent (TELEMETRY-001) and TestTelemetryReportsExternalLinksDeliveryAndCompression (TELEMETRY-005) both go from XFAIL-skip to pass. TestFailedStatementEmitsSanitizedErrorTelemetryWithoutSQLText (TELEMETRY-002) still passes.

Performance: the driver writes both tags once per statement, from a constant and from metadata it already holds. No RPC and no per-batch work is added.

Cross-driver state

Driver execution_result statement_type Notes
JDBC Supported Not supported Format from TelemetryCollector.getResultFormat (TelemetryCollector.java:202-213 @0cb8c24). The statement_type field exists, but setDriverStatementType has no caller (TelemetryHelper.java:115-121).
Python Partial Supported (by API) Thrift classifies the result queue (latency_logger.py:47-64 @5a1a7ec), and the kernel path reports FORMAT_UNSPECIFIED. execute reports QUERY, staging handlers SQL, metadata calls METADATA (client.py:1381-1836).
Node.js Supported (Thrift) / Partial (kernel) Not supported (Thrift) Cached metadata at completion, no extra RPC (DBSQLOperation.ts:28-41, 448-462 @93a9112). The exported sql_operation has no statement_type (DatabricksTelemetryExporter.ts:77-81).
Kernel Supported Supported telemetry_result_format (sea.rs:763-778 @db23442). StatementType::Sql for user SQL (statement/mutable.rs:692), set on failures too (telemetry/runtime.rs:252).
Go Not supported → Supported (Thrift, this PR) Not supported → Supported (Thrift, this PR) Follows JDBC's format mapping, and the kernel's SQL for every statement. An unknown format is omitted, which is the same as FORMAT_UNSPECIFIED in proto3 JSON. The kernel backend emits its own telemetry.

Adversarial review: both passes converged in round 1 with no high findings. Two mediums were fixed: an Arrow timestamp-cache race in the new tests (#465), and a result-setup failure losing metadata the rows had fetched themselves. Coverage-test issues were recorded for the driver-test owners.

Fixes #454

This pull request and its description were written by Isaac.

@vuanhphung
vuanhphung marked this pull request as ready for review November 13, 2026 09:58

@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: 1 Low

Looks good, with 1 low concern. The format mapping, where it is reported (Rows.Close before OnClose, and ExecContext from direct-results or staging-check metadata) and the promise of no extra RPC all check out against rows.go and operation.go. The one gap: an ExecContext statement whose staging step fails still reports a format, which doesn't match the description's "failed statements report no format".

Comment thread connection.go Resolved

@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.

✅ No issues identified by the review bot.

@vuanhphung vuanhphung changed the title fix(telemetry): report execution_result on Thrift statements fix(telemetry): report execution_result and statement_type on Thrift statements Nov 13, 2026

@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: 1 Low

Looks good, with one low concern. The tagging and mapping are correct and covered end-to-end through the real exporter, and no metadata RPC is added. The exception is the result-setup failure path, which drops a format the driver already received, unlike the fetch and staging failure cases.

Comment thread connection.go Resolved

@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.

✅ No issues identified by the review bot.

@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.

✅ No issues identified by the review bot.

@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: 1 Critical

The telemetry wiring looks correct. The format is gated on execution success, reported once per statement before OnClose, and no RPC is added. The blocker is that the new conn-level test file imports Arrow v12, but this branch now depends only on arrow-go v18, so the root package's tests won't compile.

Comment thread connection_telemetry_test.go Outdated
"testing"
"time"

"github.com/apache/arrow/go/v12/arrow"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Critical — The new test file imports github.com/apache/arrow/go/v12/arrow, .../array, .../ipc and .../memory. This branch has moved to Arrow Go v18: go.mod only requires github.com/apache/arrow-go/v18, and the CHANGELOG entry just above this PR's line describes that upgrade. With no v12 module in go.mod/go.sum, go test / go vet on the root dbsql package fails with "no required module provides package". That breaks make test and make lint for the whole package, not only these tests.

Fix: switch the imports to github.com/apache/arrow-go/v18/arrow, /arrow/array, /arrow/ipc and /arrow/memory. Then re-check the builder API: in v18, RecordBuilder.NewRecord is deprecated in favor of NewRecordBatch, and staticcheck may flag it. The "Arrow v12 caches the shared Timestamp_us zone" warm-up comment in TestConn_QueryContextTelemetryExecutionResult should also be rechecked against v18.

@vuanhphung

Copy link
Copy Markdown
Collaborator Author

@bot update v12 to v18 arrow

@oss-engineer-bot

Copy link
Copy Markdown
Contributor

Pushed a446dad to fix/issue-454-thrift-execution-result addressing your request.

Started from 5ba5485. The module already depends on github.com/apache/arrow-go/v18 v18.8.0. The only v12 imports left were in connection_telemetry_test.go, which this PR adds. I switched its four imports (arrow, array, ipc, memory) from github.com/apache/arrow/go/v12 to github.com/apache/arrow-go/v18. I also changed the deprecated b.NewRecord() to b.NewRecordBatch(), which is what the rest of the repo uses with v18. go.mod and go.sum are unchanged. go test -run Telemetry . passed, make test passed (1341 tests, 5 live E2E tests skipped because there are no credentials), and make lint reported 0 issues. gofmt -l -s . lists only the generated internal/cli_service files, which this change doesn't touch. I didn't run the live-warehouse or kernel-tagged t

oss-engineer-bot Bot pushed a commit that referenced this pull request Nov 13, 2026
Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@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.

✅ No issues identified by the review bot.

@vuanhphung

Copy link
Copy Markdown
Collaborator Author

@bot Could we preserve the format from fetched-page metadata for both public Arrow APIs? Without direct results, their iterators bypass rows.resultSetMetadata, so this accessor returns empty after successful consumption. Capturing it at the shared page-fetch boundary would avoid another RPC.

@vuanhphung vuanhphung added the skip-coverage Skip the coverage fan-out for this PR (no tracking issue opened in databricks-driver-test) label Nov 13, 2026
@vuanhphung
vuanhphung force-pushed the fix/issue-454-thrift-execution-result branch from a446dad to 9705ccc Compare November 13, 2026 19:16
vuanhphung pushed a commit that referenced this pull request Nov 13, 2026
Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
Signed-off-by: Vu Anh Phung <[email protected]>
@oss-engineer-bot

Copy link
Copy Markdown
Contributor

Pushed 2719e36 to fix/issue-454-thrift-execution-result addressing your request.

Started from a446dad. Without direct results, GetArrowBatches and GetArrowIPCStreams now report the result format. The page iterator keeps the first ResultSetMetadata a FetchResults page returns (resultPageIterator.go). If the rows hold no format, rows.ResultFormat uses that one (rows.go), with no extra RPC. New tests in connection_telemetry_test.go cover both APIs: INLINE_ARROW, no errors, zero metadata RPCs. Tests, make test (5 E2E skipped, no credentials) and make lint pass. gofmt -l -s lists only three generated internal/cli_service files I didn't touch. Not run here: live E2E and kernel-tagged tests.

oss-engineer-bot Bot pushed a commit that referenced this pull request Nov 13, 2026
Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@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: 1 Nit

Looks good. I found no correctness issues. The format is taken from metadata the driver already holds, with no new RPC, and it is reported before the statement metric is finalized. The nil, typed-nil and failure paths in QueryContext and ExecContext are handled, and the tests cover each path, including the single-event check. One nit: a test comment still refers to Arrow v12 after the v18 upgrade.

Other findings

  • ⚪ Nit — connection_telemetry_test.go: the warm-up comment says "Arrow v12 caches the shared Timestamp_us zone", but this branch is on arrow-go v18 (see CHANGELOG). Either update the comment or check that the warm-up is still needed.

@vuanhphung
vuanhphung enabled auto-merge November 13, 2026 20:27
@vuanhphung
vuanhphung added this pull request to the merge queue Nov 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Nov 13, 2026
@vuanhphung
vuanhphung enabled auto-merge November 13, 2026 21:47
@vuanhphung
vuanhphung added this pull request to the merge queue Nov 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 13, 2026
vuanhphung and others added 5 commits November 13, 2026 22:26
Thrift statement telemetry never set sql_operation.execution_result, so
the backend could not tell inline Arrow results from CloudFetch delivery.

Map the result format declared by the Thrift result-set metadata the
driver already holds (JDBC's mapping: ARROW_BASED_SET -> INLINE_ARROW,
URL_BASED_SET -> EXTERNAL_LINKS, COLUMN_BASED_SET -> COLUMNAR_INLINE)
onto the existing result.format tag. Queries report it from Rows.Close
before the statement metric is finalized; ExecContext reports it from
the direct-results metadata or the metadata the staging check fetched.
No metadata RPC is added, and failed statements report no format.

Addresses #454.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Vu Anh Phung <[email protected]>
… cases

Running TestConn_QueryContextTelemetryExecutionResult alone under -race
hit Arrow v12's unsynchronized Timestamp_us zone cache from two parallel
subtests (the production race is tracked in #465). Warm it while tests
still run serially.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Vu Anh Phung <[email protected]>
A staging or fetch failure happens after the server returned the result
metadata, so the format is still reported. This matches JDBC, which
records the format before building the volume-operation handler. Only
execution failures omit it.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Vu Anh Phung <[email protected]>
Thrift statement telemetry never set sql_operation.statement_type, so the
backend could not classify Go Thrift statements. Report SQL for every
Thrift statement, as the kernel does for user SQL, so both Go backends
report the same value. The tag is set when the statement metric starts,
so direct results, staging operations and failed statements all carry
it on their single EXECUTE_STATEMENT event.

Fixes #454.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Vu Anh Phung <[email protected]>
When QueryContext's Results fails after the server returned direct-results
metadata (e.g. a malformed Arrow schema), the discarded Rows never reported
its format, so the EXECUTE_STATEMENT event had no execution_result. Report
the format the operation already holds through ResultFormatReporter, with
no RPC, as JDBC does by recording the format before building the result.
The success path is unchanged: only Rows.Close reports it there.

Fixes #454.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Vu Anh Phung <[email protected]>
vuanhphung and others added 3 commits November 13, 2026 22:27
When direct results omit the result-set metadata, NewRows fetches it
itself. If Arrow setup then failed, that metadata stayed on the discarded
Rows and the EXECUTE_STATEMENT event had no execution_result. The
QueryContext error branch now asks the discarded Rows for its format first
(inline or fetched metadata), then the operation. No RPC is added, and the
success path still reports the format only from Rows.Close.

Fixes #454.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Vu Anh Phung <[email protected]>
Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
Signed-off-by: Vu Anh Phung <[email protected]>
Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
Signed-off-by: Vu Anh Phung <[email protected]>
@vuanhphung
vuanhphung force-pushed the fix/issue-454-thrift-execution-result branch from 2719e36 to 91d6bfd Compare November 13, 2026 22:30

@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.

✅ No issues identified by the review bot.

@vuanhphung
vuanhphung enabled auto-merge November 13, 2026 22:35
@vuanhphung
vuanhphung added this pull request to the merge queue Nov 13, 2026
Merged via the queue into main with commit 980941b Nov 13, 2026
14 checks passed
@vuanhphung
vuanhphung deleted the fix/issue-454-thrift-execution-result branch November 13, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-coverage Skip the coverage fan-out for this PR (no tracking issue opened in databricks-driver-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[coverage] Conformance findings: TELEMETRY-001,TELEMETRY-005

1 participant