diff --git a/app/vmstorage/main.go b/app/vmstorage/main.go index e722d6010..4d1ce91b4 100644 --- a/app/vmstorage/main.go +++ b/app/vmstorage/main.go @@ -22,7 +22,7 @@ import ( ) var ( - retentionPeriod = flagutil.NewDuration("retentionPeriod", 1, "Data with timestamps outside the retentionPeriod is automatically deleted") + retentionPeriod = flagutil.NewDuration("retentionPeriod", "1", "Data with timestamps outside the retentionPeriod is automatically deleted") snapshotAuthKey = flag.String("snapshotAuthKey", "", "authKey, which must be passed in query string to /snapshot* pages") forceMergeAuthKey = flag.String("forceMergeAuthKey", "", "authKey, which must be passed in query string to /internal/force_merge pages") forceFlushAuthKey = flag.String("forceFlushAuthKey", "", "authKey, which must be passed in query string to /internal/force_flush pages") diff --git a/lib/flagutil/duration.go b/lib/flagutil/duration.go index 8dd920f67..87d602c6e 100644 --- a/lib/flagutil/duration.go +++ b/lib/flagutil/duration.go @@ -12,14 +12,14 @@ import ( // NewDuration returns new `duration` flag with the given name, defaultValue and description. // // DefaultValue is in months. -func NewDuration(name string, defaultValue float64, description string) *Duration { +func NewDuration(name string, defaultValue string, description string) *Duration { description += "\nThe following optional suffixes are supported: h (hour), d (day), w (week), y (year). If suffix isn't set, then the duration is counted in months" - d := Duration{ - Msecs: int64(defaultValue * msecsPerMonth), - valueString: fmt.Sprintf("%g", defaultValue), + d := &Duration{} + if err := d.Set(defaultValue); err != nil { + panic(fmt.Sprintf("BUG: can not parse default value %s for flag %s", defaultValue, name)) } - flag.Var(&d, name, description) - return &d + flag.Var(d, name, description) + return d } // Duration is a flag for holding duration. diff --git a/lib/flagutil/duration_test.go b/lib/flagutil/duration_test.go index 2c35951b3..bd26d47b8 100644 --- a/lib/flagutil/duration_test.go +++ b/lib/flagutil/duration_test.go @@ -56,5 +56,6 @@ func TestDurationSetSuccess(t *testing.T) { f("1h", 3600*1000) f("1.5d", 1.5*24*3600*1000) f("2.3W", 2.3*7*24*3600*1000) + f("1w", 7*24*3600*1000) f("0.25y", 0.25*365*24*3600*1000) }