refactor(control-plane): split handlers/ui/dashboard.go into cache/format/aggregate files#480
Open
kiranannadatha8 wants to merge 1 commit intoAgent-Field:mainfrom
Open
Conversation
…files
Splits the 1493 LOC dashboard.go (29 functions, 20+ types, 4 mixed
concerns) into four cohesive files within the same handlers/ui package:
dashboard.go (348 LOC) - DashboardHandler + 2 public handlers
+ request-parsing helpers + base
response types
dashboard_cache.go (146 LOC) - DashboardCache, EnhancedDashboardCache,
TimeRangePreset, cache key/TTL utils
dashboard_format.go (177 LOC) - response-shape type declarations
dashboard_aggregate.go (839 LOC) - build*/get* aggregators and helpers
Pure file moves within package ui: no renames, no behavior change, no
exported-API change. All imports and callers (server.go route
registration, same-package tests) resolve unchanged.
Prep work for the WP7 test-coverage push — smaller files give tests a
narrower surface to target.
Closes Agent-Field#417
Co-Authored-By: Claude <noreply@anthropic.com>
3a10420 to
285f6bc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #417
Summary
Splits
control-plane/internal/handlers/ui/dashboard.go(1493 LOC, 29 funcs, 20+ types, 4 mixed concerns) into four focused files within the samehandlers/uipackage. Pure file moves: no renames, no behavior change, no exported-API change.File layout
dashboard.goDashboardHandler+ constructor; base response types (DashboardSummaryResponse,AgentsSummary,ExecutionsSummary,PackagesSummary); both public handlers (GetDashboardSummaryHandler,GetEnhancedDashboardSummaryHandler); request-parsing helpers (parseTimeRangeParams,calculateComparisonPeriod)dashboard_cache.goDashboardCache+ 3 methods;TimeRangePresettype + 5 constants;EnhancedDashboardCache+enhancedCacheEntry+ 3 methods;getTTLForPreset,generateCacheKeydashboard_format.goEnhancedDashboardResponse,EnhancedOverview,ExecutionTrends,AgentHealthSummary,WorkflowInsights,IncidentItem, heatmap/hotspot types, etc.)dashboard_aggregate.gobuild*aggregators (10);get*Summarygetters (3); helperscalculateSuccessRate,computeMedian,maxTimeBefore: 1 file × 1493 LOC → After: 4 files × {348, 146, 177, 839} LOC (sum 1510; +17 lines from 3 extra
package+ import blocks).Why this split
The issue proposed
dashboard.go/dashboard_aggregate.go/dashboard_format.go/dashboard_cache.go. The existing code has no literalformat*helpers — response shaping lives in struct tags — sodashboard_format.goholds the response-shape types, which is the spirit of the proposal (a file dedicated to response shape, separate from handlers and aggregators). Happy to fold the types back intodashboard.goif the reviewer prefers; the diff is tiny either way.Guardrails respected
diff <(grep '^(func|type) ' original | sort) <(grep '^(func|type) ' new/* | sort)is empty)diffagainstHEAD:dashboard.go)server/server.go:1249-1251route registration + allhandlers/ui/*_test.gofiles reference exported symbols by name; same-package visibility preserved)Test plan
cd control-plane && go test ./internal/handlers/ui/... -count=1→okin 6.038s (primary gate from the issue)cd control-plane && go build ./...→ greencd control-plane && go vet ./internal/handlers/ui/...→ cleangofmt -l control-plane/internal/handlers/ui/dashboard*.go→ cleancd control-plane && go test ./... -count=1→ everything passes except two pre-existing failures ininternal/server(TestGenerateAgentFieldServerIDFallsBackWhenGetwdFails,TestStartAdminGRPCServerReturnsListenError) which also fail on a fresh clone ofmain— environment-specific, unrelated to this PRNote on
-race:go test ./internal/handlers/ui/... -racetripscheckptrinsidegithub.com/boltdb/bolt@v1.3.1(an unsafe pointer cast in the dep) under Go 1.26. This also reproduces on upstreammainand is outside this PR's scope.AI assistance
Authored with AI assistance (Claude Code). Please apply the
ai-assistedtag.