vmalert: added disableProgressBar flag which disable progressbar (#2506)

vmalert: added disableProgressBar flag which disable progressbar

https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1761
This commit is contained in:
Dmytro Kozlov 2022-05-02 11:08:24 +03:00 committed by GitHub
parent 37cf509c3a
commit 32a6b67e6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -481,6 +481,9 @@ per rule before giving up.
(rules which depend on each other) rules. It is expected, that remote storage will be able to persist (rules which depend on each other) rules. It is expected, that remote storage will be able to persist
previously accepted data during the delay, so data will be available for the subsequent queries. previously accepted data during the delay, so data will be available for the subsequent queries.
Keep it equal or bigger than `-remoteWrite.flushInterval`. Keep it equal or bigger than `-remoteWrite.flushInterval`.
* `replay.disableProgressBar` - whether to disable progress bar which shows progress work.
Progress bar may generate a lot of log records, which is not formatted as standard VictoriaMetrics logger.
It could break logs parsing by external system and generate additional load on it.
See full description for these flags in `./vmalert --help`. See full description for these flags in `./vmalert --help`.

View file

@ -29,6 +29,8 @@ var (
"Max number of data points expected in one request. The higher the value, the less requests will be made during replay.") "Max number of data points expected in one request. The higher the value, the less requests will be made during replay.")
replayRuleRetryAttempts = flag.Int("replay.ruleRetryAttempts", 5, replayRuleRetryAttempts = flag.Int("replay.ruleRetryAttempts", 5,
"Defines how many retries to make before giving up on rule if request for it returns an error.") "Defines how many retries to make before giving up on rule if request for it returns an error.")
disableProgressBar = flag.Bool("replay.disableProgressBar", false, "Whether to disable rendering progress bars during the replay. "+
"Progress bar rendering might be verbose or break the logs parsing, so it is recommended to be disabled when not used in interactive mode.")
) )
func replay(groupsCfg []config.Group, qb datasource.QuerierBuilder, rw *remotewrite.Client) error { func replay(groupsCfg []config.Group, qb datasource.QuerierBuilder, rw *remotewrite.Client) error {
@ -88,7 +90,10 @@ func (g *Group) replay(start, end time.Time, rw *remotewrite.Client) int {
g.Name, g.Interval, iterations, step) g.Name, g.Interval, iterations, step)
for _, rule := range g.Rules { for _, rule := range g.Rules {
fmt.Printf("> Rule %q (ID: %d)\n", rule, rule.ID()) fmt.Printf("> Rule %q (ID: %d)\n", rule, rule.ID())
bar := pb.StartNew(iterations) var bar *pb.ProgressBar
if !*disableProgressBar {
bar = pb.StartNew(iterations)
}
ri.reset() ri.reset()
for ri.next() { for ri.next() {
n, err := replayRule(rule, ri.s, ri.e, rw) n, err := replayRule(rule, ri.s, ri.e, rw)
@ -96,9 +101,13 @@ func (g *Group) replay(start, end time.Time, rw *remotewrite.Client) int {
logger.Fatalf("rule %q: %s", rule, err) logger.Fatalf("rule %q: %s", rule, err)
} }
total += n total += n
bar.Increment() if bar != nil {
bar.Increment()
}
}
if bar != nil {
bar.Finish()
} }
bar.Finish()
// sleep to let remote storage to flush data on-disk // sleep to let remote storage to flush data on-disk
// so chained rules could be calculated correctly // so chained rules could be calculated correctly
time.Sleep(*replayRulesDelay) time.Sleep(*replayRulesDelay)