8000 refactor(storage): move dashboard business logic out of Spanner storage by andrzejfudro · Pull Request #1196 · google/xmc · GitHub
[go: up one dir, main page]

Skip to content

refactor(storage): move dashboard business logic out of Spanner storage - #1196

Merged
andrzejfudro merged 6 commits into
mainfrom
refactor/dashboard-business-logic-out-of-spanner
Oct 12, 2026
Merged

andrzejfudro merged 6 commits into
mainfrom
refactor/dashboard-business-logic-out-of-spanner

Conversation

@andrzejfudro
Copy link
Copy Markdown
Collaborator

Summary

Moves backend-neutral dashboard and chart merging, diffing, validation, filter construction, and post-query assembly helpers out of internal/storage/spanner/dashboard/ into internal/storage/data/ (b/571899495) so Spanner and upcoming PostgreSQL repositories stay thin and share a single implementation.

Key Changes

  • internal/storage/data: Added dashboard.go and dashboard_test.go with MergeDashboards, MergeCharts, PrepareDashboardUpdate, SortChartIDs, ChartIDsEqual, BuildPositionsMap, DeduplicateAndValidateChartIDs, BuildDashboardChartLinks, BuildChartParentFilter, CombineFilters, BuildListChartsFilter, cursor extractors, and post-query dashboard/chart assembly helpers.
  • internal/storage/spanner/dashboard: Updated Spanner dashboard and chart operations (updatedashboard.go, updatechart.go, listcharts.go, listdashboards.go, chartplots.go, and data/dashboard.go) to delegate to internal/storage/data, while keeping DashboardRepository and Spanner InsertOrUpdate behavior in CreateDashboard unchanged.
  • Tests: Added unit test coverage in internal/storage/data/dashboard_test.go and updated Spanner dashboard unit/integration tests.

Verification

  • bazel test //internal/storage/data:data_test //internal/storage/spanner/dashboard/data:data_test //internal/storage/spanner/dashboard:dashboard_test //cmd/dashboard_service/... (Passed)
  • ./.githooks/pre-commit (Passed)

TAG=agy
CONV=26aeace4-784a-418b-bb9b-c768148ee3bf

Extract backend-neutral dashboard and chart business logic out of internal/storage/spanner/dashboard into internal/storage/data so it can be shared across Spanner and PostgreSQL storage repositories:
- Field-mask merging (MergeDashboards, MergeCharts), chart-ID sorting/equality (SortChartIDs, ChartIDsEqual), update diffing (PrepareDashboardUpdate), chart-ID deduplication/validation (DeduplicateAndValidateChartIDs, BuildDashboardChartLinks), and layout position mapping (BuildPositionsMap).
- Parent-to-filter conversion (BuildChartParentFilter, CombineFilters, BuildListChartsFilter), cursor extractors, and post-query plot/position/chart-ID assembly helpers (IndexDashboardsByID, AssignDashboardChartIDs, ExtractChartIDs, AssignChartPlots, BuildChartPlotsFilter, UnmarshalPlotSpec).

Keep the existing DashboardRepository interface and Spanner InsertOrUpdate (upsert) behavior in CreateDashboard unchanged.

Bug: b/571899495
TAG=agy
CONV=26aeace4-784a-418b-bb9b-c768148ee3bf
@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the storage layer by consolidating dashboard and chart helper utilities (such as merging, sorting, layout mapping, and cursor extraction) from Spanner-specific packages into a shared internal/storage/data package. Feedback on these changes focuses on addressing potential runtime panics due to missing nil checks in ExtractChartIDs and AssignChartPlots, improving error propagation in ExtractChartCursor by wrapping grpcerr.ErrInvalidArgument, and validating dashboard parent names in BuildChartParentFilter to prevent malformed filter expressions.

Comment thread internal/storage/data/dashboard.go Resolved
Comment thread internal/storage/data/dashboard.go Resolved
Comment thread internal/storage/data/dashboard.go Resolved
Comment thread internal/storage/data/dashboard.go Resolved
- Validate dashboard parent names with validator.ValidateDashboardName in BuildChartParentFilter.
- Wrap grpcerr.ErrInvalidArgument when chart is nil in ExtractChartCursor.
- Add defensive nil checks for chart elements in ExtractChartIDs and AssignChartPlots, and add unit test cases in dashboard_test.go.

Bug: b/571899495
TAG=agy
CONV=26aeace4-784a-418b-bb9b-c768148ee3bf
@andrzejfudro
andrzejfudro marked this pull request as ready for review October 12, 2026 12:08
Comment thread internal/storage/data/dashboard_test.go Resolved
Comment thread internal/storage/data/dashboard_test.go Resolved
Comment thread internal/storage/data/dashboard_test.go Resolved
…iven tests

- Remove unused UnmarshalPlotSpec pass-through wrapper and its duplicate tests from internal/storage/spanner/dashboard/data.
- Restore table-driven t.Run subtests for TestChartIDsEqual, TestExtractChartCursor, and TestExtractDashboardCursor in internal/storage/data/dashboard_test.go.
- Use cmp.Diff with protocmp.Transform() for AssignChartPlots assertions.

Bug: b/571899495
TAG=agy
CONV=26aeace4-784a-418b-bb9b-c768148ee3bf
…siness-logic-out-of-spanner

# Conflicts:
#	internal/storage/spanner/dashboard/chartplots.go
#	internal/storage/spanner/dashboard/data/dashboard.go
#	internal/storage/spanner/dashboard/listcharts.go
#	internal/storage/spanner/dashboard/listdashboards.go
#	internal/storage/spanner/dashboard/updatechart.go
#	internal/storage/spanner/dashboard/updatedashboard.go
Update xmanager_cloud/validator/validator to xmanager_cloud/internal/validator following main's Go importpath normalization (#1209, #1210).

Bug: b/571899495
TAG=agy
CONV=26aeace4-784a-418b-bb9b-c768148ee3bf
…ashboard path

Expose the dashboard messages go_proto_library under the canonical
xmanager_cloud/api/protos/dashboard importpath, keeping the legacy
xmanager_cloud/dashboard_service/proto/api_go_proto path as an
importpath alias (same pattern as api/protos/task_queue). Existing
callers are unchanged; the new internal/storage/data files use the
canonical path so check_legacy_imports.py no longer regresses.

Bug: b/571899495
TAG=agy
CONV=26aeace4-784a-418b-bb9b-c768148ee3bf
@andrzejfudro
andrzejfudro force-pushed the refactor/dashboard-business-logic-out-of-spanner branch from 5be576c to 2d60185 Compare October 12, 2026 15:10
@andrzejfudro
andrzejfudro commented Oct 12, 2026 •
Copy link
Copy Markdown
Collaborator Author

Import changes are intentional. Needed to add alias due to the parallel effort to remove compat layer.

@andrzejfudro
andrzejfudro added this pull request to the merge queue Oct 12, 2026
Merged via the queue into main with commit 903f364 Oct 12, 2026
13 checks passed
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

0