Files
mev-beta/orig/pkg/health/pprof_integration.go
Administrator 803de231ba feat: create v2-prep branch with comprehensive planning
Restructured project for V2 refactor:

**Structure Changes:**
- Moved all V1 code to orig/ folder (preserved with git mv)
- Created docs/planning/ directory
- Added orig/README_V1.md explaining V1 preservation

**Planning Documents:**
- 00_V2_MASTER_PLAN.md: Complete architecture overview
  - Executive summary of critical V1 issues
  - High-level component architecture diagrams
  - 5-phase implementation roadmap
  - Success metrics and risk mitigation

- 07_TASK_BREAKDOWN.md: Atomic task breakdown
  - 99+ hours of detailed tasks
  - Every task < 2 hours (atomic)
  - Clear dependencies and success criteria
  - Organized by implementation phase

**V2 Key Improvements:**
- Per-exchange parsers (factory pattern)
- Multi-layer strict validation
- Multi-index pool cache
- Background validation pipeline
- Comprehensive observability

**Critical Issues Addressed:**
- Zero address tokens (strict validation + cache enrichment)
- Parsing accuracy (protocol-specific parsers)
- No audit trail (background validation channel)
- Inefficient lookups (multi-index cache)
- Stats disconnection (event-driven metrics)

Next Steps:
1. Review planning documents
2. Begin Phase 1: Foundation (P1-001 through P1-010)
3. Implement parsers in Phase 2
4. Build cache system in Phase 3
5. Add validation pipeline in Phase 4
6. Migrate and test in Phase 5

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 10:14:26 +01:00

64 lines
2.3 KiB
Go

package health
import (
"net/http"
_ "net/http/pprof" // Import for side effects (registers pprof handlers)
"github.com/fraktal/mev-beta/internal/logger"
)
// PprofHandler provides production-safe pprof profiling endpoints
type PprofHandler struct {
logger *logger.Logger
enabled bool
}
// NewPprofHandler creates a new pprof handler
func NewPprofHandler(logger *logger.Logger, enabled bool) *PprofHandler {
return &PprofHandler{
logger: logger,
enabled: enabled,
}
}
// RegisterHTTPHandlers registers pprof handlers if enabled
func (p *PprofHandler) RegisterHTTPHandlers(mux *http.ServeMux) {
if !p.enabled {
p.logger.Info("🔒 pprof profiling endpoints disabled")
return
}
// pprof handlers are automatically registered on DefaultServeMux
// We need to proxy them to our custom mux
mux.HandleFunc("/debug/pprof/", func(w http.ResponseWriter, r *http.Request) {
http.DefaultServeMux.ServeHTTP(w, r)
})
mux.HandleFunc("/debug/pprof/cmdline", func(w http.ResponseWriter, r *http.Request) {
http.DefaultServeMux.ServeHTTP(w, r)
})
mux.HandleFunc("/debug/pprof/profile", func(w http.ResponseWriter, r *http.Request) {
http.DefaultServeMux.ServeHTTP(w, r)
})
mux.HandleFunc("/debug/pprof/symbol", func(w http.ResponseWriter, r *http.Request) {
http.DefaultServeMux.ServeHTTP(w, r)
})
mux.HandleFunc("/debug/pprof/trace", func(w http.ResponseWriter, r *http.Request) {
http.DefaultServeMux.ServeHTTP(w, r)
})
p.logger.Info("✅ pprof profiling endpoints enabled at /debug/pprof/")
p.logger.Info(" Available endpoints:")
p.logger.Info(" - /debug/pprof/ - Index of available profiles")
p.logger.Info(" - /debug/pprof/heap - Memory heap profile")
p.logger.Info(" - /debug/pprof/goroutine - Goroutine profile")
p.logger.Info(" - /debug/pprof/profile - CPU profile (30s by default)")
p.logger.Info(" - /debug/pprof/block - Block profile")
p.logger.Info(" - /debug/pprof/mutex - Mutex profile")
p.logger.Info(" - /debug/pprof/trace - Execution trace")
p.logger.Info("")
p.logger.Info(" Usage examples:")
p.logger.Info(" go tool pprof http://localhost:6060/debug/pprof/heap")
p.logger.Info(" go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30")
p.logger.Info(" curl http://localhost:6060/debug/pprof/goroutine?debug=1")
}