Skip to content

Ft: Refactor codebase for health logging and different routing stragety - #73

Merged
MonkyMars merged 5 commits into
mainfrom
monitor/services
Oct 9, 2025
Merged

Ft: Refactor codebase for health logging and different routing stragety#73
MonkyMars merged 5 commits into
mainfrom
monitor/services

Conversation

@MonkyMars

@MonkyMars MonkyMars commented Oct 8, 2025

Copy link
Copy Markdown
Owner

IMPORTANT: Use this template for all PRs to ensure consistency.

You can remove sections that do not apply to your change.

Description & Motivation

Introduces a bunch of new features, leveling up the api

Related Issues

Relates #28

(Only include “Closes” for issues you intend this PR to fully resolve.)

Scope of Change

(Mark or list the relevant ones)

  • New feature
  • Bug fix
  • Refactor / cleanup
  • Documentation
  • Breaking change

@MonkyMars MonkyMars self-assigned this Oct 8, 2025
Copilot AI review requested due to automatic review settings October 8, 2025 22:13
@MonkyMars MonkyMars added enhancement New feature or request go/fiber Updates the go fiber server labels Oct 8, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a comprehensive refactoring of the PWS codebase to add health logging capabilities and implement different routing strategies. The main goal is to level up the API with better monitoring, improved worker management, and more robust configuration.

  • Introduces a new health monitoring system with dedicated workers and middleware
  • Refactors worker management from global singleton pattern to dependency injection pattern
  • Adds circuit breaker patterns for database operations to improve resilience

Reviewed Changes

Copilot reviewed 38 out of 39 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
apps/server/workers/manager_test.go New comprehensive test suite for the worker manager with concurrency and benchmark tests
apps/server/workers/manager.go New worker manager implementation with dependency injection and coordinated lifecycle management
apps/server/workers/helper.go Dead letter queue implementation for handling failed audit operations
apps/server/workers/health_worker.go Health monitoring worker for tracking API route metrics and service health
apps/server/workers/cleanup_worker.go Dedicated cleanup worker with scheduled maintenance operations
apps/server/workers/audit_worker.go Refactored audit worker with improved error handling and circuit breaker patterns
apps/server/types/config.go Extended configuration types with health monitoring and Google OAuth support
apps/server/types/app.go Updated health response structure and added health log type definitions
apps/server/tests/health_logs_test.go Test coverage for health logging functionality
apps/server/tests/health_endpoints_test.go Comprehensive tests for health monitoring endpoints with panic protection
apps/server/services/database.go Enhanced database service with circuit breaker protection
apps/server/main.go Updated application initialization to use new worker manager pattern
apps/server/lib/constants.go Added health logs table constant
apps/server/lib/circuit_breaker.go New circuit breaker implementation for database resilience
apps/server/database/migrations/create_health_logs.sql Database schema for health logging storage
apps/server/config/logger.go Added audit warning capability for improved logging granularity
apps/server/config/domains.go New domain-specific configuration management for better separation of concerns
apps/server/config/config.go Refactored configuration to support domain-based organization
apps/server/api/routes/workers.go New worker monitoring endpoints for health status and metrics
apps/server/api/routes/manager.go Route manager for coordinating different route groups
apps/server/api/routes/health.go Health check endpoints with admin middleware protection
apps/server/api/routes/files.go Refactored file routes to use new route manager pattern
apps/server/api/routes/auth.go Updated authentication routes for new router architecture
apps/server/api/router.go Enhanced router with health middleware and route discovery
apps/server/api/middleware/health.go New middleware for automatic health metric collection
apps/server/api/middleware/auth.go Added admin middleware for protected endpoints
apps/server/api/internal/workers.go Worker health monitoring API handlers
apps/server/api/internal/files/upload.go Updated file upload handlers for new router structure
apps/server/api/internal/files/retrieve.go Updated file retrieval handlers
apps/server/api/internal/files/manager.go File routes manager implementation
apps/server/api/internal/auth/google_oauth.go Moved Google OAuth handlers to auth package
apps/server/api/internal/auth/auth.go Refactored authentication handlers with improved structure
apps/server/api/internal/app.go Updated application handlers with simplified health responses
apps/server/.env.example Updated environment configuration with new health monitoring settings

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +180 to +200
wg.Go(func() {
if err := wm.auditWorker.Stop(ctx); err != nil {
errChan <- fmt.Errorf("audit worker stop error: %w", err)
}
})
}

if wm.healthWorker != nil {
wg.Go(func() {
if err := wm.healthWorker.Stop(ctx); err != nil {
errChan <- fmt.Errorf("health worker stop error: %w", err)
}
})
}

if wm.cleanupWorker != nil {
wg.Go(func() {
if err := wm.cleanupWorker.Stop(ctx); err != nil {
errChan <- fmt.Errorf("cleanup worker stop error: %w", err)
}
})

Copilot AI Oct 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method wg.Go does not exist on sync.WaitGroup. Use wg.Add(1) followed by go func() { defer wg.Done(); ... }() pattern instead.

Suggested change
wg.Go(func() {
if err := wm.auditWorker.Stop(ctx); err != nil {
errChan <- fmt.Errorf("audit worker stop error: %w", err)
}
})
}
if wm.healthWorker != nil {
wg.Go(func() {
if err := wm.healthWorker.Stop(ctx); err != nil {
errChan <- fmt.Errorf("health worker stop error: %w", err)
}
})
}
if wm.cleanupWorker != nil {
wg.Go(func() {
if err := wm.cleanupWorker.Stop(ctx); err != nil {
errChan <- fmt.Errorf("cleanup worker stop error: %w", err)
}
})
wg.Add(1)
go func() {
defer wg.Done()
if err := wm.auditWorker.Stop(ctx); err != nil {
errChan <- fmt.Errorf("audit worker stop error: %w", err)
}
}()
}
if wm.healthWorker != nil {
wg.Add(1)
go func() {
defer wg.Done()
if err := wm.healthWorker.Stop(ctx); err != nil {
errChan <- fmt.Errorf("health worker stop error: %w", err)
}
}()
}
if wm.cleanupWorker != nil {
wg.Add(1)
go func() {
defer wg.Done()
if err := wm.cleanupWorker.Stop(ctx); err != nil {
errChan <- fmt.Errorf("cleanup worker stop error: %w", err)
}
}()

Copilot uses AI. Check for mistakes.
Comment thread apps/server/workers/helper.go
Comment thread apps/server/config/domains.go Outdated
Comment thread apps/server/config/domains.go Outdated
Comment thread apps/server/main.go
Comment thread apps/server/api/middleware/auth.go
MonkyMars and others added 4 commits October 9, 2025 00:15
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@MonkyMars
MonkyMars merged commit 829e6c1 into main Oct 9, 2025
9 of 11 checks passed
@MonkyMars
MonkyMars deleted the monitor/services branch October 9, 2025 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go/fiber Updates the go fiber server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants