Repository navigation
Add DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE for workspace_host - #7410
Conversation
|
Commit: Regression test reportSelected 1 changed tests (limit=20, 0 not selected) 2 tests: regression=2 unreleased=0 coverage=0 failing=0
TestAccept/bundle/templates-machinery/workspace_variable/runtime/DMS=: branch ✅ | main (b694c4c) ❌ | latest (v1.25.0) ❌main (b694c4c): latest (v1.25.0): same output as main (b694c4c) TestAccept/bundle/templates-machinery/workspace_variable/runtime/DMS=true: branch ✅ | main (b694c4c) ❌ | latest (v1.25.0) ❌main (b694c4c): latest (v1.25.0): same output as main (b694c4c) |
✅ Integration test reportCommit: a3cd02c
Top 3 slowest tests (at least 2 minutes):
|
When the variable names a profile, the template helpers that read or call the workspace (workspace_host, user_name, default_catalog and others) use that profile in bundle init and bundle debug render-template-schema. .workspace and all other requests, including the writes of the generated files, keep the selected profile. The command fails if the two profiles have different workspace IDs. DABs in the Workspace selects the profile for the host of the page, which can be a host shared by several workspaces, and points the helpers at the workspace's own host. Templates that use workspace_host keep their output. Co-authored-by: Isaac <no-reply@databricks.com>
…eads Move the profile loading to root.MustWorkspaceClientForTemplate so it shares applyProfileAuthPrecedence with --profile, and use it in pipelines init too. The warehouse_path prompt now reads through the helpers profile as well. Fail when the helpers profile has no workspace ID instead of skipping the check. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Replace DATABRICKS_BUNDLE_INIT_HELPERS_PROFILE with DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE. Only the workspace_host helper reads the named profile, from the config file, and returns its host. The other helpers, the warehouse_path prompt and .workspace keep the selected profile, so no second client or command wiring is needed. Co-authored-by: Isaac <no-reply@databricks.com>
Reuse the profile package's host canonicalization (now exported as profile.CanonicalizeHost), reject a profile host that doesn't parse, label both workspace IDs in the mismatch error, and cover a missing config file. Co-authored-by: Isaac <no-reply@databricks.com>
…e ID Co-authored-by: Isaac <no-reply@databricks.com>
5325cb0 to
9b70d33
Compare
| return "", fmt.Errorf("profile %q from %s not found or has no host", name, workspaceHostProfileEnvVar) | ||
| } | ||
| p := profiles[0] | ||
| if p.WorkspaceID == "" || p.WorkspaceID == profile.WorkspaceIDNone || p.WorkspaceID != w.Config.WorkspaceID { |
There was a problem hiding this comment.
How will this work for a profile whose host carries the ID as ?o=<id> and has no workspace_id? The SDK treats that host as having the ID (fixHostIfNeeded promotes it), but here p.WorkspaceID is "" so the profile is rejected. Fine if the UI always writes workspace_id into the profile, just checking it's intentional.
There was a problem hiding this comment.
UI always pass workspace_id in a profile but I updated the code so it would also handle ?w= or ?o=.
| // DABs in the Workspace selects the profile for the host of the page, which can be a host shared | ||
| // by several workspaces, and sets this to a profile for the workspace's own host, so that | ||
| // templates that use workspace_host keep generating that host. | ||
| const workspaceHostProfileEnvVar = "DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE" |
There was a problem hiding this comment.
Was passing the host directly considered (something like DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST=<host>)? The only thing we read from the profile is its host, and with the indirection the UI has to write a second profile just for this. Or is the profile needed so we can check the workspace ID against the selected one?
There was a problem hiding this comment.
Yes, we need both host and workspace id. UI writes multiple profiles anyway, so there is no extra work there.
| return w.Config.Host, nil | ||
| } | ||
|
|
||
| profiles, err := profile.GetProfiler(ctx).LoadProfiles(ctx, profile.WithName(name)) |
There was a problem hiding this comment.
nit: this re-reads and parses .databrickscfg on every workspace_host call (schema defaults, welcome message, each template file). Worth caching the result like cachedUser does?
…ile once Like the SDK does for the selected profile, take the workspace ID from ?w= or ?o= in the host when the profile has no workspace_id. Cache the workspace_host result so templates don't read the config file on every call. Co-authored-by: Isaac <no-reply@databricks.com>
Changes
Adds
DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE. When it names a profile, theworkspace_hosttemplate helper returns that profile's host instead of the selected profile's host. The profile must have the selected profile's workspace ID, otherwise rendering fails. Like the SDK, the ID can also come from?w=or?o=in the profile's host. Everything else, including.workspaceand the other helpers, keeps the selected profile. The profile is read once from the config file, so there is no extra request.Why
DABs in the Workspace will select the profile for the page's host, which can be a host shared by several workspaces, so templates that use
.workspaceget that host with?w=<id>. Existing custom templates that useworkspace_hostmust keep generating the workspace's own host. Without the variable nothing changes.Tests
A unit test covers the override and each error. The
workspace_variableacceptance test renders a schema and runs init with the runner's profiles, and shows the errors. On dogfood serverless I checked that templates render the same values through the shared host, and that a bundle with the workspace's own host still validates with the runner's profiles.This pull request and its description were written by Isaac.