From 05474aaa29e25844e24bffef72c9ffc355487d59 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 1 Feb 2021 01:31:25 +0200 Subject: [PATCH] app/vmctl: fix `make check-all` warnings --- app/vmctl/influx.go | 6 ++++-- app/vmctl/influx/influx.go | 2 ++ app/vmctl/main.go | 2 +- app/vmctl/prometheus.go | 4 ++-- app/vmctl/prometheus/prometheus.go | 2 +- app/vmctl/prometheus/stats.go | 2 ++ app/vmctl/vm/timeseries.go | 3 +++ app/vmctl/vm/vm.go | 10 +++++++++- app/vmctl/vm_native.go | 6 ++++-- 9 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/vmctl/influx.go b/app/vmctl/influx.go index 032f1f6398..ececc59c6d 100644 --- a/app/vmctl/influx.go +++ b/app/vmctl/influx.go @@ -6,9 +6,9 @@ import ( "log" "sync" - "github.com/cheggaaa/pb/v3" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/influx" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm" + "github.com/cheggaaa/pb/v3" ) type influxProcessor struct { @@ -95,7 +95,9 @@ func (ip *influxProcessor) do(s *influx.Series) error { if err != nil { return fmt.Errorf("failed to fetch datapoints: %s", err) } - defer cr.Close() + defer func() { + _ = cr.Close() + }() var name string if s.Measurement != "" { name = fmt.Sprintf("%s%s%s", s.Measurement, ip.separator, s.Field) diff --git a/app/vmctl/influx/influx.go b/app/vmctl/influx/influx.go index 9e68b741a6..79ca5f2490 100644 --- a/app/vmctl/influx/influx.go +++ b/app/vmctl/influx/influx.go @@ -115,6 +115,7 @@ func NewClient(cfg Config) (*Client, error) { return client, nil } +// Database returns database name func (c Client) Database() string { return c.database } @@ -184,6 +185,7 @@ type ChunkedResponse struct { field string } +// Close closes cr. func (cr *ChunkedResponse) Close() error { return cr.cr.Close() } diff --git a/app/vmctl/main.go b/app/vmctl/main.go index d11aae8cca..89cc1c1ee0 100644 --- a/app/vmctl/main.go +++ b/app/vmctl/main.go @@ -9,11 +9,11 @@ import ( "syscall" "time" - "github.com/urfave/cli/v2" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/influx" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/prometheus" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm" "github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo" + "github.com/urfave/cli/v2" ) func main() { diff --git a/app/vmctl/prometheus.go b/app/vmctl/prometheus.go index a6c4a11ae4..cb0c02b828 100644 --- a/app/vmctl/prometheus.go +++ b/app/vmctl/prometheus.go @@ -5,10 +5,10 @@ import ( "log" "sync" - "github.com/cheggaaa/pb/v3" - "github.com/prometheus/prometheus/tsdb" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/prometheus" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm" + "github.com/cheggaaa/pb/v3" + "github.com/prometheus/prometheus/tsdb" ) type prometheusProcessor struct { diff --git a/app/vmctl/prometheus/prometheus.go b/app/vmctl/prometheus/prometheus.go index fad37e4c6a..39b9fe7090 100644 --- a/app/vmctl/prometheus/prometheus.go +++ b/app/vmctl/prometheus/prometheus.go @@ -27,7 +27,7 @@ type Filter struct { LabelValue string } -// Clinet is a wrapper over Prometheus tsdb.DBReader +// Client is a wrapper over Prometheus tsdb.DBReader type Client struct { *tsdb.DBReadOnly filter filter diff --git a/app/vmctl/prometheus/stats.go b/app/vmctl/prometheus/stats.go index a5d778debf..e6dc907d57 100644 --- a/app/vmctl/prometheus/stats.go +++ b/app/vmctl/prometheus/stats.go @@ -5,6 +5,7 @@ import ( "time" ) +// Stats represents data migration stats. type Stats struct { Filtered bool MinTime int64 @@ -15,6 +16,7 @@ type Stats struct { SkippedBlocks int } +// String returns string representation for s. func (s Stats) String() string { str := fmt.Sprintf("Prometheus snapshot stats:\n"+ " blocks found: %d;\n"+ diff --git a/app/vmctl/vm/timeseries.go b/app/vmctl/vm/timeseries.go index 7941268bab..7a54a51528 100644 --- a/app/vmctl/vm/timeseries.go +++ b/app/vmctl/vm/timeseries.go @@ -5,6 +5,7 @@ import ( "io" ) +// TimeSeries represents a time series. type TimeSeries struct { Name string LabelPairs []LabelPair @@ -12,11 +13,13 @@ type TimeSeries struct { Values []float64 } +// LabelPair represents a label type LabelPair struct { Name string Value string } +// String returns user-readable ts. func (ts TimeSeries) String() string { s := ts.Name if len(ts.LabelPairs) < 1 { diff --git a/app/vmctl/vm/vm.go b/app/vmctl/vm/vm.go index aac65f943a..dcae12f677 100644 --- a/app/vmctl/vm/vm.go +++ b/app/vmctl/vm/vm.go @@ -66,12 +66,14 @@ type Importer struct { s *stats } +// ResetStats resets im stats. func (im *Importer) ResetStats() { im.s = &stats{ startTime: time.Now(), } } +// Stats returns im stats. func (im *Importer) Stats() string { return im.s.String() } @@ -92,6 +94,7 @@ func AddExtraLabelsToImportPath(path string, extraLabels []string) (string, erro return dst, nil } +// NewImporter creates new Importer for the given cfg. func NewImporter(cfg Config) (*Importer, error) { if cfg.Concurrency < 1 { return nil, fmt.Errorf("concurrency can't be lower than 1") @@ -245,6 +248,7 @@ func (im *Importer) flush(b []*TimeSeries) error { return fmt.Errorf("import failed with %d retries: %s", backoffRetries, err) } +// Ping sends a ping to im.addr. func (im *Importer) Ping() error { url := fmt.Sprintf("%s/health", im.addr) req, err := http.NewRequest("GET", url, nil) @@ -264,6 +268,7 @@ func (im *Importer) Ping() error { return nil } +// Import imports tsBatch. func (im *Importer) Import(tsBatch []*TimeSeries) error { if len(tsBatch) < 1 { return nil @@ -333,6 +338,7 @@ func (im *Importer) Import(tsBatch []*TimeSeries) error { return nil } +// ErrBadRequest represents bad request error. var ErrBadRequest = errors.New("bad request") func do(req *http.Request) error { @@ -340,7 +346,9 @@ func do(req *http.Request) error { if err != nil { return fmt.Errorf("unexpected error when performing request: %s", err) } - defer resp.Body.Close() + defer func() { + _ = resp.Body.Close() + }() if resp.StatusCode != http.StatusNoContent { body, err := ioutil.ReadAll(resp.Body) if err != nil { diff --git a/app/vmctl/vm_native.go b/app/vmctl/vm_native.go index a691748478..02a9ffd0db 100644 --- a/app/vmctl/vm_native.go +++ b/app/vmctl/vm_native.go @@ -7,8 +7,8 @@ import ( "log" "net/http" - "github.com/cheggaaa/pb/v3" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm" + "github.com/cheggaaa/pb/v3" ) type vmNativeProcessor struct { @@ -75,7 +75,9 @@ func (p *vmNativeProcessor) run() error { if err != nil { log.Fatalf("import request failed: %s", err) } - importResp.Body.Close() + if err := importResp.Body.Close(); err != nil { + log.Fatalf("cannot close import response body: %s", err) + } }() fmt.Printf("Initing import process to %q:\n", p.dst.addr)