app/vmctl: fix make check-all warnings

This commit is contained in:
Aliaksandr Valialkin 2021-02-01 01:31:25 +02:00
parent d5c180e680
commit 29a7067827
9 changed files with 28 additions and 9 deletions

View file

@ -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)

View file

@ -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()
}

View file

@ -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() {

View file

@ -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 {

View file

@ -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

View file

@ -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"+

View file

@ -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 {

View file

@ -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 {

View file

@ -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)