diff --git a/app/vmstorage/main.go b/app/vmstorage/main.go index 14eefb5e4..f3be38ff9 100644 --- a/app/vmstorage/main.go +++ b/app/vmstorage/main.go @@ -75,7 +75,7 @@ func CheckTimeRange(tr storage.TimeRange) error { if !*denyQueriesOutsideRetention { return nil } - minAllowedTimestamp := int64(fasttime.UnixTimestamp()*1000) - retentionPeriod.Duration().Milliseconds() + minAllowedTimestamp := int64(fasttime.UnixTimestamp()*1000) - retentionPeriod.Milliseconds() if tr.MinTimestamp > minAllowedTimestamp { return nil } diff --git a/lib/flagutil/duration.go b/lib/flagutil/duration.go index 4b565bbaa..e33d1fc13 100644 --- a/lib/flagutil/duration.go +++ b/lib/flagutil/duration.go @@ -31,11 +31,16 @@ type Duration struct { valueString string } -// Duration convert to time.Duration. +// Duration returns d as time.Duration func (d *Duration) Duration() time.Duration { return time.Millisecond * time.Duration(d.msecs) } +// Milliseconds returns d in milliseconds +func (d *Duration) Milliseconds() int64 { + return d.msecs +} + // String implements flag.Value interface func (d *Duration) String() string { return d.valueString diff --git a/lib/flagutil/duration_test.go b/lib/flagutil/duration_test.go index bb138605f..f9834c679 100644 --- a/lib/flagutil/duration_test.go +++ b/lib/flagutil/duration_test.go @@ -42,8 +42,8 @@ func TestDurationSetSuccess(t *testing.T) { if err := d.Set(value); err != nil { t.Fatalf("unexpected error in d.Set(%q): %s", value, err) } - if d.msecs != expectedMsecs { - t.Fatalf("unexpected result; got %d; want %d", d.msecs, expectedMsecs) + if d.Milliseconds() != expectedMsecs { + t.Fatalf("unexpected result; got %d; want %d", d.Milliseconds(), expectedMsecs) } valueString := d.String() valueExpected := strings.ToLower(value)