Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion acceptance/cmd/api/account-flag/script
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MSYS_NO_PATHCONV=1 $CLI api get /api/2.0/clusters/list --account
trace print_requests.py --get //api/2.0/clusters/list | contains.py "!X-Databricks-Org-Id"
trace print_requests.py --get //api/2.0/clusters/list | contains.py "!X-Databricks-Workspace-Id"
2 changes: 1 addition & 1 deletion acceptance/cmd/api/account-path/script
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MSYS_NO_PATHCONV=1 $CLI api get /api/2.0/accounts/abc-123/network-policies
trace print_requests.py --get //api/2.0/accounts/abc-123/network-policies | contains.py "!X-Databricks-Org-Id"
trace print_requests.py --get //api/2.0/accounts/abc-123/network-policies | contains.py "!X-Databricks-Workspace-Id"
2 changes: 1 addition & 1 deletion acceptance/cmd/api/default-profile/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"User-Agent": [
"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_get cmd-exec-id/[UUID] interactive/none auth/pat"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"[NUMID]"
]
},
Expand Down
2 changes: 1 addition & 1 deletion acceptance/cmd/api/default-profile/script
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ unset DATABRICKS_CONFIG_PROFILE

title "default_profile is used when no --profile flag and no DATABRICKS_CONFIG_PROFILE\n"
MSYS_NO_PATHCONV=1 trace $CLI api get /api/2.0/clusters/list
trace print_requests.py --get //api/2.0/clusters/list | contains.py "X-Databricks-Org-Id"
trace print_requests.py --get //api/2.0/clusters/list | contains.py "X-Databricks-Workspace-Id"

title "--profile overrides default_profile (negative case)\n"
MSYS_NO_PATHCONV=1 errcode $CLI api get /api/2.0/clusters/list -p other 2>&1 | contains.py "other.test"
2 changes: 1 addition & 1 deletion acceptance/cmd/api/test.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RecordRequests = true
IncludeRequestHeaders = ["Authorization", "User-Agent", "X-Databricks-Org-Id"]
IncludeRequestHeaders = ["Authorization", "User-Agent", "X-Databricks-Workspace-Id"]

# Normalize OS-dependent and CI-only User-Agent segments so the recorded
# requests are stable across local macOS/Linux runs and GitHub Actions.
Expand Down
2 changes: 1 addition & 1 deletion acceptance/cmd/api/workspace-id-flag/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"User-Agent": [
"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_get cmd-exec-id/[UUID] interactive/none auth/pat"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"999"
]
},
Expand Down
2 changes: 1 addition & 1 deletion acceptance/cmd/api/workspace-id-flag/script
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MSYS_NO_PATHCONV=1 $CLI api get /api/2.0/clusters/list --workspace-id 999
trace print_requests.py --get //api/2.0/clusters/list | contains.py "X-Databricks-Org-Id" "999"
trace print_requests.py --get //api/2.0/clusters/list | contains.py "X-Databricks-Workspace-Id" "999"
2 changes: 1 addition & 1 deletion acceptance/cmd/api/workspace-id-from-query/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"User-Agent": [
"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_get cmd-exec-id/[UUID] interactive/none auth/pat"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"999"
]
},
Expand Down
2 changes: 1 addition & 1 deletion acceptance/cmd/api/workspace-id-from-query/script
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MSYS_NO_PATHCONV=1 $CLI api get "/api/2.0/clusters/list?o=999"
trace print_requests.py --get //api/2.0/clusters/list | contains.py "X-Databricks-Org-Id" "999"
trace print_requests.py --get //api/2.0/clusters/list | contains.py "X-Databricks-Workspace-Id" "999"
2 changes: 1 addition & 1 deletion acceptance/cmd/api/workspace-id-none/script
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ workspace_id = none
EOF

