Add comprehensive logging and debug endpoints for production troubleshooting

- Add request logging middleware to main.go
- Add debug handler with health, config, stats, and test-dns endpoints
- Add detailed logging to DynDNS handler
- Add logging to Technitium DNS client
- Add database Ping() and GetStats() methods
- New endpoints:
  - /health - detailed health status with database and DNS checks
  - /debug/config - sanitized configuration
  - /debug/stats - database statistics
  - /debug/test-dns - live DNS test endpoint

This will help diagnose production issues with DNS updates.
This commit is contained in:
2026-02-02 22:14:24 -05:00
parent ad494fa623
commit 01694f66a8
5 changed files with 266 additions and 0 deletions

View File

@@ -54,6 +54,42 @@ func (db *DB) Close() error {
return db.conn.Close()
}
// Ping checks if the database connection is alive
func (db *DB) Ping() error {
return db.conn.Ping()
}
// GetStats returns database statistics
func (db *DB) GetStats() (map[string]interface{}, error) {
stats := make(map[string]interface{})
// Get total spaces count
var totalSpaces int
err := db.conn.QueryRow("SELECT COUNT(*) FROM spaces").Scan(&totalSpaces)
if err != nil {
return nil, err
}
stats["total_spaces"] = totalSpaces
// Get spaces with IPs (active)
var activeSpaces int
err = db.conn.QueryRow("SELECT COUNT(*) FROM spaces WHERE last_ip IS NOT NULL").Scan(&activeSpaces)
if err != nil {
return nil, err
}
stats["active_spaces"] = activeSpaces
// Get recently updated (last 24 hours)
var recentlyUpdated int
err = db.conn.QueryRow("SELECT COUNT(*) FROM spaces WHERE updated_at > datetime('now', '-1 day')").Scan(&recentlyUpdated)
if err != nil {
return nil, err
}
stats["recently_updated_24h"] = recentlyUpdated
return stats, nil
}
func (db *DB) CreateSpace(ctx context.Context, subdomain string) (*models.Space, error) {
token, err := generateToken()
if err != nil {