2021-01-31 23:10:16 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm"
|
|
|
|
)
|
|
|
|
|
2022-05-02 07:06:34 +00:00
|
|
|
const barTpl = `{{ blue "%s:" }} {{ counters . }} {{ bar . "[" "█" (cycle . "█") "▒" "]" }} {{ percent . }}`
|
|
|
|
|
2021-01-31 23:10:16 +00:00
|
|
|
func prompt(question string) bool {
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
fmt.Print(question, " [Y/n] ")
|
|
|
|
answer, err := reader.ReadString('\n')
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
answer = strings.TrimSpace(strings.ToLower(answer))
|
|
|
|
if answer == "" || answer == "yes" || answer == "y" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-01-03 19:12:01 +00:00
|
|
|
func wrapErr(vmErr *vm.ImportError, verbose bool) error {
|
2021-01-31 23:10:16 +00:00
|
|
|
var errTS string
|
2022-01-03 19:12:01 +00:00
|
|
|
var maxTS, minTS int64
|
2021-01-31 23:10:16 +00:00
|
|
|
for _, ts := range vmErr.Batch {
|
2022-01-03 19:12:01 +00:00
|
|
|
if minTS < ts.Timestamps[0] || minTS == 0 {
|
|
|
|
minTS = ts.Timestamps[0]
|
|
|
|
}
|
|
|
|
if maxTS < ts.Timestamps[len(ts.Timestamps)-1] {
|
|
|
|
maxTS = ts.Timestamps[len(ts.Timestamps)-1]
|
|
|
|
}
|
|
|
|
if verbose {
|
|
|
|
errTS += fmt.Sprintf("%s for timestamps range %d - %d\n",
|
|
|
|
ts.String(), ts.Timestamps[0], ts.Timestamps[len(ts.Timestamps)-1])
|
|
|
|
}
|
2021-01-31 23:10:16 +00:00
|
|
|
}
|
2022-01-03 19:12:01 +00:00
|
|
|
var verboseMsg string
|
|
|
|
if !verbose {
|
|
|
|
verboseMsg = "(enable `--verbose` output to get more details)"
|
|
|
|
}
|
|
|
|
if vmErr.Err == nil {
|
|
|
|
return fmt.Errorf("%s\n\tLatest delivered batch for timestamps range %d - %d %s\n%s",
|
|
|
|
vmErr.Err, minTS, maxTS, verboseMsg, errTS)
|
|
|
|
}
|
|
|
|
return fmt.Errorf("%s\n\tImporting batch failed for timestamps range %d - %d %s\n%s",
|
|
|
|
vmErr.Err, minTS, maxTS, verboseMsg, errTS)
|
2021-01-31 23:10:16 +00:00
|
|
|
}
|