Skip to content

Expose log fields, upstream timeouts, cache inactive, and cache lock as options - #3

Merged
colemickens merged 3 commits into
DeterminateSystems:mainfrom
achen318:ac/expose-nginx-options
Jul 29, 2026
Merged

Expose log fields, upstream timeouts, cache inactive, and cache lock as options#3
colemickens merged 3 commits into
DeterminateSystems:mainfrom
achen318:ac/expose-nginx-options

Conversation

@achen318

@achen318 achen318 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This updates the edge cache to resolve cache.flakehub.com for each request instead of retaining the address chosen when nginx starts. Both proxy paths preserve the expected Host and SNI name, verify TLS, and expose diagnostics for failed DNS lookups and upstream connection attempts.

It also exposes nginx behaviors that previously required replacing the module's generated configuration:

  • dnsResolverIPv6: enable or disable IPv6 DNS answers.
  • sslVerify, sslTrustedCertificate, and sslVerifyDepth: configure upstream certificate verification.
  • extraLogFields: append custom access-log fields. The default format now includes cache status, upstream bytes and request time, plus upstream status, address, and connect time.
  • upstreamResolveTimeout: bound DNS resolution and upstream connection attempts for both the narinfo and NAR passthroughs.
  • upstreamReadTimeout: bound the narinfo passthrough read/send time (narinfo-only, so slow but progressing NAR transfers are never aborted).
  • cacheInactive: configure inactive cache-entry eviction independently from freshness.
  • cacheLock, cacheLockTimeout, and cacheLockAge: collapse concurrent fetches for the same uncached NAR.

The cache, timeout, and lock options remain opt-in. Request-time DNS resolution, upstream TLS verification, the observability log fields, and journal-based error logging are enabled by default.

Validation

  • nixfmt --check passed for all Nix files.
  • nix flake check --no-build passed on x86_64 Linux.
  • The rendered nginx configuration passed nginx -t.

…d cache lock as options

Surfaces nginx behaviors that previously required forking the hardcoded
config, all behind options that default to a no-op so existing consumers
see no change on upgrade:

- extraLogFields: append fields (e.g. $upstream_cache_status) to log_format
- upstreamConnectTimeout/upstreamReadTimeout + narinfoMissOnError: bound the
  narinfo passthrough and remap upstream failures to 404 so Nix sees a clean
  miss and falls through instead of failing the build on a 5xx/timeout
