Skip to content

Conversation

MinatoWu
Copy link
Contributor

Feat-conf hot-loading capacity

Fix :#2925

@codecov-commenter
Copy link

codecov-commenter commented Aug 27, 2025

Codecov Report

❌ Patch coverage is 48.27586% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.83%. Comparing base (60d1c2a) to head (0c14e87).
⚠️ Report is 630 commits behind head on develop.

Files with missing lines Patch % Lines
loader.go 48.27% 55 Missing and 5 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2992      +/-   ##
===========================================
- Coverage    46.76%   39.83%   -6.94%     
===========================================
  Files          295      457     +162     
  Lines        17172    38992   +21820     
===========================================
+ Hits          8031    15533    +7502     
- Misses        8287    22182   +13895     
- Partials       854     1277     +423     

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

@MinatoWu
Copy link
Contributor Author

todo :Limit critical configuration hot updates

Copy link
Contributor

@Copilot 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 implements hot-loading capacity for configuration files, allowing the application to automatically reload configuration changes without requiring a restart. The implementation adds file system watching capabilities to detect configuration file modifications and triggers hot reloads when changes occur.

  • Adds file system watcher using fsnotify to monitor configuration file changes
  • Implements hot reload functionality that updates instanceOptions and logger level dynamically
  • Introduces graceful shutdown mechanism for the file watcher with proper cleanup

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

Comment on lines +52 to +54
once sync.Once
stopCh = make(chan struct{})
watcherWg sync.WaitGroup
Copy link
Preview

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

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

Global variables for concurrency control create potential race conditions. The stopCh channel and watcherWg should be encapsulated within a struct or managed differently to avoid shared mutable state across goroutines.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, can not agree with you more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, can not agree with you more.

Thanks for the suggestion—given our single watcher and Once/stopOnce guards, this is safe; we’ll consider encapsulation if we later support multiple or restartable watchers

Comment on lines +138 to +139
// Any part of the application that accesses instanceOptions directly will now use the new values.
instanceOptions = newOpts
Copy link
Preview

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

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

Direct assignment to the global instanceOptions variable creates a race condition. Multiple goroutines could be reading instanceOptions while it's being updated, leading to inconsistent state. Consider using atomic operations or proper synchronization mechanisms.

Copilot uses AI. Check for mistakes.

loader.go Outdated
Comment on lines 421 to 426
func StopFileWatcher() {
logger.Info("Stopping file watcher...")
close(stopCh)
watcherWg.Wait()
logger.Info("File watcher stopped successfully")
}
Copy link
Preview

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

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

Closing stopCh multiple times will cause a panic. The function should check if the channel is already closed or use a sync.Once to ensure it's only closed once.

Copilot uses AI. Check for mistakes.

@@ -64,9 +72,81 @@ func Load(opts ...LoaderConfOption) error {
}

instance := &Instance{insOpts: instanceOptions}
// start the file watcher
once.Do(func() {
Copy link
Preview

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

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

The watcherWg.Add() should be called before starting the goroutine to avoid race conditions where StopFileWatcher() could call Wait() before the goroutine increments the counter.

Suggested change
once.Do(func() {
once.Do(func() {
watcherWg.Add(1)

Copilot uses AI. Check for mistakes.

Copy link

sonarqubecloud bot commented Sep 7, 2025

@MinatoWu
Copy link
Contributor Author

MinatoWu commented Sep 7, 2025

Pull Request Overview

This PR implements hot-loading capacity for configuration files, allowing the application to automatically reload configuration changes without requiring a restart. The implementation adds file system watching capabilities to detect configuration file modifications and triggers hot reloads when changes occur.

  • Adds file system watcher using fsnotify to monitor configuration file changes
  • Implements hot reload functionality that updates instanceOptions and logger level dynamically
  • Introduces graceful shutdown mechanism for the file watcher with proper cleanup

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

done

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.

3 participants