This file guides AI coding agents working on the conf-agent/ codebase.
conf-agent is the configuration delivery sidecar of AI Gateway. It polls ai-gateway-api for the latest data-plane configuration, persists it locally, triggers BFE hot reload, and keeps a bounded set of versioned config directories.
AI Gateway system context (for orientation only):
- AI Gateway API (
rainway-ai-gateway/ai-gateway-api): control plane, exposes Open/Inner APIs. - BFE (
bfenetworks/bfe): data plane, forwards traffic and consumes the configuration. - conf-agent (this repo): fetches configuration and triggers BFE hot reload.
- Dashboard (
rainway-ai-gateway/ai-gateway-web): Web UI for visual management. - Service Controller (
bfenetworks/service-controller): discovers and syncs Kubernetes backend services.
Entry point: main.go
- Parses flags (
-c conf_dir,-cf conf-agent.toml). - Loads config via
config.Init. - Initializes logging via
xlog.Init. - Creates and starts
agent.Agent, which owns one or moreconf_reload.Reloadergoroutines.
Request flow per Reloader:
- prober (
conf_reload/prober/): pollsai-gateway-apiInnerAPI endpoints and returns new/updated config files. - file_store (
conf_reload/file_store/): writes files into a temporary version directory, then switches the symlinkmod_{name}to the new version and cleans up old versions according toVersionKeepCount. - trigger (
conf_reload/trigger/): calls BFE/reload/{module}monitor port endpoint to perform hot reload.
| Directory | Responsibility |
|---|---|
agent/ |
Lifecycle container that starts/stops all Reloaders. |
conf_reload/ |
Core reload orchestration: Reloader, plus sub-packages for prober, file_store, and trigger. |
conf_reload/prober/ |
Fetches configuration from ai-gateway-api. Supports normal, multi-key JSON, and extra-file tasks. |
conf_reload/file_store/ |
Persists config to disk, manages versioned directories, symlinks, and cleanup. |
conf_reload/trigger/ |
Calls BFE monitor-port reload endpoint. |
config/ |
TOML config loading and ReloaderConfig construction. |
xfile/ |
File-system utilities: copy, symlink, junction helpers. |
xhttp/ |
HTTP client helpers. |
xlog/ |
Structured logging. |
version/ |
Version constant. |
conf/ |
Runtime TOML configuration samples. |
docs/ |
User and design documentation (zh_cn/, en_us/). |
test/ |
Integration tests using in-process httptest servers. |
- Go version: 1.22 (
go.mod). - Module:
github.com/rainway-ai-gateway/conf-agent. - Build:
makeormake buildproduces./conf-agent. - Static build:
make build-static. - Cross-compile release:
make releasebuildslinux/amd64andlinux/arm64tarballs indist/. - Test:
go test ./...runs all unit tests.cd test/integration && go test -v -count=1 ./tests/...runs integration tests.
- License headers:
make license-check/make license-fixuselicense-eye. - Start locally:
./conf-agent -c ./conf -cf conf-agent.toml
- Update
config/config.goandconfig/config_file.goif new config fields are needed. - Implement logic in the relevant
conf_reload/sub-package (prober,file_store, ortrigger). - Wire the new behavior into
conf_reload/reloader.go. - Add unit tests in the sub-package (
*_test.go) and integration tests intest/integration/if a full reload flow is affected. - Update
docs/zh_cn/sys-design/anddocs/zh_cn/config/config.mdif behavior changes are user-visible.
- Primary code:
conf_reload/file_store/file_store.go. - Cross-platform concerns: Windows junctions vs. Unix symlinks (
xfile/helpers). - Integration tests should cover both successful switch and cleanup, and failure rollback.
- Primary code:
conf_reload/trigger/. - Verify timeout, URL construction, and status-code handling.
- Primary code:
conf_reload/prober/. - Verify query parameters (
version,bfe_cluster), response parsing, and extra-file handling.
Follow the six-step methodology in docs/zh_cn/README.md:
- Create
docs/zh_cn/modifications/YYYYMMDD-<summary>/withchange-summary.md(anddesign-changes.mdif needed). - Update
docs/zh_cn/sys-design/anddocs/zh_cn/sys-design/summary.md. - Update
docs/zh_cn/config/config.mdif config semantics change. - Implement code: config → conf_reload sub-package → reloader orchestration.
- Add/update unit tests and integration tests.
- Summarize and decide whether to add a long-lived
docs/zh_cn/sys-design/details/document.
- Follow
docs/zh_cn/README.mdfor non-trivial features; keep design docs and code in sync. - Keep
Reloader.Stop()andAgent.Stop()safe to call multiple times; they usesync.Onceto close the stop channel. - Prefer platform-agnostic file operations; use
xfile/helpers for symlinks/junctions and test on both Windows and Linux when possible. - Unit-test file_store behaviors directly in
conf_reload/file_store/file_store_test.go; integration tests should exercise the fullprober → file_store → triggerflow. - Do not commit generated files such as
conf-agent,coverage.out, ordist/artifacts. - Run tests:
go test ./...after any production change.cd test/integration && go test -v -count=1 ./tests/...after integration-affecting changes.
- License headers: all new source files need the Apache 2.0 / Rainway AI Gateway header. Use
make license-fixif unsure. - Coordinate with
ai-gateway-api/when changes affect InnerAPI contract or config export formats.
README.md/docs/zh_cn/README.md— project overview and system design index.CONTRIBUTING.md— workflow and code style.docs/zh_cn/sys-design/summary.md— system design index.docs/zh_cn/config/config.md— configuration reference.test/integration/tests/cleanup/design.md— integration test scenario design.Makefile— build, test, release, and license targets.