- cacheInactive: set proxy_cache_path inactive= (defaults to null, i.e.
  nginx's 10m default; set to cacheLifetime for a bursty pull-through cache)
- cacheLock + cacheLockTimeout/cacheLockAge: enable proxy_cache_lock to
  collapse concurrent fetches of the same uncached NAR

Documents each option in the README and exercises them in the test VM.
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds FlakeHub Edge Cache options for DNS resolution, access-log fields, cache inactivity, upstream timeouts, and cache locking. It wires these options into generated nginx configuration, updates VM settings, and documents them in the README.

Changes

FlakeHub Edge Cache controls

Layer / File(s) Summary
Module options and nginx wiring
modules/default.nix
New options configure DNS resolution, logging, TLS verification, upstream timeouts, cache inactivity, and cache locking in generated nginx configuration.
VM configuration coverage
test/vm.nix
The VM configuration sets representative DNS, timeout, cache inactivity, and cache-lock values.
README option docs
README.md
The README documents the new DNS, logging, TLS, timeout, cache, and cache-lock options.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NginxResolver
  participant NginxCache
  participant Upstream
  NginxResolver->>Upstream: Resolve the cache address with IPv4/IPv6 and timeout settings
  NginxCache->>Upstream: Fetch nar or narinfo with configured TLS and timeouts
  NginxCache->>NginxCache: Coalesce cache misses using cache-lock settings
  NginxCache->>NginxCache: Record cache and upstream fields in access logs
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title captures the main new module options added by the PR, including log fields, upstream timeouts, cache inactivity, and cache locking.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Resolve FlakeHub Cache per request while preserving the expected TLS name, verifying its certificate, and bounding DNS lookup time. Add configurable resolver, TLS, and error-log settings together with upstream diagnostics for failed and retried requests.
colemickens
colemickens previously approved these changes Jul 28, 2026
Comment thread modules/default.nix Outdated
Comment thread modules/default.nix Outdated
Comment thread modules/default.nix Outdated
Comment thread modules/default.nix Outdated
@colemickens

Copy link
Copy Markdown
Member

@achen318 thanks for this! There's some great stuff in here, I'm sorry we didn't look at this sooner.

I left a few comments. A couple of which I could do in a follow-up commit, if you'd prefer. I am curious for your thoughts on the code->404 conversion that I commented on though.

Comment thread modules/default.nix
@achen318

Copy link
Copy Markdown
Contributor Author

No worries, thanks for reviewing! I can add some improvements to this PR for you to take a look.

…rop 404 remap

- Rename upstreamConnectTimeout to upstreamResolveTimeout; it drives both
  resolver_timeout and proxy_connect_timeout.
- Default extraLogFields to the cache observability fields
  ($upstream_cache_status, $upstream_bytes_received, $request_time)
  instead of requiring consumers to opt in; the option remains for
  customization.
- Drop the errorLog option and log errors to stderr so they land in the
  service manager's journal.
- Apply the connect timeout to the /nar passthrough as well; read/send
  timeouts stay narinfo-only since they bound the gap between reads and
  could abort slow but progressing NAR transfers.
- Remove narinfoMissOnError: on Nix >= 2.32 (NixOS/nix#13301) graceful
  substituter fallback makes the 5xx-to-404 remap unnecessary for
  correctness, and truthful errors avoid both negative narinfo cache
  poisoning on clients and the observability gap of synthetic misses.
@achen318 achen318 changed the title Expose log fields, narinfo timeout/error handling, cache inactive, and cache lock as options Expose log fields, upstream timeouts, cache inactive, and cache lock as options Jul 29, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
modules/default.nix (1)

219-221: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Document cache-lock bypass behavior consistently.

Nginx can release waiters after cacheLockTimeout, and cacheLockAge can permit another origin request. Both descriptions should state that requests normally wait, subject to these limits. (nginx.org)

  • modules/default.nix#L219-L221: qualify “only the first populates the cache and the rest wait.”
  • README.md#L167-L173: mirror the same qualification in the public documentation.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/default.nix` around lines 219 - 221, Qualify the proxy_cache_lock
descriptions in modules/default.nix lines 219-221 and README.md lines 167-173 so
they state that concurrent requests normally wait for the first cache fill, but
may bypass waiting when cacheLockTimeout expires or cacheLockAge permits another
origin request; keep the behavior description consistent in both locations.

Source: MCP tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@modules/default.nix`:
- Around line 219-221: Qualify the proxy_cache_lock descriptions in
modules/default.nix lines 219-221 and README.md lines 167-173 so they state that
concurrent requests normally wait for the first cache fill, but may bypass
waiting when cacheLockTimeout expires or cacheLockAge permits another origin
request; keep the behavior description consistent in both locations.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d248e707-3bc5-47f4-8ca2-771847137a79

📥 Commits

Reviewing files that changed from the base of the PR and between 9c93b05 and cad28e5.

📒 Files selected for processing (3)
  • README.md
  • modules/default.nix
  • test/vm.nix

@achen318
achen318 requested a review from colemickens July 29, 2026 20:49
@colemickens

Copy link
Copy Markdown
Member

Thanks @achen318 !

@colemickens
colemickens enabled auto-merge July 29, 2026 22:26
@colemickens
colemickens merged commit 92c0e99 into DeterminateSystems:main Jul 29, 2026
7 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 29, 2026
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