Make GeoIP cache and iptables timeout configurable - #56
Merged
Conversation
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.
Closes #25
All three knobs are configurable, by flag and by config file, with flags winning. Defaults are unchanged — the goal is configurability, and a test pins each default so that stays true.
One correction to the issue
iptablesTimeoutis avar.geoCacheTTLandgeoCacheMaxSizeareconst(pkg/enrich/geoip.go:18-20), so setters alone would not have compiled. They are nowvar, which is safe: every use is a comparison (geoip.go:436,:446,:449,:466) — no array size, no other const expression.What was added
Plus
GeoCacheTTL(),GeoCacheMaxSize()andIPTablesTimeout()readers, so a caller can show what is in effect rather than re-deriving the default — and so the tests assert through the public surface.Each setter's doc comment says call once at startup, and why: the values are read without synchronisation, so changing them mid-run is a data race.
Flags and precedence
--geo-cache-ttl24h--geo-cache-size50000--iptables-timeoutguardonly10sResolution lives in
applyTuning, called from aPersistentPreRunEonrootCmdso it runs once before any command. Precedence is flag > config file > default, implemented by writing the config layer first and the flag layer second — neither layer needs to know about the other."Was the flag set?" is asked of cobra via
f.Changed(...), not inferred by comparing against the default. Passing--geo-cache-ttl 24hexplicitly is a deliberate choice and should count as one.Validation, and one place I diverged
The setters ignore out-of-range values (defensive, for a library caller). The CLI rejects them:
Silently ignoring a bad flag would hide a typo that looks like it took effect — the opposite of the "hard to diagnose" failures this issue is about. A malformed value in the config file is rejected the same way, naming the key.
Verified through the built binary
The
--helptext carries the "0 disables caching, which is much slower" warning the issue asks for.Tests — 14
Per setter (valid values, the disabling zero, the ignored negative), plus
applyTuning: config-only, flags beating config, nothing-set leaving every default untouched, and seven rejection cases across both layers.Docs
docs/subcommands.htmlgains all three flags with defaults and the config-key mapping;tools/minify.shregeneratedsearch-index.jsonasAGENTS.mdrequires. I reverted the seven unrelated HTML files it also touched — those diffs were only adoc:modifiedtimestamp shifted by my machine's timezone, and they would have buried the real change.Verification