MSYS_NO_PATHCONV=1 $CLI api get /api/2.0/clusters/list --profile spog-account
trace print_requests.py --get //api/2.0/clusters/list | contains.py "!X-Databricks-Org-Id"
trace print_requests.py --get //api/2.0/clusters/list | contains.py "!X-Databricks-Workspace-Id"
2 changes: 1 addition & 1 deletion acceptance/cmd/api/workspace-path/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"User-Agent": [
"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_get cmd-exec-id/[UUID] interactive/none auth/pat"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"[NUMID]"
]
},
Expand Down
2 changes: 1 addition & 1 deletion acceptance/cmd/api/workspace-path/script
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MSYS_NO_PATHCONV=1 $CLI api get /api/2.0/clusters/list
trace print_requests.py --get //api/2.0/clusters/list | contains.py "X-Databricks-Org-Id"
trace print_requests.py --get //api/2.0/clusters/list | contains.py "X-Databricks-Workspace-Id"
2 changes: 1 addition & 1 deletion acceptance/cmd/api/workspace-proxy-regression/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"User-Agent": [
"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_get cmd-exec-id/[UUID] interactive/none auth/pat"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"[NUMID]"
]
},
Expand Down
2 changes: 1 addition & 1 deletion acceptance/cmd/api/workspace-proxy-regression/script
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# being misclassified as account-scope, so the routing identifier should be
# present on the recorded request.
MSYS_NO_PATHCONV=1 $CLI api get /api/2.0/preview/accounts/access-control/rule-sets
trace print_requests.py --get //api/2.0/preview/accounts/access-control/rule-sets | contains.py "X-Databricks-Org-Id"
trace print_requests.py --get //api/2.0/preview/accounts/access-control/rule-sets | contains.py "X-Databricks-Workspace-Id"
6 changes: 3 additions & 3 deletions acceptance/telemetry/failure/out.requests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Authorization": [
"Bearer [DATABRICKS_TOKEN]"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"[NUMID]"
]
},
Expand All @@ -27,7 +27,7 @@
"Authorization": [
"Bearer [DATABRICKS_TOKEN]"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"[NUMID]"
]
},
Expand All @@ -47,7 +47,7 @@
"Authorization": [
"Bearer [DATABRICKS_TOKEN]"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"[NUMID]"
]
},
Expand Down
6 changes: 3 additions & 3 deletions acceptance/telemetry/partial-success/out.requests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Authorization": [
"Bearer [DATABRICKS_TOKEN]"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"[NUMID]"
]
},
Expand All @@ -27,7 +27,7 @@
"Authorization": [
"Bearer [DATABRICKS_TOKEN]"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"[NUMID]"
]
},
Expand All @@ -47,7 +47,7 @@
"Authorization": [
"Bearer [DATABRICKS_TOKEN]"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"[NUMID]"
]
},
Expand Down
2 changes: 1 addition & 1 deletion acceptance/telemetry/success/out.requests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"User-Agent": [
"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/selftest_send-telemetry cmd-exec-id/[CMD-EXEC-ID] interactive/none auth/pat"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"[NUMID]"
]
},
Expand Down
2 changes: 1 addition & 1 deletion acceptance/telemetry/test.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IncludeRequestHeaders = ["Authorization", "X-Databricks-Org-Id"]
IncludeRequestHeaders = ["Authorization", "X-Databricks-Workspace-Id"]
RecordRequests = true

Local = true
Expand Down
2 changes: 1 addition & 1 deletion acceptance/telemetry/timeout/out.requests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Authorization": [
"Bearer [DATABRICKS_TOKEN]"
],
"X-Databricks-Org-Id": [
"X-Databricks-Workspace-Id": [
"[NUMID]"
]
},
Expand Down
12 changes: 6 additions & 6 deletions bundle/deploy/filer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ type stateFiler struct {
root filer.WorkspaceRootPath
}

