Skip to content

feat: config.toml 增加 watch reload 能力#1452

Open
0x0034 wants to merge 1 commit into
flashcatcloud:mainfrom
0x0034:feature/config-reload-on-change
Open

feat: config.toml 增加 watch reload 能力#1452
0x0034 wants to merge 1 commit into
flashcatcloud:mainfrom
0x0034:feature/config-reload-on-change

Conversation

@0x0034

@0x0034 0x0034 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: ruochen <wanxialianwei@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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_change and a filesystem watcher (pkg/reloadwatcher) to trigger reloads when config.toml changes.
  • Adds a new agentRuntime that 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 thread agent_runtime.go
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()
Comment thread agent_runtime.go

import (
"log"
"path"
Comment on lines +99 to +103
case _, ok := <-w.watcher.Errors:
if !ok {
return
}
case <-timerC:
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.

2 participants