Skip to content

Commit edcc112

Browse files
Fix persistent drift in dashboards (#4044)
## Changes Fixes persistent drift detection issues in dashboard resources for direct deployment mode. ## Why Dashboards were incorrectly showing drift on every `bundle plan` even when no actual changes were made. The following fields were causing false positives: **Local changes detected:** - `embed_credentials` (action: update) - `etag` (action: update) - `serialized_dashboard` (action: update) **Remote changes detected:** - `parent_path` (action: recreate) This PR fixes all of these issues by: 1. `parent_path`: Adding a `DashboardFixups` mutator to ensure `/Workspace` prefix is added to `parent_path` in the local config to match API responses 2. `serialized_dashboard`: Creating a new struct for dashboards that is flat. The persistent drift occured because our diff logic is go based and thus flagged a diff on the string based serialized_dashboard field 4. `etag`: Add skip trigger for local diffs. 5. `embed_credentials`: Creating a new struct for dashboards that is flat. Before embed_credentials was not being marsalled because of the custom override. Now it is being marshalled. Plan before: ``` { "plan": { "resources.dashboards.dashboard1": { "action": "recreate", "new_state": { "value": { "display_name": "test bundle-deploy-dashboard [UUID]", "parent_path": "/Users/[USERNAME]", "warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]" } }, "remote_state": { "create_time": "[TIMESTAMP]", "dashboard_id": "[DASHBOARD_ID]", "display_name": "test bundle-deploy-dashboard [UUID]", "etag": [ETAG], "lifecycle_state": "ACTIVE", "parent_path": "/Workspace/Users/[USERNAME]", "path": "/Users/[USERNAME]/test bundle-deploy-dashboard [UUID].lvdash.json", "serialized_dashboard": "{\n \"pages\": [\n {\n \"name\": \"02724bf2\",\n \"displayName\": \"Dashboard test bundle-deploy-dashboard\",\n \"pageType\": \"PAGE_TYPE_CANVAS\"\n }\n ]\n}\n", "update_time": "[TIMESTAMP]", "warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]" }, "changes": { "local": { "embed_credentials": { "action": "update" }, "etag": { "action": "update" }, "serialized_dashboard": { "action": "update" } }, "remote": { "embed_credentials": { "action": "skip", "reason": "server_side_default" }, "parent_path": { "action": "recreate" }, "serialized_dashboard": { "action": "skip", "reason": "server_side_default" } } } } } } ``` Plan now: ``` { "plan": { "resources.dashboards.dashboard1": { "action": "skip", "remote_state": { "create_time": "[TIMESTAMP]", "dashboard_id": "[DASHBOARD_ID]", "display_name": "test bundle-deploy-dashboard [UUID]", "embed_credentials": true, "etag": [ETAG], "lifecycle_state": "ACTIVE", "parent_path": "/Workspace/Users/[USERNAME]", "path": "/Users/[USERNAME]/test bundle-deploy-dashboard [UUID].lvdash.json", "serialized_dashboard": "{\n \"pages\": [\n {\n \"name\": \"02724bf2\",\n \"displayName\": \"Dashboard test bundle-deploy-dashboard\",\n \"pageType\": \"PAGE_TYPE_CANVAS\"\n }\n ]\n}\n", "update_time": "[TIMESTAMP]", "warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]" }, "changes": { "local": { "etag": { "action": "skip" } }, "remote": { "serialized_dashboard": { "action": "skip" } } } } } } ``` ## Tests Updated acceptance test `acceptance/bundle/resources/dashboards/simple` now passes with no drift detected on second plan.
1 parent 7a84cf1 commit edcc112

File tree

32 files changed

+326
-224
lines changed

32 files changed

+326
-224
lines changed

acceptance/bundle/migrate/dashboards/out.new_state.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
"__id__": "[DASHBOARD_ID]",
77
"state": {
88
"display_name": "my dashboard",
9+
"embed_credentials": true,
910
"etag": "[NUMID]",
10-
"parent_path": "/Users/[USERNAME]",
11+
"parent_path": "/Workspace/Users/[USERNAME]",
12+
"serialized_dashboard": "{\"pages\":[{\"name\":\"02724bf2\",\"displayName\":\"Dashboard test bundle-deploy-dashboard\"}]}\n",
1113
"warehouse_id": "123456"
1214
}
1315
}

