mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/flagutil: re-use Duration.Set() call in NewDuration
This commit is contained in:
parent
b2294d1cf1
commit
20bc2a2c44
3 changed files with 8 additions and 7 deletions
|
@ -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")
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue