Add goreport card and remove warnings where feasible

This commit is contained in:
beorn7 2016-09-16 19:59:04 +02:00
parent 8aae34f3ff
commit c9325a4a67
10 changed files with 22 additions and 17 deletions

View File

@ -1,6 +1,7 @@
# Prometheus Go client library # Prometheus Go client library
[![Build Status](https://travis-ci.org/prometheus/client_golang.svg?branch=master)](https://travis-ci.org/prometheus/client_golang) [![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 This is the [Go](http://golang.org) client library for
[Prometheus](http://prometheus.io). It has two separate parts, one for [Prometheus](http://prometheus.io). It has two separate parts, one for

View File

@ -42,10 +42,11 @@ const (
epSeries = "/series" epSeries = "/series"
) )
// ErrorType models the different API error types.
type ErrorType string type ErrorType string
// Possible values for ErrorType.
const ( const (
// The different API error types.
ErrBadData ErrorType = "bad_data" ErrBadData ErrorType = "bad_data"
ErrTimeout = "timeout" ErrTimeout = "timeout"
ErrCanceled = "canceled" ErrCanceled = "canceled"
@ -70,6 +71,7 @@ type CancelableTransport interface {
CancelRequest(req *http.Request) CancelRequest(req *http.Request)
} }
// DefaultTransport is used if no Transport is set in Config.
var DefaultTransport CancelableTransport = &http.Transport{ var DefaultTransport CancelableTransport = &http.Transport{
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{ Dial: (&net.Dialer{
@ -96,6 +98,7 @@ func (cfg *Config) transport() CancelableTransport {
return cfg.Transport return cfg.Transport
} }
// Client is the interface for an API client.
type Client interface { type Client interface {
url(ep string, args map[string]string) *url.URL url(ep string, args map[string]string) *url.URL
do(context.Context, *http.Request) (*http.Response, []byte, error) do(context.Context, *http.Request) (*http.Response, []byte, error)

View File

@ -352,19 +352,19 @@ func TestAPIs(t *testing.T) {
client := &apiTestClient{T: t} client := &apiTestClient{T: t}
queryApi := &httpQueryAPI{ queryAPI := &httpQueryAPI{
client: client, client: client,
} }
doQuery := func(q string, ts time.Time) func() (interface{}, error) { doQuery := func(q string, ts time.Time) func() (interface{}, error) {
return 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) { doQueryRange := func(q string, rng Range) func() (interface{}, error) {
return func() (interface{}, error) { return func() (interface{}, error) {
return queryApi.QueryRange(context.Background(), q, rng) return queryAPI.QueryRange(context.Background(), q, rng)
} }
} }

View File

@ -78,7 +78,7 @@ type Desc struct {
// Help string. Each Desc with the same fqName must have the same // Help string. Each Desc with the same fqName must have the same
// dimHash. // dimHash.
dimHash uint64 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. // registration time.
err error err error
} }

View File

@ -113,7 +113,7 @@ func ExampleCounter() {
pushComplete := make(chan struct{}) pushComplete := make(chan struct{})
// TODO: Start a goroutine that performs repository pushes and reports // TODO: Start a goroutine that performs repository pushes and reports
// each completion via the channel. // each completion via the channel.
for _ = range pushComplete { for range pushComplete {
pushCounter.Inc() pushCounter.Inc()
} }
// Output: // Output:
@ -169,8 +169,8 @@ func ExampleInstrumentHandler() {
func ExampleLabelPairSorter() { func ExampleLabelPairSorter() {
labelPairs := []*dto.LabelPair{ labelPairs := []*dto.LabelPair{
&dto.LabelPair{Name: proto.String("status"), Value: proto.String("404")}, {Name: proto.String("status"), Value: proto.String("404")},
&dto.LabelPair{Name: proto.String("method"), Value: proto.String("get")}, {Name: proto.String("method"), Value: proto.String("get")},
} }
sort.Sort(prometheus.LabelPairSorter(labelPairs)) sort.Sort(prometheus.LabelPairSorter(labelPairs))
@ -640,6 +640,7 @@ func ExampleAlreadyRegisteredError() {
panic(err) panic(err)
} }
} }
reqCounter.Inc()
} }
func ExampleGatherers() { func ExampleGatherers() {

View File

@ -24,7 +24,7 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
func ExampleExpvarCollector() { func ExampleNewExpvarCollector() {
expvarCollector := prometheus.NewExpvarCollector(map[string]*prometheus.Desc{ expvarCollector := prometheus.NewExpvarCollector(map[string]*prometheus.Desc{
"memstats": prometheus.NewDesc( "memstats": prometheus.NewDesc(
"expvar_memstats", "expvar_memstats",

View File

@ -24,7 +24,7 @@ import (
func ExampleCollectors() { func ExampleCollectors() {
completionTime := prometheus.NewGauge(prometheus.GaugeOpts{ completionTime := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "db_backup_last_completion_timestamp_seconds", 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())) completionTime.Set(float64(time.Now().Unix()))
if err := push.Collectors( if err := push.Collectors(
@ -36,12 +36,12 @@ func ExampleCollectors() {
} }
} }
func ExampleRegistry() { func ExampleFromGatherer() {
registry := prometheus.NewRegistry() registry := prometheus.NewRegistry()
completionTime := prometheus.NewGauge(prometheus.GaugeOpts{ completionTime := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "db_backup_last_completion_timestamp_seconds", 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) registry.MustRegister(completionTime)

View File

@ -447,7 +447,7 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) {
// Drain metricChan in case of premature return. // Drain metricChan in case of premature return.
defer func() { 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() 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 // MetricFamilies pruned and the remaining MetricFamilies sorted by name within
// the slice, with the contained Metrics sorted within each MetricFamily. // the slice, with the contained Metrics sorted within each MetricFamily.
func normalizeMetricFamilies(metricFamiliesByName map[string]*dto.MetricFamily) []*dto.MetricFamily { func normalizeMetricFamilies(metricFamiliesByName map[string]*dto.MetricFamily) []*dto.MetricFamily {

View File

@ -305,7 +305,7 @@ func TestSummaryDecay(t *testing.T) {
m := &dto.Metric{} m := &dto.Metric{}
i := 0 i := 0
tick := time.NewTicker(time.Millisecond) tick := time.NewTicker(time.Millisecond)
for _ = range tick.C { for range tick.C {
i++ i++
sum.Observe(float64(i)) sum.Observe(float64(i))
if i%10 == 0 { if i%10 == 0 {

View File

@ -241,8 +241,8 @@ func TestCounterVecEndToEndWithCollision(t *testing.T) {
func BenchmarkMetricVecWithLabelValuesBasic(b *testing.B) { func BenchmarkMetricVecWithLabelValuesBasic(b *testing.B) {
benchmarkMetricVecWithLabelValues(b, map[string][]string{ benchmarkMetricVecWithLabelValues(b, map[string][]string{
"l1": []string{"onevalue"}, "l1": {"onevalue"},
"l2": []string{"twovalue"}, "l2": {"twovalue"},
}) })
} }