vendor: upgrade github.com/armon/go-metrics

Pull in changes to fix race condition for concurrent tests.
This commit is contained in:
Frank Schroeder 2017-06-01 23:52:26 +02:00
parent 375825f34c
commit c5ba51db19
No known key found for this signature in database
GPG Key ID: 4D65C6EAEC87DECD
8 changed files with 122 additions and 40 deletions

View File

@ -28,6 +28,7 @@ Examples
Here is an example of using the package: Here is an example of using the package:
```go
func SlowMethod() { func SlowMethod() {
// Profiling the runtime of a method // Profiling the runtime of a method
defer metrics.MeasureSince([]string{"SlowMethod"}, time.Now()) defer metrics.MeasureSince([]string{"SlowMethod"}, time.Now())
@ -39,10 +40,11 @@ Here is an example of using the package:
// Emit a Key/Value pair // Emit a Key/Value pair
metrics.EmitKey([]string{"questions", "meaning of life"}, 42) metrics.EmitKey([]string{"questions", "meaning of life"}, 42)
```
Here is an example of setting up a signal handler:
Here is an example of setting up an signal handler: ```go
// Setup the inmem sink and signal handler // Setup the inmem sink and signal handler
inm := metrics.NewInmemSink(10*time.Second, time.Minute) inm := metrics.NewInmemSink(10*time.Second, time.Minute)
sig := metrics.DefaultInmemSignal(inm) sig := metrics.DefaultInmemSignal(inm)
@ -61,6 +63,7 @@ Here is an example of setting up an signal handler:
inm.AddSample([]string{"method", "wow"}, 22) inm.AddSample([]string{"method", "wow"}, 22)
.... ....
```
When a signal comes in, output like the following will be dumped to stderr: When a signal comes in, output like the following will be dumped to stderr:

View File

