Summary
Restructure the flat file layout into a well-organized Go package structure for better maintainability, testability, and contributor onboarding.
Architecture Changes
Current Structure
etcd-defrag/
├── main.go # Entry + CLI (mixed)
├── agent.go # All core logic (~400 lines, mixed concerns)
├── config.go # Configuration
├── endpoints.go # Endpoint management
├── evaluator.go # Rule evaluation
├── disalarm.go # Auto-disalarm
├── utils.go # Misc utilities
└── version.go # Version info
Problems
agent.go has mixed concerns - health checks, defrag, compaction, status, orchestration all in one file
- Hard to test - tightly coupled, can't mock dependencies easily
- Unclear boundaries - where should new features go?
- Difficult onboarding - new contributors struggle to navigate
Proposed Structure
etcd-defrag/
├── main.go # Minimal entry point
│
├── cmd/
│ └── root.go # CLI setup, flag registration, execution
│
├── internal/ # Private implementation packages
│ ├── agent/
│ │ ├── agent.go # Orchestration workflow
│ │ ├── agent_test.go
│ │ ├── compaction.go # Compaction operations
│ │ ├── defrag.go # Defragmentation logic
│ │ ├── disalarm.go # Auto-disalarm in agent context
│ │ ├── health.go # Health check operations
│ │ └── status.go # Member status operations
│ │
│ ├── alarm/
│ │ └── disalarm.go # Alarm management utilities
│ │
│ ├── client/
│ │ └── client.go # etcd client wrapper & TLS config
│ │
│ ├── config/
│ │ ├── config.go # Configuration struct + defaults
│ │ └── validate.go # Configuration validation
│ │
│ ├── endpoint/
│ │ ├── endpoints.go # Endpoint resolution & filtering
│ │ └── endpoints_test.go
│ │
│ └── eval/
│ ├── evaluator.go # Rule expression evaluation
│ ├── evaluator_test.go
│ └── variables.go # Evaluation variable definitions
│
└── pkg/ # Public API packages
└── version/
└── version.go # Version information
Backwards Compatibility
No breaking changes:
- Same CLI interface
- Same flags
- Same behavior
- Same output format
Notes
This is a pure refactoring with no functional changes. We should consider adding tests side by side and all existing tests must pass(code coverage expectations can be enforced later if multiple contributors start contributing and we would need high quality bits to be delivered). The goal for this issue is to prepare the codebase for future enhancements like:
- Parallel health checks
- Structured logging
- Metrics endpoint
- Better retry logic
(These are beyond the scope of this issue, but can be attempted later)
Summary
Restructure the flat file layout into a well-organized Go package structure for better maintainability, testability, and contributor onboarding.
Architecture Changes
Current Structure
Problems
agent.gohas mixed concerns - health checks, defrag, compaction, status, orchestration all in one fileProposed Structure
Backwards Compatibility
No breaking changes:
Notes
This is a pure refactoring with no functional changes. We should consider adding tests side by side and all existing tests must pass(code coverage expectations can be enforced later if multiple contributors start contributing and we would need high quality bits to be delivered). The goal for this issue is to prepare the codebase for future enhancements like:
(These are beyond the scope of this issue, but can be attempted later)