Skip to content

Commit 7b776d1

Browse files
authored
Translate dashboards' paths before their serialized contents are read (#3006)
## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> #2738 changed reading the dashboard contents before the dashboard path was normalized. This change fixes that defect, and also fixes use cases of reading dashboards contents inside a bundle, which defines sync root that is different from the bundle root ## Tests <!-- How have you tested the changes? --> Existing and new acceptance tests <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 92ea5b2 commit 7b776d1

File tree

13 files changed

+167
-8
lines changed

13 files changed

+167
-8
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
### CLI
1010

1111
### Bundles
12+
* Fix reading dashboard contents when the sync root is different than the bundle root ([#3006](https://github.com/databricks/cli/pull/3006))
1213

1314
### API Changes

acceptance/bundle/debug/out.stderr.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources
4545
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources mutator=ResolveVariableReferences(resources)
4646
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources mutator=NormalizePaths
47+
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources mutator=TranslatePaths
4748
10:07:59 Debug: Apply pid=12345 mutator=PythonMutator(load)
4849
10:07:59 Debug: Apply pid=12345 mutator=PythonMutator(init)
4950
10:07:59 Debug: Apply pid=12345 mutator=PythonMutator(load_resources)

acceptance/bundle/deploy/dashboard/nested-folders/databricks.yml.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#
2+
# Acceptance test for deploying dashboards with the following setup:
3+
# 1. dashboard file is inside the bundle root, but in a separate file from the .yml file
4+
# 2. sync root is the same as the bundle root
5+
#
16
bundle:
27
name: deploy-dashboard-nested-folders-$UNIQUE_NAME
38

acceptance/bundle/deploy/dashboard/simple/databricks.yml.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#
2+
# Acceptance test for deploying dashboards with the following setup:
3+
# 1. dashboard file is inside the bundle root
4+
# 2. sync root is the same as the bundle root
5+
#
16
bundle:
27
name: deploy-dashboard-test-$UNIQUE_NAME
38

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Acceptance test for deploying dashboards with the following setup:
3+
# 1. dashboard file is outside the bundle root
4+
# 2. sync root is one level above bundle root
5+
#
6+
bundle:
7+
name: deploy-dashboard-outside-bundle-root-$UNIQUE_NAME
8+
9+
sync:
10+
paths:
11+
- ..
12+
include:
13+
- ..
14+
15+
resources:
16+
dashboards:
17+
dashboard1:
18+
display_name: $DASHBOARD_DISPLAY_NAME
19+
warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID
20+
embed_credentials: true
21+
file_path: ../sample-dashboard.lvdash.json
22+
parent_path: /Users/$CURRENT_USER_NAME
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-dashboard-outside-bundle-root-[UNIQUE_NAME]/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
>>> [CLI] lakeview get [DASHBOARD_ID]
9+
{
10+
"lifecycle_state": "ACTIVE",
11+
"parent_path": "/Users/[USERNAME]",
12+
"path": "/Users/[USERNAME]/test bundle-deploy-dashboard [UUID].lvdash.json",
13+
"serialized_dashboard": "{\"pages\":[{\"name\":\"02724bf2\",\"displayName\":\"Dashboard test bundle-deploy-dashboard\",\"pageType\":\"PAGE_TYPE_CANVAS\"}]}"
14+
}
15+
16+
>>> [CLI] bundle destroy --auto-approve
17+
The following resources will be deleted:
18+
delete dashboard dashboard1
19+
20+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/deploy-dashboard-outside-bundle-root-[UNIQUE_NAME]/default
21+
22+
Deleting files...
23+
Destroy complete!
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
DASHBOARD_DISPLAY_NAME="test bundle-deploy-dashboard $(uuid)"
2+
if [ -z "$CLOUD_ENV" ]; then
3+
DASHBOARD_DISPLAY_NAME="test bundle/deploy/ 6260d50f-e8ff-4905-8f28-812345678903" # use hard-coded uuid when running locally
4+
export TEST_DEFAULT_WAREHOUSE_ID="warehouse-1234"
5+
fi
6+
cp $TESTDIR/../simple/sample-dashboard.lvdash.json ../.
7+
8+
export DASHBOARD_DISPLAY_NAME
9+
envsubst < databricks.yml.tmpl > databricks.yml
10+
11+
cleanup() {
12+
trace $CLI bundle destroy --auto-approve
13+
}
14+
trap cleanup EXIT
15+
16+
trace $CLI bundle deploy
17+
DASHBOARD_ID=$($CLI bundle summary --output json | jq -r '.resources.dashboards.dashboard1.id')
18+
trace $CLI lakeview get $DASHBOARD_ID | jq '{lifecycle_state, parent_path, path, serialized_dashboard}'
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Local = true
2+
Cloud = true
3+
RequiresWarehouse = true
4+
5+
Ignore = [
6+
"databricks.yml",
7+
"sample-dashboard.lvdash.json",
8+
]
9+
10+
[[Repls]]
11+
Old = "[0-9a-f]{32}"
12+
New = "[DASHBOARD_ID]"
13+
14+
[[Repls]]
15+
# Windows:
16+
Old = 'The system cannot find the file specified.'
17+
New = 'no such file or directory'
18+
19+
[[Server]]
20+
Pattern = "POST /api/2.0/lakeview/dashboards"
21+
Response.Body = '''
22+
{
23+
"dashboard_id":"1234567890abcdef1234567890abcdef"
24+
}
25+
'''
26+
27+
[[Server]]
28+
Pattern = "POST /api/2.0/lakeview/dashboards/{dashboard_id}/published"
29+
30+
[[Server]]
31+
Pattern = "GET /api/2.0/lakeview/dashboards/{dashboard_id}"
32+
Response.Body = '''
33+
{
34+
"dashboard_id":"1234567890abcdef1234567890abcdef",
35+
"display_name": "test dashboard 6260d50f-e8ff-4905-8f28-812345678903",
36+
"lifecycle_state": "ACTIVE",
37+
"path": "/Users/[USERNAME]/test bundle-deploy-dashboard 6260d50f-e8ff-4905-8f28-812345678903.lvdash.json",
38+
"parent_path": "/Users/tester@databricks.com",
39+
"serialized_dashboard": "{\"pages\":[{\"name\":\"02724bf2\",\"displayName\":\"Dashboard test bundle-deploy-dashboard\",\"pageType\":\"PAGE_TYPE_CANVAS\"}]}"
40+
}
41+
'''
42+
43+
[[Server]]
44+
Pattern = "DELETE /api/2.0/lakeview/dashboards/{dashboard_id}"

acceptance/bundle/deploy/dashboard/simple_syncroot/databricks.yml.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#
2+
# Acceptance test for deploying dashboards with the following setup:
3+
# 1. dashboard file is within the bundle root
4+
# 2. sync root is one level above bundle root
5+
#
16
bundle:
27
name: deploy-dashboard-test-$UNIQUE_NAME
38

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11

22
>>> [CLI] bundle deploy
3-
Error: failed to read serialized dashboard from file_path sample-dashboard.lvdash.json: open sample-dashboard.lvdash.json: no such file or directory
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-dashboard-test-[UNIQUE_NAME]/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
47

8+
>>> [CLI] lakeview get [DASHBOARD_ID]
9+
{
10+
"lifecycle_state": "ACTIVE",
11+
"parent_path": "/Users/[USERNAME]",
12+
"path": "/Users/[USERNAME]/test bundle-deploy-dashboard [UUID].lvdash.json",
13+
"serialized_dashboard": "{\"pages\":[{\"name\":\"02724bf2\",\"displayName\":\"Dashboard test bundle-deploy-dashboard\",\"pageType\":\"PAGE_TYPE_CANVAS\"}]}"
14+
}
515

616
>>> [CLI] bundle destroy --auto-approve
7-
Error: failed to read serialized dashboard from file_path sample-dashboard.lvdash.json: open sample-dashboard.lvdash.json: no such file or directory
17+
The following resources will be deleted:
18+
delete dashboard dashboard1
819

9-
Exit code: 1
20+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/deploy-dashboard-test-[UNIQUE_NAME]/default
21+
22+
Deleting files...
23+
Destroy complete!

0 commit comments

Comments
 (0)