2021-02-01 00:10:16 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-05-03 07:03:41 +02:00
|
|
|
"context"
|
2021-02-01 00:10:16 +01:00
|
|
|
"fmt"
|
|
|
|
"log"
|
2023-04-14 08:34:54 +02:00
|
|
|
"net/http"
|
2021-02-01 00:10:16 +01:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"strings"
|
2022-04-05 16:01:32 +02:00
|
|
|
"sync/atomic"
|
2021-02-01 00:10:16 +01:00
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
|
2023-12-12 13:05:44 +01:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
2023-03-09 14:53:29 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/auth"
|
2023-03-02 13:19:45 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/backoff"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/native"
|
2022-11-29 22:53:28 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/remoteread"
|
2022-09-06 09:09:34 +02:00
|
|
|
|
2021-02-01 00:10:16 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/influx"
|
2021-04-08 21:58:06 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/opentsdb"
|
2021-02-01 00:10:16 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/prometheus"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo"
|
2024-02-16 14:59:18 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httputils"
|
2022-04-05 16:01:32 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/common"
|
2023-02-13 19:42:58 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/native/stream"
|
2021-02-01 00:10:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-01-03 20:12:01 +01:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
importer *vm.Importer
|
|
|
|
)
|
|
|
|
|
2022-05-03 07:03:41 +02:00
|
|
|
ctx, cancelCtx := context.WithCancel(context.Background())
|
2021-02-01 00:10:16 +01:00
|
|
|
start := time.Now()
|
|
|
|
app := &cli.App{
|
|
|
|
Name: "vmctl",
|
2021-04-20 10:42:17 +02:00
|
|
|
Usage: "VictoriaMetrics command-line tool",
|
2021-02-01 00:10:16 +01:00
|
|
|
Version: buildinfo.Version,
|
|
|
|
Commands: []*cli.Command{
|
2021-04-08 21:58:06 +02:00
|
|
|
{
|
|
|
|
Name: "opentsdb",
|
2022-11-29 22:53:28 +01:00
|
|
|
Usage: "Migrate time series from OpenTSDB",
|
2021-04-08 21:58:06 +02:00
|
|
|
Flags: mergeFlags(globalFlags, otsdbFlags, vmFlags),
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
fmt.Println("OpenTSDB import mode")
|
|
|
|
|
2024-02-20 16:22:58 +01:00
|
|
|
// create Transport with given TLS config
|
|
|
|
certFile := c.String(otsdbCertFile)
|
|
|
|
keyFile := c.String(otsdbKeyFile)
|
|
|
|
caFile := c.String(otsdbCAFile)
|
|
|
|
serverName := c.String(otsdbServerName)
|
|
|
|
insecureSkipVerify := c.Bool(otsdbInsecureSkipVerify)
|
|
|
|
addr := c.String(otsdbAddr)
|
|
|
|
|
2024-03-14 11:45:39 +01:00
|
|
|
tr, err := httputils.Transport(addr, certFile, keyFile, caFile, serverName, insecureSkipVerify)
|
2024-02-20 16:22:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create Transport: %s", err)
|
|
|
|
}
|
2021-04-08 21:58:06 +02:00
|
|
|
oCfg := opentsdb.Config{
|
2024-02-20 16:22:58 +01:00
|
|
|
Addr: addr,
|
2021-04-08 21:58:06 +02:00
|
|
|
Limit: c.Int(otsdbQueryLimit),
|
|
|
|
Offset: c.Int64(otsdbOffsetDays),
|
|
|
|
HardTS: c.Int64(otsdbHardTSStart),
|
|
|
|
Retentions: c.StringSlice(otsdbRetentions),
|
|
|
|
Filters: c.StringSlice(otsdbFilters),
|
|
|
|
Normalize: c.Bool(otsdbNormalize),
|
|
|
|
MsecsTime: c.Bool(otsdbMsecsTime),
|
2024-02-20 16:22:58 +01:00
|
|
|
Transport: tr,
|
2021-04-08 21:58:06 +02:00
|
|
|
}
|
|
|
|
otsdbClient, err := opentsdb.NewClient(oCfg)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create opentsdb client: %s", err)
|
|
|
|
}
|
|
|
|
|
2024-03-08 20:47:36 +01:00
|
|
|
vmCfg, err := initConfigVM(c)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to init VM configuration: %s", err)
|
|
|
|
}
|
2022-05-02 09:06:34 +02:00
|
|
|
// disable progress bars since openTSDB implementation
|
|
|
|
// does not use progress bar pool
|
|
|
|
vmCfg.DisableProgressBar = true
|
2023-02-22 13:06:55 +01:00
|
|
|
importer, err := vm.NewImporter(ctx, vmCfg)
|
2021-04-08 21:58:06 +02:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create VM importer: %s", err)
|
|
|
|
}
|
|
|
|
|
2023-06-02 14:57:08 +02:00
|
|
|
otsdbProcessor := newOtsdbProcessor(otsdbClient, importer, c.Int(otsdbConcurrency), c.Bool(globalSilent), c.Bool(globalVerbose))
|
|
|
|
return otsdbProcessor.run()
|
2021-04-08 21:58:06 +02:00
|
|
|
},
|
|
|
|
},
|
2021-02-01 00:10:16 +01:00
|
|
|
{
|
|
|
|
Name: "influx",
|
2022-11-29 22:53:28 +01:00
|
|
|
Usage: "Migrate time series from InfluxDB",
|
2021-02-01 00:10:16 +01:00
|
|
|
Flags: mergeFlags(globalFlags, influxFlags, vmFlags),
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
fmt.Println("InfluxDB import mode")
|
|
|
|
|
2024-02-16 14:59:18 +01:00
|
|
|
// create TLS config
|
2024-02-16 15:08:51 +01:00
|
|
|
certFile := c.String(influxCertFile)
|
|
|
|
keyFile := c.String(influxKeyFile)
|
|
|
|
caFile := c.String(influxCAFile)
|
|
|
|
serverName := c.String(influxServerName)
|
|
|
|
insecureSkipVerify := c.Bool(influxInsecureSkipVerify)
|
2024-02-16 14:59:18 +01:00
|
|
|
|
2024-03-14 11:45:39 +01:00
|
|
|
tc, err := httputils.TLSConfig(certFile, keyFile, caFile, serverName, insecureSkipVerify)
|
2024-02-16 14:59:18 +01:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create TLS Config: %s", err)
|
|
|
|
}
|
|
|
|
|
2021-02-01 00:10:16 +01:00
|
|
|
iCfg := influx.Config{
|
|
|
|
Addr: c.String(influxAddr),
|
|
|
|
Username: c.String(influxUser),
|
|
|
|
Password: c.String(influxPassword),
|
|
|
|
Database: c.String(influxDB),
|
|
|
|
Retention: c.String(influxRetention),
|
|
|
|
Filter: influx.Filter{
|
|
|
|
Series: c.String(influxFilterSeries),
|
|
|
|
TimeStart: c.String(influxFilterTimeStart),
|
|
|
|
TimeEnd: c.String(influxFilterTimeEnd),
|
|
|
|
},
|
|
|
|
ChunkSize: c.Int(influxChunkSize),
|
2024-02-16 14:59:18 +01:00
|
|
|
TLSConfig: tc,
|
2021-02-01 00:10:16 +01:00
|
|
|
}
|
2024-02-16 14:59:18 +01:00
|
|
|
|
2021-02-01 00:10:16 +01:00
|
|
|
influxClient, err := influx.NewClient(iCfg)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create influx client: %s", err)
|
|
|
|
}
|
|
|
|
|
2024-03-08 20:47:36 +01:00
|
|
|
vmCfg, err := initConfigVM(c)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to init VM configuration: %s", err)
|
|
|
|
}
|
2023-02-22 13:06:55 +01:00
|
|
|
importer, err = vm.NewImporter(ctx, vmCfg)
|
2021-02-01 00:10:16 +01:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create VM importer: %s", err)
|
|
|
|
}
|
|
|
|
|
2022-05-03 07:03:41 +02:00
|
|
|
processor := newInfluxProcessor(
|
|
|
|
influxClient,
|
|
|
|
importer,
|
|
|
|
c.Int(influxConcurrency),
|
2022-05-06 17:06:54 +02:00
|
|
|
c.String(influxMeasurementFieldSeparator),
|
2022-05-07 21:52:42 +02:00
|
|
|
c.Bool(influxSkipDatabaseLabel),
|
2023-06-02 14:57:08 +02:00
|
|
|
c.Bool(influxPrometheusMode),
|
|
|
|
c.Bool(globalSilent),
|
|
|
|
c.Bool(globalVerbose))
|
|
|
|
return processor.run()
|
2021-02-01 00:10:16 +01:00
|
|
|
},
|
|
|
|
},
|
2022-11-29 22:53:28 +01:00
|
|
|
{
|
|
|
|
Name: "remote-read",
|
|
|
|
Usage: "Migrate time series via Prometheus remote-read protocol",
|
|
|
|
Flags: mergeFlags(globalFlags, remoteReadFlags, vmFlags),
|
|
|
|
Action: func(c *cli.Context) error {
|
2024-03-14 11:45:39 +01:00
|
|
|
fmt.Println("Remote-read import mode")
|
|
|
|
|
|
|
|
addr := c.String(remoteReadSrcAddr)
|
|
|
|
|
|
|
|
// create TLS config
|
|
|
|
certFile := c.String(remoteReadCertFile)
|
|
|
|
keyFile := c.String(remoteReadKeyFile)
|
|
|
|
caFile := c.String(remoteReadCAFile)
|
|
|
|
serverName := c.String(remoteReadServerName)
|
|
|
|
insecureSkipVerify := c.Bool(remoteReadInsecureSkipVerify)
|
|
|
|
|
|
|
|
tr, err := httputils.Transport(addr, certFile, keyFile, caFile, serverName, insecureSkipVerify)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create transport: %s", err)
|
|
|
|
}
|
|
|
|
|
2022-11-29 22:53:28 +01:00
|
|
|
rr, err := remoteread.NewClient(remoteread.Config{
|
2024-03-14 11:45:39 +01:00
|
|
|
Addr: addr,
|
|
|
|
Transport: tr,
|
|
|
|
Username: c.String(remoteReadUser),
|
|
|
|
Password: c.String(remoteReadPassword),
|
|
|
|
Timeout: c.Duration(remoteReadHTTPTimeout),
|
|
|
|
UseStream: c.Bool(remoteReadUseStream),
|
|
|
|
Headers: c.String(remoteReadHeaders),
|
|
|
|
LabelName: c.String(remoteReadFilterLabel),
|
|
|
|
LabelValue: c.String(remoteReadFilterLabelValue),
|
|
|
|
DisablePathAppend: c.Bool(remoteReadDisablePathAppend),
|
2022-11-29 22:53:28 +01:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error create remote read client: %s", err)
|
|
|
|
}
|
|
|
|
|
2024-03-08 20:47:36 +01:00
|
|
|
vmCfg, err := initConfigVM(c)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to init VM configuration: %s", err)
|
|
|
|
}
|
2023-02-22 13:06:55 +01:00
|
|
|
importer, err := vm.NewImporter(ctx, vmCfg)
|
2022-11-29 22:53:28 +01:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create VM importer: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
rmp := remoteReadProcessor{
|
|
|
|
src: rr,
|
|
|
|
dst: importer,
|
|
|
|
filter: remoteReadFilter{
|
2023-12-12 13:05:44 +01:00
|
|
|
timeStart: c.Timestamp(remoteReadFilterTimeStart),
|
|
|
|
timeEnd: c.Timestamp(remoteReadFilterTimeEnd),
|
|
|
|
chunk: c.String(remoteReadStepInterval),
|
|
|
|
timeReverse: c.Bool(remoteReadFilterTimeReverse),
|
2022-11-29 22:53:28 +01:00
|
|
|
},
|
2023-06-02 14:57:08 +02:00
|
|
|
cc: c.Int(remoteReadConcurrency),
|
|
|
|
isSilent: c.Bool(globalSilent),
|
|
|
|
isVerbose: c.Bool(globalVerbose),
|
2022-11-29 22:53:28 +01:00
|
|
|
}
|
2023-06-02 14:57:08 +02:00
|
|
|
return rmp.run(ctx)
|
2022-11-29 22:53:28 +01:00
|
|
|
},
|
|
|
|
},
|
2021-02-01 00:10:16 +01:00
|
|
|
{
|
|
|
|
Name: "prometheus",
|
2022-11-29 22:53:28 +01:00
|
|
|
Usage: "Migrate time series from Prometheus",
|
2021-02-01 00:10:16 +01:00
|
|
|
Flags: mergeFlags(globalFlags, promFlags, vmFlags),
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
fmt.Println("Prometheus import mode")
|
|
|
|
|
2024-03-08 20:47:36 +01:00
|
|
|
vmCfg, err := initConfigVM(c)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to init VM configuration: %s", err)
|
|
|
|
}
|
2023-02-22 13:06:55 +01:00
|
|
|
importer, err = vm.NewImporter(ctx, vmCfg)
|
2021-02-01 00:10:16 +01:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create VM importer: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
promCfg := prometheus.Config{
|
|
|
|
Snapshot: c.String(promSnapshot),
|
|
|
|
Filter: prometheus.Filter{
|
|
|
|
TimeMin: c.String(promFilterTimeStart),
|
|
|
|
TimeMax: c.String(promFilterTimeEnd),
|
|
|
|
Label: c.String(promFilterLabel),
|
|
|
|
LabelValue: c.String(promFilterLabelValue),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
cl, err := prometheus.NewClient(promCfg)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create prometheus client: %s", err)
|
|
|
|
}
|
|
|
|
pp := prometheusProcessor{
|
|
|
|
cl: cl,
|
|
|
|
im: importer,
|
|
|
|
cc: c.Int(promConcurrency),
|
|
|
|
}
|
2023-06-02 14:57:08 +02:00
|
|
|
return pp.run(c.Bool(globalSilent), c.Bool(globalVerbose))
|
2021-02-01 00:10:16 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "vm-native",
|
|
|
|
Usage: "Migrate time series between VictoriaMetrics installations via native binary format",
|
2023-03-02 13:19:45 +01:00
|
|
|
Flags: mergeFlags(globalFlags, vmNativeFlags),
|
2021-02-01 00:10:16 +01:00
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
fmt.Println("VictoriaMetrics Native import mode")
|
|
|
|
|
|
|
|
if c.String(vmNativeFilterMatch) == "" {
|
|
|
|
return fmt.Errorf("flag %q can't be empty", vmNativeFilterMatch)
|
|
|
|
}
|
|
|
|
|
2023-04-14 08:34:54 +02:00
|
|
|
disableKeepAlive := c.Bool(vmNativeDisableHTTPKeepAlive)
|
|
|
|
|
2023-03-09 14:53:29 +01:00
|
|
|
var srcExtraLabels []string
|
|
|
|
srcAddr := strings.Trim(c.String(vmNativeSrcAddr), "/")
|
|
|
|
srcAuthConfig, err := auth.Generate(
|
|
|
|
auth.WithBasicAuth(c.String(vmNativeSrcUser), c.String(vmNativeSrcPassword)),
|
|
|
|
auth.WithBearer(c.String(vmNativeSrcBearerToken)),
|
|
|
|
auth.WithHeaders(c.String(vmNativeSrcHeaders)))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error initilize auth config for source: %s", srcAddr)
|
|
|
|
}
|
2024-03-08 19:52:55 +01:00
|
|
|
|
|
|
|
// create TLS config
|
|
|
|
srcCertFile := c.String(vmNativeSrcCertFile)
|
|
|
|
srcKeyFile := c.String(vmNativeSrcKeyFile)
|
|
|
|
srcCAFile := c.String(vmNativeSrcCAFile)
|
|
|
|
srcServerName := c.String(vmNativeSrcServerName)
|
|
|
|
srcInsecureSkipVerify := c.Bool(vmNativeSrcInsecureSkipVerify)
|
|
|
|
|
2024-03-14 11:22:12 +01:00
|
|
|
srcTC, err := httputils.TLSConfig(srcCertFile, srcKeyFile, srcCAFile, srcServerName, srcInsecureSkipVerify)
|
2024-03-08 19:52:55 +01:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create TLS Config: %s", err)
|
|
|
|
}
|
|
|
|
|
2024-01-11 14:04:32 +01:00
|
|
|
srcHTTPClient := &http.Client{Transport: &http.Transport{
|
|
|
|
DisableKeepAlives: disableKeepAlive,
|
2024-03-08 19:52:55 +01:00
|
|
|
TLSClientConfig: srcTC,
|
2024-01-11 14:04:32 +01:00
|
|
|
}}
|
2023-03-09 14:53:29 +01:00
|
|
|
|
|
|
|
dstAddr := strings.Trim(c.String(vmNativeDstAddr), "/")
|
|
|
|
dstExtraLabels := c.StringSlice(vmExtraLabel)
|
|
|
|
dstAuthConfig, err := auth.Generate(
|
|
|
|
auth.WithBasicAuth(c.String(vmNativeDstUser), c.String(vmNativeDstPassword)),
|
|
|
|
auth.WithBearer(c.String(vmNativeDstBearerToken)),
|
|
|
|
auth.WithHeaders(c.String(vmNativeDstHeaders)))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error initilize auth config for destination: %s", dstAddr)
|
|
|
|
}
|
2024-03-08 19:52:55 +01:00
|
|
|
|
|
|
|
// create TLS config
|
|
|
|
dstCertFile := c.String(vmNativeDstCertFile)
|
|
|
|
dstKeyFile := c.String(vmNativeDstKeyFile)
|
|
|
|
dstCAFile := c.String(vmNativeDstCAFile)
|
|
|
|
dstServerName := c.String(vmNativeDstServerName)
|
|
|
|
dstInsecureSkipVerify := c.Bool(vmNativeDstInsecureSkipVerify)
|
|
|
|
|
2024-03-14 11:22:12 +01:00
|
|
|
dstTC, err := httputils.TLSConfig(dstCertFile, dstKeyFile, dstCAFile, dstServerName, dstInsecureSkipVerify)
|
2024-03-08 19:52:55 +01:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create TLS Config: %s", err)
|
|
|
|
}
|
|
|
|
|
2024-01-11 14:04:32 +01:00
|
|
|
dstHTTPClient := &http.Client{Transport: &http.Transport{
|
|
|
|
DisableKeepAlives: disableKeepAlive,
|
2024-03-08 19:52:55 +01:00
|
|
|
TLSClientConfig: dstTC,
|
2024-01-11 14:04:32 +01:00
|
|
|
}}
|
2023-03-09 14:53:29 +01:00
|
|
|
|
2021-02-01 00:10:16 +01:00
|
|
|
p := vmNativeProcessor{
|
2022-12-06 02:18:09 +01:00
|
|
|
rateLimit: c.Int64(vmRateLimit),
|
|
|
|
interCluster: c.Bool(vmInterCluster),
|
2023-03-02 13:19:45 +01:00
|
|
|
filter: native.Filter{
|
2023-12-12 13:05:44 +01:00
|
|
|
Match: c.String(vmNativeFilterMatch),
|
|
|
|
TimeStart: c.String(vmNativeFilterTimeStart),
|
|
|
|
TimeEnd: c.String(vmNativeFilterTimeEnd),
|
|
|
|
Chunk: c.String(vmNativeStepInterval),
|
|
|
|
TimeReverse: c.Bool(vmNativeFilterTimeReverse),
|
2021-02-01 00:10:16 +01:00
|
|
|
},
|
2023-03-02 13:19:45 +01:00
|
|
|
src: &native.Client{
|
2023-04-14 08:34:54 +02:00
|
|
|
AuthCfg: srcAuthConfig,
|
|
|
|
Addr: srcAddr,
|
|
|
|
ExtraLabels: srcExtraLabels,
|
|
|
|
HTTPClient: srcHTTPClient,
|
2021-02-01 00:10:16 +01:00
|
|
|
},
|
2023-03-02 13:19:45 +01:00
|
|
|
dst: &native.Client{
|
2023-04-14 08:34:54 +02:00
|
|
|
AuthCfg: dstAuthConfig,
|
|
|
|
Addr: dstAddr,
|
|
|
|
ExtraLabels: dstExtraLabels,
|
|
|
|
HTTPClient: dstHTTPClient,
|
2021-02-01 00:10:16 +01:00
|
|
|
},
|
2023-12-15 12:36:28 +01:00
|
|
|
backoff: backoff.New(),
|
|
|
|
cc: c.Int(vmConcurrency),
|
|
|
|
disablePerMetricRequests: c.Bool(vmNativeDisablePerMetricMigration),
|
|
|
|
isSilent: c.Bool(globalSilent),
|
|
|
|
isNative: !c.Bool(vmNativeDisableBinaryProtocol),
|
2021-02-01 00:10:16 +01:00
|
|
|
}
|
2023-06-02 14:57:08 +02:00
|
|
|
return p.run(ctx)
|
2021-02-01 00:10:16 +01:00
|
|
|
},
|
|
|
|
},
|
2022-04-05 16:01:32 +02:00
|
|
|
{
|
|
|
|
Name: "verify-block",
|
|
|
|
Usage: "Verifies exported block with VictoriaMetrics Native format",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "gunzip",
|
|
|
|
Usage: "Use GNU zip decompression for exported block",
|
|
|
|
Value: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
common.StartUnmarshalWorkers()
|
|
|
|
blockPath := c.Args().First()
|
|
|
|
isBlockGzipped := c.Bool("gunzip")
|
|
|
|
if len(blockPath) == 0 {
|
|
|
|
return cli.Exit("you must provide path for exported data block", 1)
|
|
|
|
}
|
|
|
|
log.Printf("verifying block at path=%q", blockPath)
|
|
|
|
f, err := os.OpenFile(blockPath, os.O_RDONLY, 0600)
|
|
|
|
if err != nil {
|
|
|
|
return cli.Exit(fmt.Errorf("cannot open exported block at path=%q err=%w", blockPath, err), 1)
|
|
|
|
}
|
2024-04-16 11:33:04 +02:00
|
|
|
defer f.Close()
|
2024-02-24 01:44:19 +01:00
|
|
|
var blocksCount atomic.Uint64
|
2024-04-02 22:16:24 +02:00
|
|
|
if err := stream.Parse(f, isBlockGzipped, func(_ *stream.Block) error {
|
2024-02-24 01:44:19 +01:00
|
|
|
blocksCount.Add(1)
|
2022-04-05 16:01:32 +02:00
|
|
|
return nil
|
|
|
|
}); err != nil {
|
2024-02-24 01:44:19 +01:00
|
|
|
return cli.Exit(fmt.Errorf("cannot parse block at path=%q, blocksCount=%d, err=%w", blockPath, blocksCount.Load(), err), 1)
|
2022-04-05 16:01:32 +02:00
|
|
|
}
|
2024-02-24 01:44:19 +01:00
|
|
|
log.Printf("successfully verified block at path=%q, blockCount=%d", blockPath, blocksCount.Load())
|
2022-04-05 16:01:32 +02:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
2021-02-01 00:10:16 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
go func() {
|
|
|
|
<-c
|
|
|
|
fmt.Println("\r- Execution cancelled")
|
2022-01-03 20:12:01 +01:00
|
|
|
if importer != nil {
|
|
|
|
importer.Close()
|
|
|
|
}
|
2022-05-03 07:03:41 +02:00
|
|
|
cancelCtx()
|
2021-02-01 00:10:16 +01:00
|
|
|
}()
|
|
|
|
|
2022-01-03 20:12:01 +01:00
|
|
|
err = app.Run(os.Args)
|
2021-02-01 00:10:16 +01:00
|
|
|
if err != nil {
|
2022-04-13 11:52:55 +02:00
|
|
|
log.Fatalln(err)
|
2021-02-01 00:10:16 +01:00
|
|
|
}
|
|
|
|
log.Printf("Total time: %v", time.Since(start))
|
|
|
|
}
|
|
|
|
|
2024-03-08 20:47:36 +01:00
|
|
|
func initConfigVM(c *cli.Context) (vm.Config, error) {
|
|
|
|
addr := c.String(vmAddr)
|
|
|
|
|
|
|
|
// create Transport with given TLS config
|
|
|
|
certFile := c.String(vmCertFile)
|
|
|
|
keyFile := c.String(vmKeyFile)
|
|
|
|
caFile := c.String(vmCAFile)
|
|
|
|
serverName := c.String(vmServerName)
|
|
|
|
insecureSkipVerify := c.Bool(vmInsecureSkipVerify)
|
|
|
|
|
2024-03-14 11:45:39 +01:00
|
|
|
tr, err := httputils.Transport(addr, certFile, keyFile, caFile, serverName, insecureSkipVerify)
|
2024-03-08 20:47:36 +01:00
|
|
|
if err != nil {
|
|
|
|
return vm.Config{}, fmt.Errorf("failed to create Transport: %s", err)
|
|
|
|
}
|
|
|
|
|
2021-02-01 00:10:16 +01:00
|
|
|
return vm.Config{
|
2024-03-08 20:47:36 +01:00
|
|
|
Addr: addr,
|
|
|
|
Transport: tr,
|
2021-02-01 00:10:16 +01:00
|
|
|
User: c.String(vmUser),
|
|
|
|
Password: c.String(vmPassword),
|
|
|
|
Concurrency: uint8(c.Int(vmConcurrency)),
|
|
|
|
Compress: c.Bool(vmCompress),
|
|
|
|
AccountID: c.String(vmAccountID),
|
|
|
|
BatchSize: c.Int(vmBatchSize),
|
|
|
|
SignificantFigures: c.Int(vmSignificantFigures),
|
2021-02-01 13:27:05 +01:00
|
|
|
RoundDigits: c.Int(vmRoundDigits),
|
2021-02-01 00:10:16 +01:00
|
|
|
ExtraLabels: c.StringSlice(vmExtraLabel),
|
2021-12-24 11:18:07 +01:00
|
|
|
RateLimit: c.Int64(vmRateLimit),
|
2022-05-02 09:06:34 +02:00
|
|
|
DisableProgressBar: c.Bool(vmDisableProgressBar),
|
2024-03-08 20:47:36 +01:00
|
|
|
}, nil
|
2021-02-01 00:10:16 +01:00
|
|
|
}
|