Commit 9261ac6
authored
Extract SPOG org-id from cluster httpPath for non-Thrift requests (#367)
## Summary
- Fixes silent telemetry loss on SPOG (custom-URL) hosts when connecting
to an all-purpose cluster via an httpPath like
`sql/protocolv1/o/<workspace-id>/<cluster-id>`.
- `extractSpogHeaders` now extracts the workspace ID from the
`/o/<wsid>/` path segment as a fallback when `?o=<wsid>` is not present,
and emits an `x-databricks-org-id` header so the wrapped
`telemetryClient` / feature-flag client can route correctly on SPOG.
- Priority order preserved: `?o=` in `httpPath` ▶
`/sql/protocolv1/o/<wsid>/` path segment. Caller-set request headers
still win, including mixed-case `X-Databricks-Org-Id`.
## Why
On a SPOG host the workspace identity has to be in either the URL or the
`x-databricks-org-id` header for PoPP to route a request to the correct
workspace. For all-purpose cluster Thrift this is free — the workspace
ID is in the `/o/<wsid>/` segment of httpPath, so PoPP routes Thrift via
`routing_reason=workspace-id` and the session opens fine without an
explicit `?o=`.
The telemetry and feature-flag transports built by `connector.Connect`
wrap `c.client` with `withSpogHeaders` only when
`extractSpogHeaders(c.cfg.HTTPPath)` returns a non-nil map. Before this
PR that only happened when `?o=` was present, so cluster URLs without
`?o=` produced no `x-databricks-org-id` header, PoPP fell back to
default (account) routing on `/telemetry-ext`, and the responses were
303 redirects to `/login` — silently dropping telemetry on SPOG.
## What changes
`connector.go`
- New `clusterPathOrgIDPattern` regex
(`(?:^|/)sql/protocolv1/o/(\d+)/[^/?]+`) compiled once at package init.
- `extractSpogHeaders` checks `?o=` first (existing behavior), then
falls back to the cluster path segment, then returns nil. The
malformed-query-string path now also falls through to path inspection
instead of returning early. Log messages indicate which source produced
the workspace ID.
- Updated the connection comment to describe both query-param and
cluster-path extraction.
- `regexp` added to imports.
`connector_spog_test.go`
- Four new table entries under `TestExtractSpogHeaders`:
- Cluster path without `?o=` → header extracted from `/o/<wsid>/`
- Cluster path with leading `/` → same
- Cluster path with `?o=` → query-param value wins
- Warehouse path without `?o=` → still nil (regression guard: the new
regex must not match warehouse paths)
- New transport regression test proving a mixed-case caller-set
`X-Databricks-Org-Id` is not overwritten by the SPOG wrapper.
## Test plan
- [x] `go test -run
'TestExtractSpogHeaders|TestHeaderInjectingTransport' -v .` — focused
SPOG extraction and transport tests pass.
- [x] `go test -short .` — root package suite passes.
- [x] Behavior validated on the OSS JDBC equivalent fix against Prod
SPOG (`peco.azuredatabricks.net`) all-purpose cluster: telemetry POST
`/telemetry-ext` flipped from `HTTP 303 → /login` to `HTTP 200 OK` once
the path-segment extraction populated `x-databricks-org-id`. Same shape
of fix here.
## Out of scope
- The corresponding OSS JDBC driver fix is opened as
databricks/databricks-jdbc#1475.
- The Python connector (`databricks/databricks-sql-python`) has a
sibling upstream-head PR for the same fix:
databricks/databricks-sql-python#817.
- The Node.js connector (`databricks/databricks-sql-nodejs`) already
extracts org ID from both query param and path segment (see
`extractWorkspaceId` in `lib/DBSQLClient.ts`).
This pull request and its description were written with assistance from
Claude Code.
---------
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>1 parent 9d711e7 commit 9261ac6
2 files changed
Lines changed: 141 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
139 | | - | |
140 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
141 | 149 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
148 | 155 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
153 | 162 | | |
154 | | - | |
| 163 | + | |
155 | 164 | | |
156 | 165 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
165 | 186 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
172 | 195 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
177 | 201 | | |
178 | 202 | | |
179 | 203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
54 | 69 | | |
55 | 70 | | |
56 | 71 | | |
57 | 72 | | |
58 | 73 | | |
59 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
60 | 115 | | |
61 | 116 | | |
62 | 117 | | |
| |||
111 | 166 | | |
112 | 167 | | |
113 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
114 | 192 | | |
115 | 193 | | |
116 | 194 | | |
| |||
0 commit comments