acceptance/bundle/migrate/dashboards/out.plan_after_migrate.json

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
{
22
"plan": {
33
"resources.dashboards.dashboard1": {
4-
"action": "recreate",
5-
"new_state": {
6-
"value": {
7-
"display_name": "my dashboard",
8-
"parent_path": "/Users/[USERNAME]",
9-
"warehouse_id": "123456"
10-
}
11-
},
4+
"action": "skip",
125
"remote_state": {
136
"create_time": "[TIMESTAMP]",
147
"dashboard_id": "[DASHBOARD_ID]",
158
"display_name": "my dashboard",
9+
"embed_credentials": true,
1610
"etag": "[NUMID]",
1711
"lifecycle_state": "ACTIVE",
1812
"parent_path": "/Workspace/Users/[USERNAME]",
@@ -23,27 +17,13 @@
2317
},
2418
"changes": {
2519
"local": {
26-
"embed_credentials": {
27-
"action": "update"
28-
},
2920
"etag": {
30-
"action": "update"
31-
},
32-
"serialized_dashboard": {
33-
"action": "update"
21+
"action": "skip"
3422
}
3523
},
3624
"remote": {
37-
"embed_credentials": {
38-
"action": "skip",
39-
"reason": "server_side_default"
40-
},
41-
"parent_path": {
42-
"action": "recreate"
43-
},
4425
"serialized_dashboard": {
45-
"action": "skip",
46-
"reason": "server_side_default"
26+
"action": "skip"
4727
}
4828
}
4929
}

acceptance/bundle/migrate/dashboards/output.txt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,17 @@ Available state files:
3232

3333

3434
>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan
35-
recreate dashboards.dashboard1
36-
37-
Plan: 1 to add, 0 to change, 1 to delete, 0 unchanged
38-
contains error: '1 unchanged' not found in the output.
35+
Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
3936

4037
>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan
41-
recreate dashboards.dashboard1
42-
43-
Plan: 1 to add, 0 to change, 1 to delete, 0 unchanged
44-
contains error: '1 unchanged' not found in the output.
38+
Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
4539

4640
>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan -o json
4741

4842
>>> print_requests.py --get //dashboards
4943

5044
>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy --auto-approve
5145
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
52-
53-
This action will result in the deletion or recreation of the following dashboards.
54-
This will result in changed IDs and permanent URLs of the dashboards that will be recreated:
55-
recreate resources.dashboards.dashboard1
5646
Deploying resources...
5747
Updating deployment state...
5848
Deployment complete!

acceptance/bundle/refschema/out.fields.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ resources.dashboards.*.permissions[*].level resources.DashboardPermissionLevel I
435435
resources.dashboards.*.permissions[*].service_principal_name string INPUT
436436
resources.dashboards.*.permissions[*].user_name string INPUT
437437
resources.dashboards.*.serialized_dashboard any ALL
438-
resources.dashboards.*.serialized_dashboard string ALL
439438
resources.dashboards.*.update_time string ALL
440439
resources.dashboards.*.url string INPUT
441440
resources.dashboards.*.warehouse_id string ALL

acceptance/bundle/resources/dashboards/change-parent-path/out.dashboardrequests.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"path": "/api/2.0/lakeview/dashboards",
44
"body": {
55
"display_name": "test dashboard",
6-
"parent_path": "/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources",
6+
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources",
77
"serialized_dashboard": "{}\n",
88
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
99
}
@@ -12,15 +12,15 @@
1212
"method": "POST",
1313
"path": "/api/2.0/workspace/mkdirs",
1414
"body": {
15-
"path": "/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources"
15+
"path": "/Workspace/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources"
1616
}
1717
}
1818
{
1919
"method": "POST",
2020
"path": "/api/2.0/lakeview/dashboards",
2121
"body": {
2222
"display_name": "test dashboard",
23-
"parent_path": "/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources",
23+
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources",
2424
"serialized_dashboard": "{}\n",
2525
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
2626
}
@@ -42,7 +42,7 @@
4242
"path": "/api/2.0/lakeview/dashboards",
4343
"body": {
4444
"display_name": "test dashboard",
45-
"parent_path": "/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources2",
45+
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources2",
4646
"serialized_dashboard": "{}\n",
4747
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
4848
}
@@ -51,15 +51,15 @@
5151
"method": "POST",
5252
"path": "/api/2.0/workspace/mkdirs",
5353
"body": {
54-
"path": "/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources2"
54+
"path": "/Workspace/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources2"
5555
}
5656
}
5757
{
5858
"method": "POST",
5959
"path": "/api/2.0/lakeview/dashboards",
6060
"body": {
6161
"display_name": "test dashboard",
62-
"parent_path": "/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources2",
62+
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources2",
6363
"serialized_dashboard": "{}\n",
6464
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
6565
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
recreate dashboards.my_dashboard
2-
3-
Plan: 1 to add, 0 to change, 1 to delete, 0 unchanged
1+
Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged

acceptance/bundle/resources/dashboards/delete-trashed-out-of-band/out.plan.direct.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@
55
"new_state": {
66
"value": {
77
"display_name": "test bundle-deploy-dashboard [UNIQUE_NAME])",
8+
"embed_credentials": false,
89
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/delete-trashed-out-of-band-[UNIQUE_NAME]/default/resources",
10+
"serialized_dashboard": "{\"pages\":[{\"name\":\"test-page\",\"displayName\":\"Test Dashboard\"}]}\n",
911
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
1012
}
1113
},
1214
"changes": {
1315
"local": {
14-
"embed_credentials": {
15-
"action": "update"
16-
},
1716
"etag": {
18-
"action": "update"
19-
},
20-
"serialized_dashboard": {
21-
"action": "update"
17+
"action": "skip"
2218
}
2319
}
2420
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"plan": {
3+
"resources.dashboards.dashboard1": {
4+
"action": "skip",
5+
"remote_state": {
6+
"create_time": "[TIMESTAMP]",
7+
"dashboard_id": "[DASHBOARD_ID]",
8+
"display_name": "test bundle-deploy-dashboard [UUID]",
9+
"embed_credentials": true,
10+
"etag": [ETAG],
11+
"lifecycle_state": "ACTIVE",
12+
"parent_path": "/Workspace/Users/[USERNAME]",
13+
"path": "/Users/[USERNAME]/test bundle-deploy-dashboard [UUID].lvdash.json",
14+
"serialized_dashboard": "{}\n",
15+
"update_time": "[TIMESTAMP]",
16+
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
17+
},
18+
"changes": {
19+
"local": {
20+
"etag": {
21+
"action": "skip"
22+
}
23+
},
24+
"remote": {
25+
"serialized_dashboard": {
26+
"action": "skip"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}

acceptance/bundle/resources/dashboards/simple/out.plan.direct.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"plan": {
3+
"resources.dashboards.dashboard1": {
4+
"action": "skip"
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)