feat: separate config file polling from container detection#307
feat: separate config file polling from container detection#307
Conversation
BREAKING CHANGE: Configuration options renamed for clarity - poll-interval → config-poll-interval (for INI file watching) - no-poll → (removed, use docker-poll-interval=0) New configuration model with separated concerns: - config-poll-interval: INI file change detection (default: 10s) - events: Docker events for container detection (default: true) - docker-poll-interval: Explicit container polling (default: 0/disabled) - polling-fallback: Auto-fallback interval if events fail (default: 10s) Key features: - Events enabled by default with exponential backoff reconnection - Auto-fallback to polling when event stream fails (if configured) - Warning logged if both events and explicit polling are enabled - Backwards compatibility with deprecated poll-interval/no-poll options This allows users to disable container polling while keeping INI file watching, and provides resilient container detection via events with optional automatic fallback.
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
There was a problem hiding this comment.
Pull request overview
This PR redesigns Ofelia's configuration model to cleanly separate INI configuration file polling from Docker container detection mechanisms. Previously, both concerns were conflated under a single poll-interval setting, leading to confusion about what was being polled. The refactoring introduces explicit, well-named configuration options and implements Docker events as the default container detection method with automatic fallback to polling when events fail.
Key Changes:
- Replaced monolithic
poll-intervalwith separateconfig-poll-interval(INI file watching) anddocker-poll-interval(container polling) options - Changed default container detection from polling to Docker events API (
events=trueby default) - Implemented exponential backoff reconnection logic (1s-5min) for Docker event stream failures
- Added automatic fallback to container polling when event subscription fails (
polling-fallbackoption)
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| cli/config.go | Adds new configuration fields (ConfigPollInterval, DockerPollInterval, PollingFallback) with comprehensive documentation; changes UseEvents default from false to true; retains deprecated fields for backward compatibility |
| cli/docker_config_handler.go | Core implementation: adds resolveConfig() for deprecation handling; splits original watch() into watchConfig(), watchEvents(), and watchContainerPolling(); implements event stream reconnection with exponential backoff and automatic fallback mechanism |
| cli/docker_handler_test.go | Updates test to reflect renamed field configPollInterval and renamed method watchConfig() |
| cli/daemon_lifecycle_test.go | Updates all mock DockerHandler initializations to use new field names (configPollInterval, dockerPollInterval, pollingFallback) |
| cli/config_initialize_test.go | Updates mock DockerHandler factory functions to use new configuration field names |
| README.md | Comprehensive documentation update explaining the separation of concerns, new configuration options, CLI flags, and backward compatibility with deprecated options |
Address Copilot review feedback from PR #306: - Use comma-ok idiom for errCh and eventCh to detect channel closure - Extract handleEventStreamError() and clearEventStreamError() helpers - Reduce watchEvents() cyclomatic complexity from 17 to 12 Channel closure now properly triggers reconnection instead of potential busy-wait on closed channels.
Force early API version negotiation by calling NegotiateAPIVersion() before returning the client. This prevents race conditions when concurrent goroutines (e.g., Events and ContainerList) make their first API calls simultaneously.
Address Copilot review feedback: - Stop fallback polling when events recover (clearEventStreamError) - Add backward compatibility: poll-interval now sets polling-fallback - Add comprehensive tests for: - resolveConfig() with deprecated option migration - watchContainerPolling() lifecycle - startFallbackPolling() activation and cancellation - Event recovery stopping fallback polling The fallback polling mechanism now properly cleans up when the Docker event stream recovers, preventing resource waste from redundant polling.
|
🚀 Released in v0.15.0 Thank you for your contribution! 🙏 This is now available in the latest release. Please test and verify everything works as expected in your environment. If you encounter any issues, please open a new issue. |
Summary
This PR redesigns the configuration model to clearly separate INI config file polling from Docker container detection, addressing confusion where these concerns were mixed under
poll-interval.Key Changes
config-poll-interval(default: 10s): Polls for INI configuration file changes onlyevents(default: true): Uses Docker events API for real-time container detectiondocker-poll-interval(default: 0/disabled): Explicit container polling (fallback method)polling-fallback(default: 10s): Auto-enables container polling if events failFeatures
poll-intervalandno-polloptionsBreaking Changes
poll-interval→config-poll-interval(with deprecation warning)no-poll→ Usedocker-poll-interval=0(with deprecation warning)Configuration Examples
Test Plan
Closes discussion from previous PR about confusing configuration.
Addresses: