httpcaddyfile: accept duration strings for log sampling interval (#7694)

Co-authored-by: tomholford <tomholford@users.noreply.github.com>
This commit is contained in:
tomholford 2026-05-07 11:32:20 -07:00 committed by GitHub
parent d2172bea61
commit 0780d4489c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 7 additions and 7 deletions

View file

@ -1053,7 +1053,7 @@ func parseLogHelper(h Helper, globalLogNames map[string]struct{}) ([]ConfigValue
if !d.NextArg() {
return nil, d.ArgErr()
}
interval, err := time.ParseDuration(d.Val() + "ns")
interval, err := caddy.ParseDuration(d.Val())
if err != nil {
return nil, d.Errf("failed to parse interval: %v", err)
}

View file

@ -66,14 +66,14 @@ func TestLogDirectiveSyntax(t *testing.T) {
input: `:8080 {
log {
sampling {
interval 2
interval 2s
first 3
thereafter 4
}
}
}
`,
output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"sampling":{"interval":2,"first":3,"thereafter":4},"include":["http.log.access.log0"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"log0"}}}}}}`,
output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"sampling":{"interval":2000000000,"first":3,"thereafter":4},"include":["http.log.access.log0"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"log0"}}}}}}`,
expectError: false,
},
} {

View file

@ -1,7 +1,7 @@
{
log {
sampling {
interval 300
interval 5m
first 50
thereafter 40
}
@ -13,7 +13,7 @@
"logs": {
"default": {
"sampling": {
"interval": 300,
"interval": 300000000000,
"first": 50,
"thereafter": 40
}

View file

@ -1,7 +1,7 @@
:80 {
log {
sampling {
interval 300
interval 5m
first 50
thereafter 40
}
@ -18,7 +18,7 @@
},
"log0": {
"sampling": {
"interval": 300,
"interval": 300000000000,
"first": 50,
"thereafter": 40
},