lib/flagutil: use month limit for duration flag for parsed duration assessment (#6486)

use maxMonths limit for parsed duration flag value

https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6330

---------

Signed-off-by: hagen1778 <roman@victoriametrics.com>
Co-authored-by: hagen1778 <roman@victoriametrics.com>
This commit is contained in:
Andrii Chubatiuk 2024-06-14 16:20:21 +03:00 committed by GitHub
parent 5223981fed
commit faf67aa8b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 1 deletions

View File

@ -45,6 +45,7 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/).
* BUGFIX: [vmbackup](https://docs.victoriametrics.com/vmbackup/): properly configure authentication with S3 when `-configFilePath` cmd-line flag is specified.
* BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert/) enterprise: properly configure authentication with S3 when `-s3.configFilePath` cmd-line flag is specified for reading rule configs.
* BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert/): properly specify oauth2 `ClientSecret` when configuring authentication for `notifier.url`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6471) for details. Thanks to @yincongcyincong for the [pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6478).
* BUGFIX: [Single-node VictoriaMetrics](https://docs.victoriametrics.com/) and `vmstorage` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): add validation for the max value specified for `-retentionPeriod`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6330) for details.
## [v1.102.0-rc1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.102.0-rc1)

View File

@ -76,11 +76,13 @@ func (d *Duration) Set(value string) error {
if err != nil {
return err
}
if msecs/msecsPer31Days > maxMonths {
return fmt.Errorf("duration must be smaller than %d months; got approx %d months", maxMonths, msecs/msecsPer31Days)
}
d.msecs = msecs
d.valueString = value
return nil
}
const maxMonths = 12 * 100
const msecsPer31Days = 31 * 24 * 3600 * 1000

View File

@ -24,6 +24,7 @@ func TestDurationSetFailure(t *testing.T) {
f("12345")
// Too big duration
f("999y")
f("100000000000y")
// Negative duration
@ -59,6 +60,7 @@ func TestDurationSetSuccess(t *testing.T) {
f("2.3W", 2.3*7*24*3600*1000)
f("1w", 7*24*3600*1000)
f("0.25y", 0.25*365*24*3600*1000)
f("100y", 100*365*24*3600*1000)
}
func TestDurationDuration(t *testing.T) {