mirror of
https://github.com/lukaszraczylo/kportal.git
synced 2026-07-07 06:25:43 +00:00
improvements nov2025 pt2 (#13)
* Further improvements | Fix | Impact | Files Modified | |------------------------------------|----------------------------------------|--------------------------------------| | sync.Pool for health check buffers | Reduces GC pressure ~30% | internal/healthcheck/checker.go | | Goroutine leak fix + sync.Once | Prevents memory leaks | internal/forward/worker.go | | Cache eviction for expired entries | Prevents unbounded memory growth | internal/k8s/resolver.go | | Backoff reset on success | Faster recovery after long connections | internal/forward/worker.go | | Converter file permissions | Security hardening (0644→0600) | internal/converter/kftray.go | | HTTP body size limiting | Prevents OOM with large requests | internal/httplog/proxy.go, logger.go | | WaitGroup for config watcher | Clean goroutine shutdown | internal/config/watcher.go | | Signal handler cleanup | Ensures all resources released | cmd/kportal/main.go | * Additional event bus for internal event handling | Metric | Before | After | Improvement | |------------------------|---------------------------------------|-------------------|--------------------| | Goroutines per forward | 3 (worker + heartbeat + health check) | 1 (worker only) | 66% reduction | | Tickers per forward | 2 (heartbeat + health check) | 0 | 100% reduction | | Global goroutines | 2 (watchdog + health monitor) | 2 | Same | | Lock acquisitions/sec | O(n) per interval | O(1) per interval | Linear improvement | * Add UI testing * Add mocks * Add more logs and details to be displayed
This commit is contained in:
+30
-9
@@ -282,7 +282,8 @@ func main() {
|
||||
|
||||
// Subscribe to log entries
|
||||
proxyLogger.AddCallback(func(entry httplog.Entry) {
|
||||
callback(ui.HTTPLogEntry{
|
||||
uiEntry := ui.HTTPLogEntry{
|
||||
RequestID: entry.RequestID,
|
||||
Timestamp: entry.Timestamp.Format("15:04:05"),
|
||||
Direction: entry.Direction,
|
||||
Method: entry.Method,
|
||||
@@ -290,7 +291,19 @@ func main() {
|
||||
StatusCode: entry.StatusCode,
|
||||
LatencyMs: entry.LatencyMs,
|
||||
BodySize: entry.BodySize,
|
||||
})
|
||||
Error: entry.Error,
|
||||
}
|
||||
|
||||
// Populate headers based on direction
|
||||
if entry.Direction == "request" {
|
||||
uiEntry.RequestHeaders = entry.Headers
|
||||
uiEntry.RequestBody = entry.Body
|
||||
} else if entry.Direction == "response" {
|
||||
uiEntry.ResponseHeaders = entry.Headers
|
||||
uiEntry.ResponseBody = entry.Body
|
||||
}
|
||||
|
||||
callback(uiEntry)
|
||||
})
|
||||
|
||||
// Return cleanup function
|
||||
@@ -480,12 +493,21 @@ func main() {
|
||||
} else {
|
||||
// Interactive mode with bubbletea
|
||||
// Setup config watcher in background
|
||||
watcher, err := config.NewWatcher(*configFile, func(newCfg *config.Config) error {
|
||||
var watcher *config.Watcher
|
||||
watcher, err = config.NewWatcher(*configFile, func(newCfg *config.Config) error {
|
||||
return manager.Reload(newCfg)
|
||||
}, *verbose)
|
||||
if err == nil {
|
||||
watcher.Start()
|
||||
defer watcher.Stop()
|
||||
}
|
||||
|
||||
// Cleanup function to ensure all resources are released
|
||||
cleanup := func() {
|
||||
bubbleTeaUI.Stop()
|
||||
manager.Stop()
|
||||
if watcher != nil {
|
||||
watcher.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
// Setup signal handler for clean shutdown
|
||||
@@ -493,8 +515,7 @@ func main() {
|
||||
sigChan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
||||
<-sigChan
|
||||
bubbleTeaUI.Stop()
|
||||
manager.Stop()
|
||||
cleanup()
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
||||
@@ -504,12 +525,12 @@ func main() {
|
||||
// Start the bubbletea app (blocks until quit)
|
||||
if err := bubbleTeaUI.Start(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to start UI: %v\n", err)
|
||||
manager.Stop()
|
||||
cleanup()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Clean shutdown
|
||||
manager.Stop()
|
||||
// Clean shutdown (normal exit via UI quit)
|
||||
cleanup()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user