fix: update the precision parameter default value (#10814)

This commit is contained in:
Joshua Powers 2022-03-16 07:18:27 -06:00 committed by GitHub
parent 4fcff21c18
commit 8701ed173a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -381,7 +381,7 @@ var agentConfig = `
##
## Precision will NOT be used for service inputs. It is up to each individual
## service input to set the timestamp at the appropriate precision.
precision = ""
precision = "0s"
## Log at debug level.
# debug = false

View File

@ -38,6 +38,10 @@ func (d *Duration) UnmarshalTOML(b []byte) error {
// Finally, try value is a TOML string (e.g. "3s", 3s) or literal (e.g. '3s')
durStr = strings.ReplaceAll(durStr, "'", "")
durStr = strings.ReplaceAll(durStr, "\"", "")
if durStr == "" {
durStr = "0s"
}
dur, err := time.ParseDuration(durStr)
if err != nil {
return err

View File

@ -52,6 +52,14 @@ func TestDuration(t *testing.T) {
require.NoError(t, d.UnmarshalTOML([]byte(`1.5`)))
require.Equal(t, time.Second, time.Duration(d))
d = config.Duration(0)
require.NoError(t, d.UnmarshalTOML([]byte(``)))
require.Equal(t, 0*time.Second, time.Duration(d))
d = config.Duration(0)
require.NoError(t, d.UnmarshalTOML([]byte(`""`)))
require.Equal(t, 0*time.Second, time.Duration(d))
require.Error(t, d.UnmarshalTOML([]byte(`"1"`))) // string missing unit
require.Error(t, d.UnmarshalTOML([]byte(`'2'`))) // string missing unit
require.Error(t, d.UnmarshalTOML([]byte(`'ns'`))) // string missing time