forked from mirror/client_golang
Merge pull request #238 from prometheus/beorn7/lint
Add goreport card and remove warnings where feasible
This commit is contained in:
commit
5636dc67ae
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"},
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue