Skip to content

Use X-Databricks-Workspace-Id for workspace routing#1688

Merged
Divyansh-db merged 6 commits into
mainfrom
divyansh-vijayvergia_data/new-workspace-parameter
May 28, 2026
Merged

Use X-Databricks-Workspace-Id for workspace routing#1688
Divyansh-db merged 6 commits into
mainfrom
divyansh-vijayvergia_data/new-workspace-parameter

Conversation

@Divyansh-db
Copy link
Copy Markdown
Contributor

@Divyansh-db Divyansh-db commented May 19, 2026

Summary

Workspace-scoped API calls now identify the target workspace via the X-Databricks-Workspace-Id request header instead of X-Databricks-Org-Id. The value source is unchanged: it still comes from Config.WorkspaceID (or the DATABRICKS_WORKSPACE_ID environment variable). The response-side header read in CurrentWorkspaceID is left on the legacy name for now. A new CurrentWorkspaceIdentifier helper is added to support workspace identifier formats other than classic numeric IDs.

Why

On unified Databricks hosts that serve multiple workspaces, the SDK sends a routing header on every workspace-scoped HTTP request so the gateway can dispatch it to the correct workspace. Until now that header was X-Databricks-Org-Id.

The Databricks platform is consolidating workspace addressing onto a single header, X-Databricks-Workspace-Id, which accepts a broader range of workspace identifier formats and replaces the older single-purpose channels going forward. The previous header continues to be accepted by the platform, so older SDK versions keep working, but new SDK versions should use the new name.

This PR is the Go SDK's part of that migration on the request side. The platform's response-side echo header has not yet been renamed, so the SDK continues to read the workspace ID back from the legacy X-Databricks-Org-Id response header.

What changed

Interface changes

  • New: WorkspaceClient.CurrentWorkspaceIdentifier(ctx context.Context) (string, error) — returns the workspace identifier exactly as the server echoes it back, without attempting to parse it as a number. Use this in preference to CurrentWorkspaceID if your code may run against workspaces whose identifier is not a classic numeric ID.
  • Config.WorkspaceID keeps the same field name, type (string), and environment variable (DATABRICKS_WORKSPACE_ID). The doc comment is widened to note that the value may now be either a classic numeric workspace ID or another workspace identifier format that the server understands.
  • CurrentWorkspaceID(ctx) (int64, error) is unchanged signature-wise but is now a thin ParseInt adapter over CurrentWorkspaceIdentifier. Existing callers keep working byte-for-byte against classic numeric workspaces; for non-numeric identifiers it returns the parse error from strconv.ParseInt.

Behavioral changes

  • Workspace-scoped requests no longer send X-Databricks-Org-Id. They now send X-Databricks-Workspace-Id (with the same value, gated on Config.WorkspaceID being non-empty). Account-scoped requests are unaffected.
  • WorkspaceClient.CurrentWorkspaceID and the new CurrentWorkspaceIdentifier send X-Databricks-Workspace-Id as the routing header and read the workspace ID back from the legacy X-Databricks-Org-Id response header on /api/2.0/preview/scim/v2/Me — the server still emits the legacy name on responses, and the response-side migration is on a separate, later schedule.

Internal changes

  • Regenerated service/*/impl.go and internal/testspecs/service/*/impl.go from the corresponding generator template change: 34 files, 944 line swaps, no logic change.
  • Updated the hand-written sites that emit the same header on workspace-scoped calls but are not covered by the generator: service/iam/ext_impl.go, service/sharing/ext_api.go, service/workspace/ext_utilities.go, and workspace_functions.go.
  • Manually patched 16 occurrences in newly-merged generated code (service/bundle/impl.go, service/dashboards/impl.go:733, service/postgres/impl.go:625) that came in via an auto-codegen update made before the generator template change was available. This will be a no-op against the next regen after the generator change lands upstream.
  • Renamed the two TestCurrentWorkspaceID* test functions so the names match the new header on the request side.

How is this tested?

  • make fmt, make lint, and make test all pass locally. Full unit suite is green.
  • The four workspace_functions_test.go tests cover both helpers: they assert the new X-Databricks-Workspace-Id request header is sent, that the SDK reads the workspace ID back from the legacy X-Databricks-Org-Id response header, and that CurrentWorkspaceIdentifier returns non-numeric identifiers verbatim while CurrentWorkspaceID returns a parse error for those.
  • Spot-checked the regenerated diff: every changed line in service/*/impl.go is exclusively the request-header literal swap; no collateral changes.
  • End-to-end verified against a staging workspace: the SDK sends X-Databricks-Workspace-Id correctly and the gateway routes the request to the expected workspace. The response on /api/2.0/preview/scim/v2/Me echoes the workspace ID on x-databricks-org-id, which is why the response read site stays on the legacy name.
  • Added a new acceptance test TestAccUnifiedHostSendsWorkspaceIdHeader in internal/unified_host_test.go. It hooks a capturing http.RoundTripper into a workspace client built against a unified host and verifies on the wire that (1) the SDK sends X-Databricks-Workspace-Id and not X-Databricks-Org-Id on the request, (2) the server still echoes X-Databricks-Org-Id on the response, and (3) the SCIM Me call succeeds end-to-end. Skips when the workspace-test environment variables (UNIFIED_HOST, THIS_WORKSPACE_ID, TEST_ACCOUNT_ID, DATABRICKS_CLIENT_ID, DATABRICKS_CLIENT_SECRET) are missing.

Regenerated from the gosdkv0 template change in
databricks-eng/universe#1955306, which renames the workspace routing header
emitted on SPOG/unified-host requests from `X-Databricks-Org-Id` to
`X-Databricks-Workspace-Id`. This is the M1 piece of the "DECO + Unified
Workspace Addressing" initiative.

The diff is mechanical: 944 swaps across 34 generated files, no behavioral
change. The value still comes from `Config.WorkspaceID` and emission is still
gated on the operation being workspace-scoped (`!Service.IsAccounts`).

Co-authored-by: Isaac
Signed-off-by: Divyansh Vijayvergia <divyansh.vijayvergia@databricks.com>
Companion to the regenerated code: the generator only touched the OpenAPI-spec
backed `service/*/impl.go` files. This change updates the hand-written sites
that emit or parse the same SPOG routing header on workspace-scoped API calls:

- `service/iam/ext_impl.go`, `service/sharing/ext_api.go`,
  `service/workspace/ext_utilities.go`: swap `X-Databricks-Org-Id` →
  `X-Databricks-Workspace-Id` in the manually-written header injection (these
  files extend generated services with hand-written endpoints/wrappers and
  weren't covered by the codegen pass).
- `workspace_functions.go`: `CurrentWorkspaceID` now sends and reads the new
  header on `/api/2.0/preview/scim/v2/Me`; doc comments updated.
- `workspace_functions_test.go`: tests assert the new header name; function
  names renamed (`OrgIdHeader` → `WorkspaceIdHeader`) so the test names
  reflect what they cover.
- `config/config.go`: widen the `WorkspaceID` doc comment to note the value
  can now be a classic numeric workspace ID *or* a CPDR connection ID (the
  server disambiguates). Field name, type, and env var (`DATABRICKS_WORKSPACE_ID`)
  unchanged.
- `NEXT_CHANGELOG.md`: entry under Internal Changes.

POPP keeps accepting the legacy `X-Databricks-Org-Id` for rollback safety, so
this is safe to land any time after M0 platform support is fully rolled out.

Co-authored-by: Isaac
Signed-off-by: Divyansh Vijayvergia <divyansh.vijayvergia@databricks.com>
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 19, 2026 12:51 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 19, 2026 12:52 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 19, 2026 12:53 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db changed the title Divyansh vijayvergia data/new workspace parameter Use X-Databricks-Workspace-Id for workspace routing May 19, 2026
@Divyansh-db Divyansh-db requested a review from hectorcast-db May 22, 2026 15:51
End-to-end testing against the staging shard confirmed that the server still
echoes the legacy `X-Databricks-Org-Id` response header on
/api/2.0/preview/scim/v2/Me even when the request is made with the new
`X-Databricks-Workspace-Id` header. The response side of the migration is on
a separate, later schedule.

This is request-side asymmetric now: send `X-Databricks-Workspace-Id`, read
back from `X-Databricks-Org-Id`. Updated the comments and test fakes to
reflect that. If we kept reading the new response header, `CurrentWorkspaceID`
would return (0, ParseIntError) for every caller hitting a server that hasn't
renamed its echo yet.

Co-authored-by: Isaac
Signed-off-by: Divyansh Vijayvergia <divyansh.vijayvergia@databricks.com>
After merging latest main, six auto-codegen PRs (#1689, #1691, #1692, #1694,
#1695, #1696) re-introduced the legacy `X-Databricks-Org-Id` request header
in code generated against the still-unflipped gosdkv0 template. Affected:

  - service/bundle/ (brand-new service, 14 occurrences)
  - service/dashboards/impl.go:733 (new method)
  - service/postgres/impl.go:625 (new method)

Mechanically swap these 16 lines so the branch's request-side migration is
internally consistent. Once the upstream generator template change lands and
the next auto-codegen PR runs, this manual patch will be a no-op against the
freshly-regenerated output.

Co-authored-by: Isaac
Signed-off-by: Divyansh Vijayvergia <divyansh.vijayvergia@databricks.com>
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 12:31 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 13:22 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 13:22 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 13:57 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 13:59 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 14:00 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db force-pushed the divyansh-vijayvergia_data/new-workspace-parameter branch from 67b5775 to abede5d Compare May 26, 2026 14:06
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 14:06 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 14:06 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 14:06 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db force-pushed the divyansh-vijayvergia_data/new-workspace-parameter branch from abede5d to 7248519 Compare May 26, 2026 14:41
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 14:41 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 14:42 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 14:42 — with GitHub Actions Inactive
Hooks a capturing http.RoundTripper into a workspace client built against a
unified (SPOG) host and verifies what crosses the wire:

  1. SDK sends X-Databricks-Workspace-Id with Config.WorkspaceID on the
     request and no longer sends the legacy X-Databricks-Org-Id.
  2. Server still echoes the workspace ID on the legacy X-Databricks-Org-Id
     response header — which is why workspace_functions.go reads that name.
  3. The workspace-scoped /api/2.0/preview/scim/v2/Me call succeeds against
     the unified host gateway.

Targets the workspace test environment. Requires UNIFIED_HOST,
THIS_WORKSPACE_ID, TEST_ACCOUNT_ID, DATABRICKS_CLIENT_ID, and
DATABRICKS_CLIENT_SECRET, and skips if TEST_ENVIRONMENT_TYPE is set to
anything other than WORKSPACE / UC_WORKSPACE.

Co-authored-by: Isaac
Signed-off-by: Divyansh Vijayvergia <divyansh.vijayvergia@databricks.com>
@Divyansh-db Divyansh-db force-pushed the divyansh-vijayvergia_data/new-workspace-parameter branch from 7248519 to 60e716c Compare May 26, 2026 14:46
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 14:46 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 14:46 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 26, 2026 14:46 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 27, 2026 09:58 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 27, 2026 09:59 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 27, 2026 10:00 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db force-pushed the divyansh-vijayvergia_data/new-workspace-parameter branch from 7eb0c2c to 60e716c Compare May 27, 2026 11:48
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 27, 2026 11:48 — with GitHub Actions Inactive
@github-actions
Copy link
Copy Markdown

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-go

Inputs:

  • PR number: 1688
  • Commit SHA: 60e716cd64f18c63928269532618c27c19f3989c

Checks will be approved automatically on success.

@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 27, 2026 11:49 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db temporarily deployed to test-trigger-is May 27, 2026 11:50 — with GitHub Actions Inactive
@Divyansh-db Divyansh-db added this pull request to the merge queue May 28, 2026
Merged via the queue into main with commit 0a030bd May 28, 2026
27 checks passed
@Divyansh-db Divyansh-db deleted the divyansh-vijayvergia_data/new-workspace-parameter branch May 28, 2026 09:42
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.

2 participants