diff --git a/cmd/options.go b/cmd/options.go index 4414e7e1de1..2a7e5450bc5 100644 --- a/cmd/options.go +++ b/cmd/options.go @@ -91,7 +91,10 @@ func optionFlagSet() *pflag.FlagSet { flags.StringSlice("tag", nil, "add a `tag` to be applied to all samples, as `[name]=[value]`") flags.String("console-output", "", "redirects the console logging to the provided output file") flags.Bool("discard-response-bodies", false, "Read but don't process or save HTTP response bodies") - flags.String("dns", "ttl=inf,strategy=first", "DNS configuration") + flags.String("dns", "ttl=inf,strategy=first", "DNS configuration. Possible ttl values are: 'inf' "+ + "for a persistent cache, '0' to disable the cache,\nor a positive duration, e.g. '1s', '1m', etc. "+ + "Milliseconds are assumed if no unit is provided.\n"+ + "Possible values for the strategy to use to select a single IP are: 'first', 'random' or 'round-robin'.\n") return flags } diff --git a/core/local/local_test.go b/core/local/local_test.go index 3211ef4bcae..6f151a0ce38 100644 --- a/core/local/local_test.go +++ b/core/local/local_test.go @@ -1009,6 +1009,12 @@ func TestDNSResolver(t *testing.T) { Strategy: lib.DefaultDNSConfig().Strategy, }}, }, + "1000ms": { // cache IPs for 1s, test that unitless values are interpreted as ms + lib.Options{DNS: &lib.DNSConfig{ + TTL: null.StringFrom("1000"), + Strategy: lib.DefaultDNSConfig().Strategy, + }}, + }, "2s": { lib.Options{DNS: &lib.DNSConfig{ TTL: null.StringFrom("2s"), @@ -1064,6 +1070,9 @@ func TestDNSResolver(t *testing.T) { case "0": require.Len(t, entries, 5) checkLog(t, entries) + case "1000ms": + require.Len(t, entries, 3) + checkLog(t, entries) case "2s": require.Len(t, entries, 2) checkLog(t, entries) diff --git a/js/runner.go b/js/runner.go index a0115879901..bf090e84bce 100644 --- a/js/runner.go +++ b/js/runner.go @@ -353,9 +353,9 @@ func parseTTL(ttlS string) (types.NullDuration, error) { // disable cache default: origTTLs := ttlS - // Treat unitless values as seconds + // Treat unitless values as milliseconds if t, err := strconv.ParseFloat(ttlS, 32); err == nil { - ttlS = fmt.Sprintf("%.2fs", t) + ttlS = fmt.Sprintf("%.2fms", t) } ttlD, err := types.ParseExtendedDuration(ttlS) if ttlD < 0 || err != nil {