Skip to content

Commit

Permalink
fix: update the precision parameter default value
Browse files Browse the repository at this point in the history
In influxdata#10803, precision parsing was made more strict so that incorrect
values would be caught. The default precision value however is not
correct as an empty string, but will still accept the emptry string.

fixes: influxdata#10813
  • Loading branch information
powersj committed Mar 14, 2022
1 parent 4fcff21 commit 9fa8210
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions config/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9fa8210

Please sign in to comment.