Commit Graph

9 Commits

Author SHA1 Message Date
00e796c608 Enhance build system and logging configuration
- Add scripts/build.sh to compile binaries into bin/ directory

- Move all zerolog setup logic from cmd/server/main.go to pkg/config

- Add log level configuration support (trace, debug, info, warn, error, fatal, panic)

- Simplify cmd/server/main.go from 57 to 27 lines (53% reduction)

- Update .gitignore to use bin/ directory instead of individual files

- Document build process and bin directory in AGENTS.md

- Maintain backward compatibility with all existing functionality
2026-04-04 13:24:33 +02:00
9855f521f3 Refactor server architecture: move internal logic to pkg/server package
- Simplify cmd/server/main.go from 158 to 57 lines (64% reduction)

- Move HTTP server creation, graceful shutdown, and context management to pkg/server

- Add Run() method to encapsulate server lifecycle management

- Maintain all existing functionality and OpenTelemetry integration

- Improve separation of concerns and code organization

This refactoring makes cmd/server/main.go a thin entrypoint while moving all server implementation details to the pkg/server package, following Go best practices for package organization.

Add server and greet binaries to .gitignore
2026-04-04 12:48:51 +02:00
Mistral Vibe
36f0b79b90 Add OpenTelemetry instrumentation with middleware-only approach 2026-04-04 12:19:48 +02:00
Gabriel Radureau
f986711974 Add readiness endpoint for graceful shutdown coordination
Implement readiness endpoint (/api/ready) that returns:
- {"ready":true} (HTTP 200) during normal operation
- {"ready":false} (HTTP 503) during graceful shutdown

Key changes:
- Added readiness context to control readiness state
- Modified server.NewServer() to accept readiness context
- Implemented handleReadiness() with context-aware logic
- Updated cmd/server/main.go to manage readiness state
- Readiness set to false when shutdown signal received
- Updated test script to validate readiness behavior
- Added comprehensive documentation for readiness endpoint

This allows Kubernetes/service meshes to stop routing traffic
to the pod during graceful shutdown while allowing existing
requests to complete. Health endpoint continues to return
happy status during shutdown for proper orchestration.
2026-04-03 19:53:14 +02:00
Gabriel Radureau
7c5e61c386 Implement comprehensive graceful shutdown with JSON logging
- Added signal.NotifyContext for modern signal handling in cmd/server/main.go
- Implemented BaseContext for proper context propagation to HTTP handlers
- Added readiness drain delay before shutdown for graceful degradation
- Fixed PID detection in start-server.sh to target actual server process
- Added Logging.JSON configuration option with DLC_LOGGING_JSON environment variable
- Created comprehensive test script that validates entire server lifecycle
- Updated documentation with JSON logging configuration examples
- All shutdown logs now appear correctly in JSON format
- Server terminates gracefully on SIGTERM with proper log flushing

The graceful shutdown implementation follows VictoriaMetrics best practices:
1. Catches termination signals (SIGTERM, SIGINT)
2. Stops accepting new requests but allows ongoing requests to complete
3. Waits for active requests to finish within configured timeout
4. Releases resources and performs cleanup
5. Logs all shutdown steps for observability

Test script validates:
- Server startup and API functionality
- Graceful shutdown sequence
- JSON log format validation
- Complete log sequence verification
- Proper signal handling and context propagation

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-03 19:23:23 +02:00
Gabriel Radureau
8103f64db9 Add configuration management with Viper
- Implement pkg/config package with Viper integration
- Support environment variables with DLC_ prefix
- Add configurable server host, port, and shutdown timeout
- Update server to use configuration values
- Add config.example.yaml template file
- Update AGENTS.md with configuration documentation
- Maintain backward compatibility with default values

Configuration options:
- DLC_SERVER_HOST (default: 0.0.0.0)
- DLC_SERVER_PORT (default: 8080)
- DLC_SHUTDOWN_TIMEOUT (default: 30s)
2026-04-03 13:53:57 +02:00
Gabriel Radureau
e52870480d Enhance server with context initialization and graceful shutdown
- Added context-aware server initialization in cmd/server/main.go
- Implemented graceful shutdown handling with SIGINT/SIGTERM signals
- Added 30-second shutdown timeout for active connections
- Updated Greet service to use context.Context as first parameter
- Enhanced Zerolog integration with Trace level logging
- Added context-aware logging in Greet function calls
- Fixed route structure to use /api/v1/greet/* prefix
- Updated all handlers and tests to use context
- Comprehensive AGENTS.md documentation with verified commands
- Added server context management architecture section
- Updated API endpoint documentation with working examples

Changes:
- cmd/server/main.go: Complete rewrite with context and graceful shutdown
- pkg/greet/greet.go: Added context parameter and trace logging
- pkg/greet/api_v1.go: Updated interface and handlers for context
- pkg/greet/greet_test.go: Updated tests to use context
- cmd/greet/main.go: Updated CLI to use context
- pkg/server/server.go: Trace level config and context logging
- AGENTS.md: Comprehensive documentation update
- go.mod/go.sum: Added Zerolog dependency

All tests passing, server working with graceful shutdown verified.
2026-04-03 13:39:50 +02:00
Gabriel Radureau
6365f92359 Refactor to JSON API with Chi router and interface-based design
- Add pkg/greet/api_v1.go with ApiV1Greet interface and handler
- Implement Greeter interface for dependency injection
- Return JSON responses with proper Content-Type headers
- Move greet service instantiation to server package
- Separate v1 route registration into registerApiV1Routes function
- Health endpoint at /api level, greet endpoints at /api/v1/greet
- Simplify server entrypoint by removing external dependencies
2026-04-03 13:04:33 +02:00
Gabriel Radureau
3efc1992d5 Initial commit: Go project with greet function and CLI 2026-04-03 12:20:55 +02:00