feat: cache distributed config fetches - #149
Open
tionis wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces central configuration distribution load by adding standard HTTP caching semantics (freshness + conditional revalidation) for HTTP-based repos, and by making the distribution polling cadence configurable via dist.poll_interval (default remains 10s).
Changes:
- Add
dist.poll_intervalto central config, validate it, and document it (docs + sample config). - Introduce a persistent
configFetcherthat reuses HTTP connections and implements ETag / Last-Modified conditional requests plus Cache-Control/Expires freshness handling. - Switch the config distribution scheduler to a dynamic repeat loop so the poll interval can update after live config reloads; add unit tests for caching and YAML duration parsing.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
state/validation.go |
Validates dist.poll_interval is present and positive when configured. |
state/config.go |
Adds PollInterval *time.Duration to DistributionCfg with YAML mapping. |
state/config_distribution_test.go |
Tests YAML unmarshalling of poll_interval and validator enforcement. |
example/sample-central.yaml |
Documents and demonstrates poll_interval usage in sample config. |
docs/reference/config.mdx |
Updates config reference docs to include poll_interval and HTTP caching behavior. |
docs/guides/config-distribution.mdx |
Expands distribution guide with poll_interval and caching details. |
core/nylon.go |
Adds configFetcher + configPollDelay fields, initializes fetcher, and wires cleanup. |
core/nylon_scheduler.go |
Adds RepeatTaskDynamic to support runtime-adjustable polling intervals. |
core/nylon_distribution.go |
Implements caching-aware HTTP fetching and integrates it into periodic config polling. |
core/nylon_distribution_test.go |
Adds tests for ETag/Last-Modified behavior, freshness handling, and poll delay updates. |
core/nylon_apply.go |
Updates poll delay when a new central config is successfully applied. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
I noticed that Nylon currently doesn’t use HTTP caching when fetching distributed configuration, and its polling interval isn’t configurable. This can put more load on the central HTTP server than necessary. (And cost me a few cent more in bandwidth from my CDN provider).
This PR adds standard HTTP caching—including ETag and Last-Modified revalidation—and makes the config fetch interval configurable through dist.poll_interval. Existing behavior remains unchanged by default, with polling every 10 seconds.