Moved to google.golang.org/genproto/googleapis/api/annotations
Fixes #52
This commit is contained in:
86
vendor/github.com/go-kit/kit/metrics/multi/multi.go
generated
vendored
Normal file
86
vendor/github.com/go-kit/kit/metrics/multi/multi.go
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
// Package multi provides adapters that send observations to multiple metrics
|
||||
// simultaneously. This is useful if your service needs to emit to multiple
|
||||
// instrumentation systems at the same time, for example if your organization is
|
||||
// transitioning from one system to another.
|
||||
package multi
|
||||
|
||||
import "github.com/go-kit/kit/metrics"
|
||||
|
||||
// Counter collects multiple individual counters and treats them as a unit.
|
||||
type Counter []metrics.Counter
|
||||
|
||||
// NewCounter returns a multi-counter, wrapping the passed counters.
|
||||
func NewCounter(c ...metrics.Counter) Counter {
|
||||
return Counter(c)
|
||||
}
|
||||
|
||||
// Add implements counter.
|
||||
func (c Counter) Add(delta float64) {
|
||||
for _, counter := range c {
|
||||
counter.Add(delta)
|
||||
}
|
||||
}
|
||||
|
||||
// With implements counter.
|
||||
func (c Counter) With(labelValues ...string) metrics.Counter {
|
||||
next := make(Counter, len(c))
|
||||
for i := range c {
|
||||
next[i] = c[i].With(labelValues...)
|
||||
}
|
||||
return next
|
||||
}
|
||||
|
||||
// Gauge collects multiple individual gauges and treats them as a unit.
|
||||
type Gauge []metrics.Gauge
|
||||
|
||||
// NewGauge returns a multi-gauge, wrapping the passed gauges.
|
||||
func NewGauge(g ...metrics.Gauge) Gauge {
|
||||
return Gauge(g)
|
||||
}
|
||||
|
||||
// Set implements Gauge.
|
||||
func (g Gauge) Set(value float64) {
|
||||
for _, gauge := range g {
|
||||
gauge.Set(value)
|
||||
}
|
||||
}
|
||||
|
||||
// With implements gauge.
|
||||
func (g Gauge) With(labelValues ...string) metrics.Gauge {
|
||||
next := make(Gauge, len(g))
|
||||
for i := range g {
|
||||
next[i] = g[i].With(labelValues...)
|
||||
}
|
||||
return next
|
||||
}
|
||||
|
||||
// Add implements metrics.Gauge.
|
||||
func (g Gauge) Add(delta float64) {
|
||||
for _, gauge := range g {
|
||||
gauge.Add(delta)
|
||||
}
|
||||
}
|
||||
|
||||
// Histogram collects multiple individual histograms and treats them as a unit.
|
||||
type Histogram []metrics.Histogram
|
||||
|
||||
// NewHistogram returns a multi-histogram, wrapping the passed histograms.
|
||||
func NewHistogram(h ...metrics.Histogram) Histogram {
|
||||
return Histogram(h)
|
||||
}
|
||||
|
||||
// Observe implements Histogram.
|
||||
func (h Histogram) Observe(value float64) {
|
||||
for _, histogram := range h {
|
||||
histogram.Observe(value)
|
||||
}
|
||||
}
|
||||
|
||||
// With implements histogram.
|
||||
func (h Histogram) With(labelValues ...string) metrics.Histogram {
|
||||
next := make(Histogram, len(h))
|
||||
for i := range h {
|
||||
next[i] = h[i].With(labelValues...)
|
||||
}
|
||||
return next
|
||||
}
|
96
vendor/github.com/go-kit/kit/metrics/multi/multi_test.go
generated
vendored
Normal file
96
vendor/github.com/go-kit/kit/metrics/multi/multi_test.go
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
package multi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/go-kit/kit/metrics"
|
||||
)
|
||||
|
||||
func TestMultiCounter(t *testing.T) {
|
||||
c1 := &mockCounter{}
|
||||
c2 := &mockCounter{}
|
||||
c3 := &mockCounter{}
|
||||
mc := NewCounter(c1, c2, c3)
|
||||
|
||||
mc.Add(123)
|
||||
mc.Add(456)
|
||||
|
||||
want := "[123 456]"
|
||||
for i, m := range []fmt.Stringer{c1, c2, c3} {
|
||||
if have := m.String(); want != have {
|
||||
t.Errorf("c%d: want %q, have %q", i+1, want, have)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiGauge(t *testing.T) {
|
||||
g1 := &mockGauge{}
|
||||
g2 := &mockGauge{}
|
||||
g3 := &mockGauge{}
|
||||
mg := NewGauge(g1, g2, g3)
|
||||
|
||||
mg.Set(9)
|
||||
mg.Set(8)
|
||||
mg.Set(7)
|
||||
mg.Add(3)
|
||||
|
||||
want := "[9 8 7 10]"
|
||||
for i, m := range []fmt.Stringer{g1, g2, g3} {
|
||||
if have := m.String(); want != have {
|
||||
t.Errorf("g%d: want %q, have %q", i+1, want, have)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiHistogram(t *testing.T) {
|
||||
h1 := &mockHistogram{}
|
||||
h2 := &mockHistogram{}
|
||||
h3 := &mockHistogram{}
|
||||
mh := NewHistogram(h1, h2, h3)
|
||||
|
||||
mh.Observe(1)
|
||||
mh.Observe(2)
|
||||
mh.Observe(4)
|
||||
mh.Observe(8)
|
||||
|
||||
want := "[1 2 4 8]"
|
||||
for i, m := range []fmt.Stringer{h1, h2, h3} {
|
||||
if have := m.String(); want != have {
|
||||
t.Errorf("g%d: want %q, have %q", i+1, want, have)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type mockCounter struct {
|
||||
obs []float64
|
||||
}
|
||||
|
||||
func (c *mockCounter) Add(delta float64) { c.obs = append(c.obs, delta) }
|
||||
func (c *mockCounter) With(...string) metrics.Counter { return c }
|
||||
func (c *mockCounter) String() string { return fmt.Sprintf("%v", c.obs) }
|
||||
|
||||
type mockGauge struct {
|
||||
obs []float64
|
||||
}
|
||||
|
||||
func (g *mockGauge) Set(value float64) { g.obs = append(g.obs, value) }
|
||||
func (g *mockGauge) With(...string) metrics.Gauge { return g }
|
||||
func (g *mockGauge) String() string { return fmt.Sprintf("%v", g.obs) }
|
||||
func (g *mockGauge) Add(delta float64) {
|
||||
var value float64
|
||||
if len(g.obs) > 0 {
|
||||
value = g.obs[len(g.obs)-1] + delta
|
||||
} else {
|
||||
value = delta
|
||||
}
|
||||
g.obs = append(g.obs, value)
|
||||
}
|
||||
|
||||
type mockHistogram struct {
|
||||
obs []float64
|
||||
}
|
||||
|
||||
func (h *mockHistogram) Observe(value float64) { h.obs = append(h.obs, value) }
|
||||
func (h *mockHistogram) With(...string) metrics.Histogram { return h }
|
||||
func (h *mockHistogram) String() string { return fmt.Sprintf("%v", h.obs) }
|
Reference in New Issue
Block a user