mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 15:16:42 +00:00
lib/flagutil: re-use Duration.Set() call in NewDuration
This commit is contained in:
parent
25e54d2b50
commit
a436836402
3 changed files with 8 additions and 7 deletions
|
@ -24,7 +24,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")
|
||||
httpListenAddr = flag.String("httpListenAddr", ":8482", "Address to listen for http connections")
|
||||
storageDataPath = flag.String("storageDataPath", "vmstorage-data", "Path to storage data")
|
||||
vminsertAddr = flag.String("vminsertAddr", ":8400", "TCP address to accept connections from vminsert services")
|
||||
|
|
|
@ -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