Package list golang-github-go-kit-kit / 839f598
metrics/generic: With should track Name Closes #455 Peter Bourgon 4 years ago
2 changed file(s) with 20 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
3232 // With implements Counter.
3333 func (c *Counter) With(labelValues ...string) metrics.Counter {
3434 return &Counter{
35 Name: c.Name,
3536 bits: atomic.LoadUint64(&c.bits),
3637 lvs: c.lvs.With(labelValues...),
3738 }
9495 // With implements Gauge.
9596 func (g *Gauge) With(labelValues ...string) metrics.Gauge {
9697 return &Gauge{
98 Name: g.Name,
9799 bits: atomic.LoadUint64(&g.bits),
98100 lvs: g.lvs.With(labelValues...),
99101 }
149151 // With implements Histogram.
150152 func (h *Histogram) With(labelValues ...string) metrics.Histogram {
151153 return &Histogram{
152 lvs: h.lvs.With(labelValues...),
153 h: h.h,
154 Name: h.Name,
155 lvs: h.lvs.With(labelValues...),
156 h: h.h,
154157 }
155158 }
156159
1414 )
1515
1616 func TestCounter(t *testing.T) {
17 counter := generic.NewCounter("my_counter").With("label", "counter").(*generic.Counter)
17 name := "my_counter"
18 counter := generic.NewCounter(name).With("label", "counter").(*generic.Counter)
19 if want, have := name, counter.Name; want != have {
20 t.Errorf("Name: want %q, have %q", want, have)
21 }
1822 value := func() float64 { return counter.Value() }
1923 if err := teststat.TestCounter(counter, value); err != nil {
2024 t.Fatal(err)
3539 }
3640
3741 func TestGauge(t *testing.T) {
38 gauge := generic.NewGauge("my_gauge").With("label", "gauge").(*generic.Gauge)
42 name := "my_gauge"
43 gauge := generic.NewGauge(name).With("label", "gauge").(*generic.Gauge)
44 if want, have := name, gauge.Name; want != have {
45 t.Errorf("Name: want %q, have %q", want, have)
46 }
3947 value := func() float64 { return gauge.Value() }
4048 if err := teststat.TestGauge(gauge, value); err != nil {
4149 t.Fatal(err)
4351 }
4452
4553 func TestHistogram(t *testing.T) {
46 histogram := generic.NewHistogram("my_histogram", 50).With("label", "histogram").(*generic.Histogram)
54 name := "my_histogram"
55 histogram := generic.NewHistogram(name, 50).With("label", "histogram").(*generic.Histogram)
56 if want, have := name, histogram.Name; want != have {
57 t.Errorf("Name: want %q, have %q", want, have)
58 }
4759 quantiles := func() (float64, float64, float64, float64) {
4860 return histogram.Quantile(0.50), histogram.Quantile(0.90), histogram.Quantile(0.95), histogram.Quantile(0.99)
4961 }