app/vmctl: fix make check-all warnings

This commit is contained in:
Aliaksandr Valialkin 2021-02-01 01:31:25 +02:00
parent 7f4fb34182
commit 05474aaa29
9 changed files with 28 additions and 9 deletions

View File

@ -6,9 +6,9 @@ import (
"log" "log"
"sync" "sync"
"github.com/cheggaaa/pb/v3"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/influx" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/influx"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm"
"github.com/cheggaaa/pb/v3"
) )
type influxProcessor struct { type influxProcessor struct {
@ -95,7 +95,9 @@ func (ip *influxProcessor) do(s *influx.Series) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to fetch datapoints: %s", err) return fmt.Errorf("failed to fetch datapoints: %s", err)
} }
defer cr.Close() defer func() {
_ = cr.Close()
}()
var name string var name string
if s.Measurement != "" { if s.Measurement != "" {
name = fmt.Sprintf("%s%s%s", s.Measurement, ip.separator, s.Field) name = fmt.Sprintf("%s%s%s", s.Measurement, ip.separator, s.Field)

View File

@ -115,6 +115,7 @@ func NewClient(cfg Config) (*Client, error) {
return client, nil return client, nil
} }
// Database returns database name
func (c Client) Database() string { func (c Client) Database() string {
return c.database return c.database
} }
@ -184,6 +185,7 @@ type ChunkedResponse struct {
field string field string
} }
// Close closes cr.
func (cr *ChunkedResponse) Close() error { func (cr *ChunkedResponse) Close() error {
return cr.cr.Close() return cr.cr.Close()
} }

View File

@ -9,11 +9,11 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/urfave/cli/v2"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/influx" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/influx"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/prometheus" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/prometheus"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo" "github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo"
"github.com/urfave/cli/v2"
) )
func main() { func main() {

View File

@ -5,10 +5,10 @@ import (
"log" "log"
"sync" "sync"
"github.com/cheggaaa/pb/v3"
"github.com/prometheus/prometheus/tsdb"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/prometheus" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/prometheus"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm"
"github.com/cheggaaa/pb/v3"
"github.com/prometheus/prometheus/tsdb"
) )
type prometheusProcessor struct { type prometheusProcessor struct {

View File

@ -27,7 +27,7 @@ type Filter struct {
LabelValue string LabelValue string
} }
// Clinet is a wrapper over Prometheus tsdb.DBReader // Client is a wrapper over Prometheus tsdb.DBReader
type Client struct { type Client struct {
*tsdb.DBReadOnly *tsdb.DBReadOnly
filter filter filter filter

View File

@ -5,6 +5,7 @@ import (
"time" "time"
) )
// Stats represents data migration stats.
type Stats struct { type Stats struct {
Filtered bool Filtered bool
MinTime int64 MinTime int64
@ -15,6 +16,7 @@ type Stats struct {
SkippedBlocks int SkippedBlocks int
} }
// String returns string representation for s.
func (s Stats) String() string { func (s Stats) String() string {
str := fmt.Sprintf("Prometheus snapshot stats:\n"+ str := fmt.Sprintf("Prometheus snapshot stats:\n"+
" blocks found: %d;\n"+ " blocks found: %d;\n"+

View File

@ -5,6 +5,7 @@ import (
"io" "io"
) )
// TimeSeries represents a time series.
type TimeSeries struct { type TimeSeries struct {
Name string Name string
LabelPairs []LabelPair LabelPairs []LabelPair
@ -12,11 +13,13 @@ type TimeSeries struct {
Values []float64 Values []float64
} }
// LabelPair represents a label
type LabelPair struct { type LabelPair struct {
Name string Name string
Value string Value string
} }
// String returns user-readable ts.
func (ts TimeSeries) String() string { func (ts TimeSeries) String() string {
s := ts.Name s := ts.Name
if len(ts.LabelPairs) < 1 { if len(ts.LabelPairs) < 1 {

View File

@ -66,12 +66,14 @@ type Importer struct {
s *stats s *stats
} }
// ResetStats resets im stats.
func (im *Importer) ResetStats() { func (im *Importer) ResetStats() {
im.s = &stats{ im.s = &stats{
startTime: time.Now(), startTime: time.Now(),
} }
} }
// Stats returns im stats.
func (im *Importer) Stats() string { func (im *Importer) Stats() string {
return im.s.String() return im.s.String()
} }
@ -92,6 +94,7 @@ func AddExtraLabelsToImportPath(path string, extraLabels []string) (string, erro
return dst, nil return dst, nil
} }
// NewImporter creates new Importer for the given cfg.
func NewImporter(cfg Config) (*Importer, error) { func NewImporter(cfg Config) (*Importer, error) {
if cfg.Concurrency < 1 { if cfg.Concurrency < 1 {
return nil, fmt.Errorf("concurrency can't be lower than 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) return fmt.Errorf("import failed with %d retries: %s", backoffRetries, err)
} }
// Ping sends a ping to im.addr.
func (im *Importer) Ping() error { func (im *Importer) Ping() error {
url := fmt.Sprintf("%s/health", im.addr) url := fmt.Sprintf("%s/health", im.addr)
req, err := http.NewRequest("GET", url, nil) req, err := http.NewRequest("GET", url, nil)
@ -264,6 +268,7 @@ func (im *Importer) Ping() error {
return nil return nil
} }
// Import imports tsBatch.
func (im *Importer) Import(tsBatch []*TimeSeries) error { func (im *Importer) Import(tsBatch []*TimeSeries) error {
if len(tsBatch) < 1 { if len(tsBatch) < 1 {
return nil return nil
@ -333,6 +338,7 @@ func (im *Importer) Import(tsBatch []*TimeSeries) error {
return nil return nil
} }
// ErrBadRequest represents bad request error.
var ErrBadRequest = errors.New("bad request") var ErrBadRequest = errors.New("bad request")
func do(req *http.Request) error { func do(req *http.Request) error {
@ -340,7 +346,9 @@ func do(req *http.Request) error {
if err != nil { if err != nil {
return fmt.Errorf("unexpected error when performing request: %s", err) return fmt.Errorf("unexpected error when performing request: %s", err)
} }
defer resp.Body.Close() defer func() {
_ = resp.Body.Close()
}()
if resp.StatusCode != http.StatusNoContent { if resp.StatusCode != http.StatusNoContent {
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {

View File

@ -7,8 +7,8 @@ import (
"log" "log"
"net/http" "net/http"
"github.com/cheggaaa/pb/v3"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm"
"github.com/cheggaaa/pb/v3"
) )
type vmNativeProcessor struct { type vmNativeProcessor struct {
@ -75,7 +75,9 @@ func (p *vmNativeProcessor) run() error {
if err != nil { if err != nil {
log.Fatalf("import request failed: %s", err) 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) fmt.Printf("Initing import process to %q:\n", p.dst.addr)