@ -3,6 +3,7 @@ package metrics
import ( import (
"fmt" "fmt"
"math" "math"
"net/url"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -120,6 +121,24 @@ func (a *AggregateSample) String() string {
} }
} }
// NewInmemSinkFromURL creates an InmemSink from a URL. It is used
// (and tested) from NewMetricSinkFromURL.
func NewInmemSinkFromURL(u *url.URL) (MetricSink, error) {
params := u.Query()
interval, err := time.ParseDuration(params.Get("interval"))
if err != nil {
return nil, fmt.Errorf("Bad 'interval' param: %s", err)
}
retain, err := time.ParseDuration(params.Get("retain"))
if err != nil {
return nil, fmt.Errorf("Bad 'retain' param: %s", err)
}
return NewInmemSink(interval, retain), nil
}
// NewInmemSink is used to construct a new in-memory sink. // NewInmemSink is used to construct a new in-memory sink.
// Uses an aggregation interval and maximum retention period. // Uses an aggregation interval and maximum retention period.
func NewInmemSink(interval, retain time.Duration) *InmemSink { func NewInmemSink(interval, retain time.Duration) *InmemSink {

0
vendor/github.com/armon/go-metrics/metrics.go generated vendored Executable file → Normal file
View File

45
vendor/github.com/armon/go-metrics/sink.go generated vendored Executable file → Normal file
View File

@ -1,5 +1,10 @@
package metrics package metrics
import (
"fmt"
"net/url"
)
// The MetricSink interface is used to transmit metrics information // The MetricSink interface is used to transmit metrics information
// to an external system // to an external system
type MetricSink interface { type MetricSink interface {
@ -50,3 +55,43 @@ func (fh FanoutSink) AddSample(key []string, val float32) {
s.AddSample(key, val) s.AddSample(key, val)
} }
} }
// sinkURLFactoryFunc is an generic interface around the *SinkFromURL() function provided
// by each sink type
type sinkURLFactoryFunc func(*url.URL) (MetricSink, error)
// sinkRegistry supports the generic NewMetricSink function by mapping URL
// schemes to metric sink factory functions
var sinkRegistry = map[string]sinkURLFactoryFunc{
"statsd": NewStatsdSinkFromURL,
"statsite": NewStatsiteSinkFromURL,
"inmem": NewInmemSinkFromURL,
}
// NewMetricSinkFromURL allows a generic URL input to configure any of the
// supported sinks. The scheme of the URL identifies the type of the sink, the
// and query parameters are used to set options.
//
// "statsd://" - Initializes a StatsdSink. The host and port are passed through
// as the "addr" of the sink
//
// "statsite://" - Initializes a StatsiteSink. The host and port become the
// "addr" of the sink
//
// "inmem://" - Initializes an InmemSink. The host and port are ignored. The
// "interval" and "duration" query parameters must be specified with valid
// durations, see NewInmemSink for details.
func NewMetricSinkFromURL(urlStr string) (MetricSink, error) {
u, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
sinkURLFactoryFunc := sinkRegistry[u.Scheme]
if sinkURLFactoryFunc == nil {
return nil, fmt.Errorf(
"cannot create metric sink, unrecognized sink name: %q", u.Scheme)
}
return sinkURLFactoryFunc(u)
}

17
vendor/github.com/armon/go-metrics/start.go generated vendored Executable file → Normal file
View File

@ -26,10 +26,11 @@ type Metrics struct {
} }
// Shared global metrics instance // Shared global metrics instance
var global atomic.Value var globalMetrics atomic.Value // *Metrics
func init() { func init() {
global.Store(&Metrics{sink: &BlackholeSink{}}) // Initialize to a blackhole sink to avoid errors
globalMetrics.Store(&Metrics{sink: &BlackholeSink{}})
} }
// DefaultConfig provides a sane default configuration // DefaultConfig provides a sane default configuration
@ -68,28 +69,28 @@ func New(conf *Config, sink MetricSink) (*Metrics, error) {
func NewGlobal(conf *Config, sink MetricSink) (*Metrics, error) { func NewGlobal(conf *Config, sink MetricSink) (*Metrics, error) {
metrics, err := New(conf, sink) metrics, err := New(conf, sink)
if err == nil { if err == nil {
global.Store(metrics) globalMetrics.Store(metrics)
} }
return metrics, err return metrics, err
} }
// Proxy all the methods to the globalMetrics instance // Proxy all the methods to the globalMetrics instance
func SetGauge(key []string, val float32) { func SetGauge(key []string, val float32) {
global.Load().(*Metrics).SetGauge(key, val) globalMetrics.Load().(*Metrics).SetGauge(key, val)
} }
func EmitKey(key []string, val float32) { func EmitKey(key []string, val float32) {
global.Load().(*Metrics).EmitKey(key, val) globalMetrics.Load().(*Metrics).EmitKey(key, val)
} }
func IncrCounter(key []string, val float32) { func IncrCounter(key []string, val float32) {
global.Load().(*Metrics).IncrCounter(key, val) globalMetrics.Load().(*Metrics).IncrCounter(key, val)
} }
func AddSample(key []string, val float32) { func AddSample(key []string, val float32) {
global.Load().(*Metrics).AddSample(key, val) globalMetrics.Load().(*Metrics).AddSample(key, val)
} }
func MeasureSince(key []string, start time.Time) { func MeasureSince(key []string, start time.Time) {
global.Load().(*Metrics).MeasureSince(key, start) globalMetrics.Load().(*Metrics).MeasureSince(key, start)
} }

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"log" "log"
"net" "net"
"net/url"
"strings" "strings"
"time" "time"
) )
@ -23,6 +24,12 @@ type StatsdSink struct {
metricQueue chan string metricQueue chan string
} }
// NewStatsdSinkFromURL creates an StatsdSink from a URL. It is used
// (and tested) from NewMetricSinkFromURL.
func NewStatsdSinkFromURL(u *url.URL) (MetricSink, error) {
return NewStatsdSink(u.Host)
}
// NewStatsdSink is used to create a new StatsdSink // NewStatsdSink is used to create a new StatsdSink
func NewStatsdSink(addr string) (*StatsdSink, error) { func NewStatsdSink(addr string) (*StatsdSink, error) {
s := &StatsdSink{ s := &StatsdSink{

7
vendor/github.com/armon/go-metrics/statsite.go generated vendored Executable file → Normal file
View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"log" "log"
"net" "net"
"net/url"
"strings" "strings"
"time" "time"
) )
@ -16,6 +17,12 @@ const (
flushInterval = 100 * time.Millisecond flushInterval = 100 * time.Millisecond
) )
// NewStatsiteSinkFromURL creates an StatsiteSink from a URL. It is used
// (and tested) from NewMetricSinkFromURL.
func NewStatsiteSinkFromURL(u *url.URL) (MetricSink, error) {
return NewStatsiteSink(u.Host)
}
// StatsiteSink provides a MetricSink that can be used with a // StatsiteSink provides a MetricSink that can be used with a
// statsite metrics server // statsite metrics server
type StatsiteSink struct { type StatsiteSink struct {

6
vendor/vendor.json vendored
View File

@ -87,10 +87,10 @@
"revisionTime": "2015-08-27T00:49:46Z" "revisionTime": "2015-08-27T00:49:46Z"
}, },
{ {
"checksumSHA1": "d6798KSc0jDg2MHNxKdgyNfMK7A=", "checksumSHA1": "M+ZeYktTT2wak9ZvQ0OZBbIHAGo=",
"path": "github.com/armon/go-metrics", "path": "github.com/armon/go-metrics",
"revision": "3df31a1ada83e310c2e24b267c8e8b68836547b4", "revision": "f036747b9d0e8590f175a5d654a2194a7d9df4b5",
"revisionTime": "2016-07-17T04:34:58Z" "revisionTime": "2017-06-01T21:44:32Z"
}, },
{ {
"checksumSHA1": "OmqT9Y1mAHvlAKeJh0jBHC9SH78=", "checksumSHA1": "OmqT9Y1mAHvlAKeJh0jBHC9SH78=",