// orgIDHeaders returns headers with X-Databricks-Org-Id set if a workspace ID
// is configured. SPOG hosts require this header to route requests to the
// correct workspace.
func (s stateFiler) orgIDHeaders() map[string]string {
// workspaceIDHeaders returns headers with X-Databricks-Workspace-Id set if a
// workspace ID is configured. SPOG hosts require this header to route requests
// to the correct workspace.
func (s stateFiler) workspaceIDHeaders() map[string]string {
wsID := s.apiClient.Config.WorkspaceID
if wsID == "" {
return nil
}
return map[string]string{
"X-Databricks-Org-Id": wsID,
"X-Databricks-Workspace-Id": wsID,
}
}

Expand Down Expand Up @@ -63,7 +63,7 @@ func (s stateFiler) Read(ctx context.Context, path string) (io.ReadCloser, error

var buf bytes.Buffer
urlPath := "/api/2.0/workspace-files/" + url.PathEscape(strings.TrimLeft(absPath, "/"))
err = s.apiClient.Do(ctx, http.MethodGet, urlPath, s.orgIDHeaders(), nil, nil, &buf)
err = s.apiClient.Do(ctx, http.MethodGet, urlPath, s.workspaceIDHeaders(), nil, nil, &buf)
if err != nil {
return nil, err
}
Expand Down
12 changes: 7 additions & 5 deletions cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
)

const (
// orgIDHeader is the workspace routing identifier sent on workspace-scope
// requests against unified hosts. Generated SDK service methods set this
// per-call when cfg.WorkspaceID is populated; we mirror the same idiom.
orgIDHeader = "X-Databricks-Org-Id"
// workspaceIDHeader is the workspace routing identifier sent on
// workspace-scope requests against unified hosts. Generated SDK service
// methods set this per-call when cfg.WorkspaceID is populated; we mirror
// the same idiom. The gateway also accepts the legacy X-Databricks-Org-Id
// header for rollback safety.
workspaceIDHeader = "X-Databricks-Workspace-Id"

// orgIDQueryParam is the SPOG (single-page-of-glass) URL convention used
// by the Databricks UI: "?o=<workspace-id>" identifies the workspace a URL
Expand Down Expand Up @@ -114,7 +116,7 @@ func makeCommand(method string) *cobra.Command {

headers := map[string]string{"Content-Type": "application/json"}
if orgID != "" {
headers[orgIDHeader] = orgID
headers[workspaceIDHeader] = orgID
}

var response any
Expand Down
14 changes: 7 additions & 7 deletions libs/filer/files_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ func NewFilesClient(w *databricks.WorkspaceClient, root string) (Filer, error) {
}, nil
}

// orgIDHeaders returns headers with X-Databricks-Org-Id set if a workspace ID
// is configured. SPOG hosts require this header to route requests to the
// correct workspace.
func (w *FilesClient) orgIDHeaders() map[string]string {
// workspaceIDHeaders returns headers with X-Databricks-Workspace-Id set if a
// workspace ID is configured. SPOG hosts require this header to route requests
// to the correct workspace.
func (w *FilesClient) workspaceIDHeaders() map[string]string {
wsID := w.workspaceClient.Config.WorkspaceID
if wsID == "" {
return nil
}
return map[string]string{
"X-Databricks-Org-Id": wsID,
"X-Databricks-Workspace-Id": wsID,
}
}

Expand Down Expand Up @@ -162,7 +162,7 @@ func (w *FilesClient) Write(ctx context.Context, name string, reader io.Reader,
urlPath = fmt.Sprintf("%s?overwrite=%t", urlPath, overwrite)
headers := map[string]string{"Content-Type": "application/octet-stream"}
if wsID := w.workspaceClient.Config.WorkspaceID; wsID != "" {
headers["X-Databricks-Org-Id"] = wsID
headers["X-Databricks-Workspace-Id"] = wsID
}
err = w.apiClient.Do(ctx, http.MethodPut, urlPath, headers, nil, reader, nil)

Expand Down Expand Up @@ -192,7 +192,7 @@ func (w *FilesClient) Read(ctx context.Context, name string) (io.ReadCloser, err
}

var reader io.ReadCloser
err = w.apiClient.Do(ctx, http.MethodGet, urlPath, w.orgIDHeaders(), nil, nil, &reader)
err = w.apiClient.Do(ctx, http.MethodGet, urlPath, w.workspaceIDHeaders(), nil, nil, &reader)

// Return early on success.
if err == nil {
Expand Down
14 changes: 7 additions & 7 deletions libs/filer/workspace_files_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ type WorkspaceFilesClient struct {
root WorkspaceRootPath
}

// orgIDHeaders returns headers with X-Databricks-Org-Id set if a workspace ID
// is configured. SPOG hosts require this header to route requests to the
// correct workspace.
func (w *WorkspaceFilesClient) orgIDHeaders() map[string]string {
// workspaceIDHeaders returns headers with X-Databricks-Workspace-Id set if a
// workspace ID is configured. SPOG hosts require this header to route requests
// to the correct workspace.
func (w *WorkspaceFilesClient) workspaceIDHeaders() map[string]string {
if w.workspaceClient == nil || w.workspaceClient.Config == nil {
return nil
}
Expand All @@ -133,7 +133,7 @@ func (w *WorkspaceFilesClient) orgIDHeaders() map[string]string {
return nil
}
return map[string]string{
"X-Databricks-Org-Id": wsID,
"X-Databricks-Workspace-Id": wsID,
}
}

Expand Down Expand Up @@ -171,7 +171,7 @@ func (w *WorkspaceFilesClient) Write(ctx context.Context, name string, reader io
return err
}

err = w.apiClient.Do(ctx, http.MethodPost, urlPath, w.orgIDHeaders(), nil, body, nil)
err = w.apiClient.Do(ctx, http.MethodPost, urlPath, w.workspaceIDHeaders(), nil, body, nil)

// Return early on success.
if err == nil {
Expand Down Expand Up @@ -349,7 +349,7 @@ func (w *WorkspaceFilesClient) Stat(ctx context.Context, name string) (fs.FileIn
ctx,
http.MethodGet,
"/api/2.0/workspace/get-status",
w.orgIDHeaders(),
w.workspaceIDHeaders(),
nil,
map[string]string{
"path": absPath,
Expand Down
8 changes: 4 additions & 4 deletions libs/filer/workspace_files_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestWorkspaceFilesDirEntry(t *testing.T) {
assert.True(t, i2.IsDir())
}

func TestWorkspaceFilesClientOrgIDHeaders(t *testing.T) {
func TestWorkspaceFilesClientWorkspaceIDHeaders(t *testing.T) {
tests := []struct {
name string
workspaceID string
Expand All @@ -70,7 +70,7 @@ func TestWorkspaceFilesClientOrgIDHeaders(t *testing.T) {
{
name: "with workspace ID",
workspaceID: "7474644166319138",
expect: map[string]string{"X-Databricks-Org-Id": "7474644166319138"},
expect: map[string]string{"X-Databricks-Workspace-Id": "7474644166319138"},
},
{
name: "without workspace ID",
Expand All @@ -87,13 +87,13 @@ func TestWorkspaceFilesClientOrgIDHeaders(t *testing.T) {
},
},
}
assert.Equal(t, tc.expect, w.orgIDHeaders())
assert.Equal(t, tc.expect, w.workspaceIDHeaders())
})
}

t.Run("nil workspace client", func(t *testing.T) {
w := &WorkspaceFilesClient{}
assert.Nil(t, w.orgIDHeaders())
assert.Nil(t, w.workspaceIDHeaders())
})
}

Expand Down
14 changes: 7 additions & 7 deletions libs/telemetry/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,23 @@ func Upload(ctx context.Context, ec protos.ExecutionContext) error {
return errors.New("failed to upload telemetry logs after three attempts")
}

// orgIDHeaders returns headers with X-Databricks-Org-Id set if a workspace ID
// is configured. SPOG hosts require this header to route requests to the
// correct workspace; without it, telemetry is recorded in a central shard
// instead of the correct workspace.
func orgIDHeaders(apiClient *client.DatabricksClient) map[string]string {
// workspaceIDHeaders returns headers with X-Databricks-Workspace-Id set if a
// workspace ID is configured. SPOG hosts require this header to route requests
// to the correct workspace; without it, telemetry is recorded in a central
// shard instead of the correct workspace.
func workspaceIDHeaders(apiClient *client.DatabricksClient) map[string]string {
wsID := apiClient.Config.WorkspaceID
if wsID == "" {
return nil
}
return map[string]string{
"X-Databricks-Org-Id": wsID,
"X-Databricks-Workspace-Id": wsID,
}
}

func attempt(ctx context.Context, apiClient *client.DatabricksClient, protoLogs []string) (*ResponseBody, error) {
resp := &ResponseBody{}
err := apiClient.Do(ctx, http.MethodPost, "/telemetry-ext", orgIDHeaders(apiClient), nil, RequestBody{
err := apiClient.Do(ctx, http.MethodPost, "/telemetry-ext", workspaceIDHeaders(apiClient), nil, RequestBody{
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.

There are a bunch of places where we call ApiClient.Do but don't set the headers like for example

cli/libs/git/info.go

Lines 64 to 78 in 6795f16

err = apiClient.Do(
ctx,
http.MethodGet,
apiEndpoint,
nil,
nil,
map[string]string{
"path": path,
"return_git_info": "true",
},
&response,
)
if err != nil {
return result, err
}

@simonfaltum any thoughts on it?

UploadTime: time.Now().UnixMilli(),
// There is a bug in the `/telemetry-ext` API which requires us to
// send an empty array for the `Items` field. Otherwise the API returns
Expand Down
Loading