feat: config.toml 增加 watch reload 能力#1452
Open
0x0034 wants to merge 1 commit into
Open
Conversation
Signed-off-by: ruochen <wanxialianwei@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds config.toml hot-reload support (watch + debounce) and refactors startup/reload flow so the agent and writers can be rebuilt and restarted when configuration changes.
Changes:
- Introduces
global.reload_on_changeand a filesystem watcher (pkg/reloadwatcher) to trigger reloads whenconfig.tomlchanges. - Adds a new
agentRuntimethat coordinates config reload, writer rebuild/apply, agent restart, and watcher lifecycle. - Refactors writer initialization to support rebuilding and applying writer maps safely, plus adds unit tests for reload behavior.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| writer/writers.go | Refactors writer initialization/reload; adds BuildWriters, ApplyWriters, and improves concurrent access in WriteTimeSeries. |
| writer/writers_test.go | Adds a unit test ensuring writer reload replaces writer map while preserving the queue. |
| pkg/reloadwatcher/reloadwatcher.go | Adds a debounced fsnotify-based watcher for a single target file. |
| pkg/reloadwatcher/reloadwatcher_test.go | Adds debounce/target-filtering tests for the watcher. |
| main.go | Switches runtime control from agent.Agent to agentRuntime and routes SIGHUP to runtime reload. |
| main_windows.go | Updates Windows service/interactive execution to use agentRuntime. |
| main_posix.go | Updates POSIX run loop to use agentRuntime. |
| main_other.go | Updates non-windows/non-linux run loop to use agentRuntime. |
| go.mod | Makes github.com/fsnotify/fsnotify a direct dependency. |
| config/config.go | Adds ReloadOnChange, factors out LoadConfig, and makes InitConfig safer about updating global Config. |
| config/config_test.go | Adds a test ensuring failed config reload does not overwrite the current config. |
| conf/config.toml | Documents the new reload_on_change option. |
| agent_runtime.go | Adds the new runtime responsible for reload orchestration and config.toml watching. |
| agent_runtime_test.go | Adds unit tests for runtime reload success/failure behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+103
to
+118
| currentConfig := config.Config | ||
| currentAgent := rt.agent | ||
| rt.deps.applyConfig(nextConfig) | ||
|
|
||
| nextAgent, err := rt.deps.newAgent() | ||
| if err != nil { | ||
| rt.deps.applyConfig(currentConfig) | ||
| return err | ||
| } | ||
|
|
||
| currentAgent.Stop() | ||
| rt.deps.applyWriters(nextWriters) | ||
| rt.agent = nextAgent | ||
| rt.deps.initLog(nextConfig.Log.FileName) | ||
| rt.agent.Start() | ||
| rt.reconcileWatcherLocked() |
|
|
||
| import ( | ||
| "log" | ||
| "path" |
Comment on lines
+99
to
+103
| case _, ok := <-w.watcher.Errors: | ||
| if !ok { | ||
| return | ||
| } | ||
| case <-timerC: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.