Skip to content

refactor(control-plane): split handlers/ui/dashboard.go into cache/format/aggregate files#480

Open
kiranannadatha8 wants to merge 1 commit intoAgent-Field:mainfrom
kiranannadatha8:refactor/split-dashboard-handler
Open

refactor(control-plane): split handlers/ui/dashboard.go into cache/format/aggregate files#480
kiranannadatha8 wants to merge 1 commit intoAgent-Field:mainfrom
kiranannadatha8:refactor/split-dashboard-handler

Conversation

@kiranannadatha8
Copy link
Copy Markdown

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 same handlers/ui package. Pure file moves: no renames, no behavior change, no exported-API change.

File layout

File LOC Contents
dashboard.go 348 DashboardHandler + constructor; base response types (DashboardSummaryResponse, AgentsSummary, ExecutionsSummary, PackagesSummary); both public handlers (GetDashboardSummaryHandler, GetEnhancedDashboardSummaryHandler); request-parsing helpers (parseTimeRangeParams, calculateComparisonPeriod)
dashboard_cache.go 146 DashboardCache + 3 methods; TimeRangePreset type + 5 constants; EnhancedDashboardCache + enhancedCacheEntry + 3 methods; getTTLForPreset, generateCacheKey
dashboard_format.go 177 Response-shape type declarations only (EnhancedDashboardResponse, EnhancedOverview, ExecutionTrends, AgentHealthSummary, WorkflowInsights, IncidentItem, heatmap/hotspot types, etc.)
dashboard_aggregate.go 839 All build* aggregators (10); get*Summary getters (3); helpers calculateSuccessRate, computeMedian, maxTime

Before: 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 literal format* helpers — response shaping lives in struct tags — so dashboard_format.go holds 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 into dashboard.go if the reviewer prefers; the diff is tiny either way.

Guardrails respected

  • No renames (every symbol preserved — diff <(grep '^(func|type) ' original | sort) <(grep '^(func|type) ' new/* | sort) is empty)
  • No behavior change (byte-identical function bodies — verified with ranged diff against HEAD:dashboard.go)
  • No caller changes needed (server/server.go:1249-1251 route registration + all handlers/ui/*_test.go files reference exported symbols by name; same-package visibility preserved)
  • Scope limited to the four dashboard files

Test plan

  • cd control-plane && go test ./internal/handlers/ui/... -count=1ok in 6.038s (primary gate from the issue)
  • cd control-plane && go build ./...green
  • cd control-plane && go vet ./internal/handlers/ui/...clean
  • gofmt -l control-plane/internal/handlers/ui/dashboard*.goclean
  • cd control-plane && go test ./... -count=1 → everything passes except two pre-existing failures in internal/server (TestGenerateAgentFieldServerIDFallsBackWhenGetwdFails, TestStartAdminGRPCServerReturnsListenError) which also fail on a fresh clone of main — environment-specific, unrelated to this PR
  • CI green

Note on -race: go test ./internal/handlers/ui/... -race trips checkptr inside github.com/boltdb/bolt@v1.3.1 (an unsafe pointer cast in the dep) under Go 1.26. This also reproduces on upstream main and is outside this PR's scope.

AI assistance

Authored with AI assistance (Claude Code). Please apply the ai-assisted tag.

@kiranannadatha8 kiranannadatha8 requested review from a team and AbirAbbas as code owners April 19, 2026 03:19
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 19, 2026

CLA assistant check
All committers have signed the CLA.

…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>
@kiranannadatha8 kiranannadatha8 force-pushed the refactor/split-dashboard-handler branch from 3a10420 to 285f6bc Compare April 19, 2026 03:46
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.

[Refactor] Split control-plane/internal/handlers/ui/dashboard.go (1493 LOC)

2 participants