From c9325a4a671129712361a47ecfa1701a103f1135 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Fri, 16 Sep 2016 19:59:04 +0200 Subject: [PATCH] Add goreport card and remove warnings where feasible --- README.md | 1 + api/prometheus/api.go | 5 ++++- api/prometheus/api_test.go | 6 +++--- prometheus/desc.go | 2 +- prometheus/examples_test.go | 7 ++++--- prometheus/expvar_collector_test.go | 2 +- prometheus/push/examples_test.go | 6 +++--- prometheus/registry.go | 4 ++-- prometheus/summary_test.go | 2 +- prometheus/vec_test.go | 4 ++-- 10 files changed, 22 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 557eacf..d0e06bd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Prometheus Go client library [![Build Status](https://travis-ci.org/prometheus/client_golang.svg?branch=master)](https://travis-ci.org/prometheus/client_golang) +[![Go Report Card](https://goreportcard.com/badge/github.com/prometheus/client_golang)](https://goreportcard.com/report/github.com/prometheus/client_golang) This is the [Go](http://golang.org) client library for [Prometheus](http://prometheus.io). It has two separate parts, one for diff --git a/api/prometheus/api.go b/api/prometheus/api.go index 3028d74..cc5cbc3 100644 --- a/api/prometheus/api.go +++ b/api/prometheus/api.go @@ -42,10 +42,11 @@ const ( epSeries = "/series" ) +// ErrorType models the different API error types. type ErrorType string +// Possible values for ErrorType. const ( - // The different API error types. ErrBadData ErrorType = "bad_data" ErrTimeout = "timeout" ErrCanceled = "canceled" @@ -70,6 +71,7 @@ type CancelableTransport interface { CancelRequest(req *http.Request) } +// DefaultTransport is used if no Transport is set in Config. var DefaultTransport CancelableTransport = &http.Transport{ Proxy: http.ProxyFromEnvironment, Dial: (&net.Dialer{ @@ -96,6 +98,7 @@ func (cfg *Config) transport() CancelableTransport { return cfg.Transport } +// Client is the interface for an API client. type Client interface { url(ep string, args map[string]string) *url.URL do(context.Context, *http.Request) (*http.Response, []byte, error) diff --git a/api/prometheus/api_test.go b/api/prometheus/api_test.go index 87d3e40..ca084a0 100644 --- a/api/prometheus/api_test.go +++ b/api/prometheus/api_test.go @@ -352,19 +352,19 @@ func TestAPIs(t *testing.T) { client := &apiTestClient{T: t} - queryApi := &httpQueryAPI{ + queryAPI := &httpQueryAPI{ client: client, } doQuery := func(q string, ts time.Time) func() (interface{}, error) { return func() (interface{}, error) { - return queryApi.Query(context.Background(), q, ts) + return queryAPI.Query(context.Background(), q, ts) } } doQueryRange := func(q string, rng Range) func() (interface{}, error) { return func() (interface{}, error) { - return queryApi.QueryRange(context.Background(), q, rng) + return queryAPI.QueryRange(context.Background(), q, rng) } } diff --git a/prometheus/desc.go b/prometheus/desc.go index 77f4b30..0593be5 100644 --- a/prometheus/desc.go +++ b/prometheus/desc.go @@ -78,7 +78,7 @@ type Desc struct { // Help string. Each Desc with the same fqName must have the same // dimHash. dimHash uint64 - // err is an error that occured during construction. It is reported on + // err is an error that occurred during construction. It is reported on // registration time. err error } diff --git a/prometheus/examples_test.go b/prometheus/examples_test.go index f87f21a..468c9ef 100644 --- a/prometheus/examples_test.go +++ b/prometheus/examples_test.go @@ -113,7 +113,7 @@ func ExampleCounter() { pushComplete := make(chan struct{}) // TODO: Start a goroutine that performs repository pushes and reports // each completion via the channel. - for _ = range pushComplete { + for range pushComplete { pushCounter.Inc() } // Output: @@ -169,8 +169,8 @@ func ExampleInstrumentHandler() { func ExampleLabelPairSorter() { labelPairs := []*dto.LabelPair{ - &dto.LabelPair{Name: proto.String("status"), Value: proto.String("404")}, - &dto.LabelPair{Name: proto.String("method"), Value: proto.String("get")}, + {Name: proto.String("status"), Value: proto.String("404")}, + {Name: proto.String("method"), Value: proto.String("get")}, } sort.Sort(prometheus.LabelPairSorter(labelPairs)) @@ -640,6 +640,7 @@ func ExampleAlreadyRegisteredError() { panic(err) } } + reqCounter.Inc() } func ExampleGatherers() { diff --git a/prometheus/expvar_collector_test.go b/prometheus/expvar_collector_test.go index 5d3128f..910dac3 100644 --- a/prometheus/expvar_collector_test.go +++ b/prometheus/expvar_collector_test.go @@ -24,7 +24,7 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func ExampleExpvarCollector() { +func ExampleNewExpvarCollector() { expvarCollector := prometheus.NewExpvarCollector(map[string]*prometheus.Desc{ "memstats": prometheus.NewDesc( "expvar_memstats", diff --git a/prometheus/push/examples_test.go b/prometheus/push/examples_test.go index 7f17ca2..8006bda 100644 --- a/prometheus/push/examples_test.go +++ b/prometheus/push/examples_test.go @@ -24,7 +24,7 @@ import ( func ExampleCollectors() { completionTime := prometheus.NewGauge(prometheus.GaugeOpts{ Name: "db_backup_last_completion_timestamp_seconds", - Help: "The timestamp of the last succesful completion of a DB backup.", + Help: "The timestamp of the last successful completion of a DB backup.", }) completionTime.Set(float64(time.Now().Unix())) if err := push.Collectors( @@ -36,12 +36,12 @@ func ExampleCollectors() { } } -func ExampleRegistry() { +func ExampleFromGatherer() { registry := prometheus.NewRegistry() completionTime := prometheus.NewGauge(prometheus.GaugeOpts{ Name: "db_backup_last_completion_timestamp_seconds", - Help: "The timestamp of the last succesful completion of a DB backup.", + Help: "The timestamp of the last successful completion of a DB backup.", }) registry.MustRegister(completionTime) diff --git a/prometheus/registry.go b/prometheus/registry.go index 32a3986..405d6dd 100644 --- a/prometheus/registry.go +++ b/prometheus/registry.go @@ -447,7 +447,7 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) { // Drain metricChan in case of premature return. defer func() { - for _ = range metricChan { + for range metricChan { } }() @@ -683,7 +683,7 @@ func (s metricSorter) Less(i, j int) bool { return s[i].GetTimestampMs() < s[j].GetTimestampMs() } -// normalizeMetricFamilies returns a MetricFamily slice whith empty +// normalizeMetricFamilies returns a MetricFamily slice with empty // MetricFamilies pruned and the remaining MetricFamilies sorted by name within // the slice, with the contained Metrics sorted within each MetricFamily. func normalizeMetricFamilies(metricFamiliesByName map[string]*dto.MetricFamily) []*dto.MetricFamily { diff --git a/prometheus/summary_test.go b/prometheus/summary_test.go index c4575ff..b14c997 100644 --- a/prometheus/summary_test.go +++ b/prometheus/summary_test.go @@ -305,7 +305,7 @@ func TestSummaryDecay(t *testing.T) { m := &dto.Metric{} i := 0 tick := time.NewTicker(time.Millisecond) - for _ = range tick.C { + for range tick.C { i++ sum.Observe(float64(i)) if i%10 == 0 { diff --git a/prometheus/vec_test.go b/prometheus/vec_test.go index 445a6b3..e3c5aeb 100644 --- a/prometheus/vec_test.go +++ b/prometheus/vec_test.go @@ -241,8 +241,8 @@ func TestCounterVecEndToEndWithCollision(t *testing.T) { func BenchmarkMetricVecWithLabelValuesBasic(b *testing.B) { benchmarkMetricVecWithLabelValues(b, map[string][]string{ - "l1": []string{"onevalue"}, - "l2": []string{"twovalue"}, + "l1": {"onevalue"}, + "l2": {"twovalue"}, }) }