Skip to content

feat: separate config file polling from container detection#307

Merged
CybotTM merged 4 commits intomainfrom
feature/config-separation
Dec 7, 2025
Merged

feat: separate config file polling from container detection#307
CybotTM merged 4 commits intomainfrom
feature/config-separation

Conversation

@CybotTM
Copy link
Copy Markdown
Member

@CybotTM CybotTM commented Dec 7, 2025

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 only
  • events (default: true): Uses Docker events API for real-time container detection
  • docker-poll-interval (default: 0/disabled): Explicit container polling (fallback method)
  • polling-fallback (default: 10s): Auto-enables container polling if events fail

Features

  • ✅ Events enabled by default with exponential backoff reconnection (1s-5min)
  • ✅ Auto-fallback to polling when event stream fails (if configured)
  • ✅ Warning logged if both events and explicit polling are enabled (wasteful)
  • ✅ Users can now disable container polling while keeping INI file watching
  • ✅ Backwards compatibility with deprecated poll-interval and no-poll options

Breaking Changes

  • poll-intervalconfig-poll-interval (with deprecation warning)
  • no-poll → Use docker-poll-interval=0 (with deprecation warning)

Configuration Examples

[docker]
; Default: events for containers, polling for INI file
events = true
config-poll-interval = 10s

; Explicit polling only (e.g., when events are unreliable)
events = false
docker-poll-interval = 30s

; Events with auto-fallback
events = true
polling-fallback = 30s

Test Plan

  • All existing tests pass
  • Linting passes
  • CI workflow validates changes
  • Manual testing with Docker events and polling scenarios

Closes discussion from previous PR about confusing configuration.


Addresses:

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.
Copilot AI review requested due to automatic review settings December 7, 2025 10:16
@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 7, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 7, 2025

⚠️ Mutation Testing Results

Mutation Score: 0% (threshold: 60%)

⚠️ Score is below threshold. Consider improving test coverage or test quality.

What is mutation testing?

Mutation testing measures test quality by introducing small changes (mutations) to the code and checking if tests detect them. A higher score means better test effectiveness.

  • Killed mutants: Tests caught the mutation (good!)
  • Survived mutants: Tests missed the mutation (needs improvement)

Copy link
Copy Markdown

Copilot AI left a comment

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 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-interval with separate config-poll-interval (INI file watching) and docker-poll-interval (container polling) options
  • Changed default container detection from polling to Docker events API (events=true by default)
  • Implemented exponential backoff reconnection logic (1s-5min) for Docker event stream failures
  • Added automatic fallback to container polling when event subscription fails (polling-fallback option)

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

Comment thread cli/docker_config_handler.go
Comment thread cli/docker_config_handler.go
Comment thread cli/docker_config_handler.go
Comment thread cli/docker_config_handler.go Outdated
Comment thread cli/docker_config_handler.go
Comment thread cli/docker_config_handler.go
Comment thread cli/docker_config_handler.go Outdated
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.
@CybotTM CybotTM added this pull request to the merge queue Dec 7, 2025
Merged via the queue into main with commit c0a18e5 Dec 7, 2025
18 checks passed
@CybotTM CybotTM deleted the feature/config-separation branch December 7, 2025 12:22
@CybotTM CybotTM added the released:v0.15.0 Included in v0.15.0 release label Dec 22, 2025
@CybotTM
Copy link
Copy Markdown
Member Author

CybotTM commented Dec 22, 2025

🚀 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released:v0.15.0 Included in v0.15.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants