Skip to content

Conversation

@thomaspoignant
Copy link
Owner

Description

This PR implements dynamic flagset reloading for the relay-proxy, allowing flagsets to be added or removed without restarting the service. The implementation follows the requirements from issue #4288:

  • Add/remove flagsets without restart: Flagsets can now be dynamically added or removed by modifying the configuration file
  • Reject modifications to existing flagsets: If an existing flagset configuration is modified (beyond API key changes), the entire configuration change is rejected
  • Config file only: All changes are controlled through the configuration file, no API endpoints are added

Implementation Details

  1. Config File Watcher: Added a file watcher using fsnotify that monitors the configuration file for changes
  2. ReloadFlagsets Method: New method on FlagsetManager that:
    • Validates existing flagsets haven't been modified
    • Adds new flagsets
    • Removes deleted flagsets
    • Rejects the entire change if any existing flagset is modified
  3. Thread-Safe: All flagset operations are protected with mutex locks
  4. Comprehensive Tests: Added 9 test cases covering all scenarios

How to Test

  1. Start the relay-proxy with flagsets configured
  2. Modify the configuration file to add a new flagset
  3. The new flagset should be available without restart
  4. Try modifying an existing flagset configuration - it should be rejected
  5. Remove a flagset from the config - it should be removed without restart

Closes issue(s)

Resolves #4288

Checklist

  • I have tested this code
  • I have added unit test to cover this code
  • I have updated the documentation (README.md and /website/docs)
  • I have followed the contributing guide

- Add config file watcher to monitor configuration changes
- Implement ReloadFlagsets method to add/remove flagsets dynamically
- Validate that existing flagsets haven't been modified
- Reject configuration changes if existing flagsets are modified
- Add comprehensive tests for reload functionality

Resolves #4288
@netlify
Copy link

netlify bot commented Dec 10, 2025

Deploy Preview for go-feature-flag-doc-preview canceled.

Name Link
🔨 Latest commit 91c91f8
🔍 Latest deploy log https://app.netlify.com/projects/go-feature-flag-doc-preview/deploys/6939f2b75ef52b0008e1e6d1

- Extract event handling logic from startConfigWatcher into separate functions
- Split ReloadFlagsets into smaller, focused helper methods
- Improve code readability and maintainability

Fixes SonarQube cognitive complexity issues
@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

❌ Patch coverage is 60.11236% with 71 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.61%. Comparing base (57caa82) to head (91c91f8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/relayproxy/config/config.go 0.00% 29 Missing ⚠️
cmd/relayproxy/main.go 0.00% 24 Missing ⚠️
cmd/relayproxy/service/flagset_manager.go 85.60% 14 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4462      +/-   ##
==========================================
- Coverage   85.33%   84.61%   -0.73%     
==========================================
  Files         145      145              
  Lines        6056     6233     +177     
==========================================
+ Hits         5168     5274     +106     
- Misses        663      730      +67     
- Partials      225      229       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Simplify the return statement by removing the intermediate variable.
This fixes SonarQube issue AZsKQJmYYhhLTmDGVjcX.
- Replace custom fsnotify implementation with koanf's file.Provider().Watch()
- Remove direct fsnotify dependency from main.go
- Simplify file watching code by leveraging koanf's abstraction
- Add WatchConfigFile function in config package using koanf's Watch() method
- Fix linter issues: add missing ReloadFlagsets to mock and fix line length violations

This change reduces code complexity and uses the library's built-in
functionality as recommended in koanf documentation.
…warnings

- Prefix unused apiKey parameters with _ to indicate they're intentionally unused
- Fixes SonarQube rule godre:S1172 warnings
- Move fsnotify from direct to indirect dependency
- It's now only needed indirectly through koanf's file provider
@sonarqubecloud
Copy link

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(question) How to efficiently modify flagSet list

2 participants