2.9 KiB
2.9 KiB
Quickstart: Modular Proxy & Cache Segmentation
1. Prepare Workspace
- Ensure Go 1.25+ toolchain is installed (
go version). - From repo root, run
go mod tidy(ormake depsif defined) to sync modules. - Export
ANY_HUB_CONFIGpointing to your working config (optional).
2. Create/Update Hub Module
- Copy
internal/hubmodule/template/tointernal/hubmodule/<module-key>/and rename the package/types. - In the new package's
init(), callhubmodule.MustRegister(hubmodule.ModuleMetadata{Key: "<module-key>", ...})to describe supported protocols、缓存策略与迁移阶段。 - Register runtime behavior (proxy handler) from your module by calling
proxy.RegisterModuleHandler("<module-key>", handler)during initialization. - Add tests under the module directory and run
make modules-test(delegates togo test ./internal/hubmodule/...).
3. Bind Module via Config
- Edit
config.tomland setModule = "<module-key>"inside the target[[Hub]]block (omit to uselegacy). - While validating a new module, set
Rollout = "dual"so you can flip back to legacy without editing other fields. - (Optional) Override cache behavior per hub using existing fields (
CacheTTL, etc.). - Run
ANY_HUB_CONFIG=./config.toml go test ./...(ormake modules-test) to ensure loader validation passes and the module registry sees your key.
4. Run and Verify
- Start the binary:
go run ./cmd/any-hub --config ./config.toml. - Use
curl -H "Host: <hub-domain>" http://127.0.0.1:<port>/<path>to produce traffic, then hitcurl http://127.0.0.1:<port>/-/modulesand confirm the hub binding points to your module with the expectedrollout_flag. - Inspect
./storage/<hub>/to confirm the cached files mirror the upstream path (no suffix). When a path also has child entries (e.g.,/pkgmetadata plus/pkg/-/...tarballs), the metadata payload is stored in a__contentfile under that directory so both artifacts can coexist. Verify TTL overrides are propagated. - Monitor
logs/any-hub.log(or the samplelogs/module_migration_sample.log) to verify each entry exposesmodule_key+rollout_flag. Example:{"action":"proxy","hub":"testhub","module_key":"testhub","rollout_flag":"dual","cache_hit":false,"upstream_status":200} - Exercise rollback by switching
Rollout = "legacy-only"(orModule = "legacy"if needed) and re-running the traffic to ensure diagnostics/logs show the transition.
5. Ship
- Commit module code + config docs.
- Update release notes mentioning the module key, migration guidance, and related diagnostics.
- Monitor cache hit/miss metrics post-deploy; adjust TTL overrides if necessary.
6. Attach Validation Artifacts
- Save the JSON snapshot from
/-/modulesand a short log excerpt (seelogs/module_migration_sample.log) with both legacy + modular hubs present; attach them to the change request so reviewers can confirm you followed the playbook.