Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics/generic: With should track Name #459

Merged
merged 1 commit into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions metrics/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func NewCounter(name string) *Counter {
// With implements Counter.
func (c *Counter) With(labelValues ...string) metrics.Counter {
return &Counter{
Name: c.Name,
bits: atomic.LoadUint64(&c.bits),
lvs: c.lvs.With(labelValues...),
}
Expand Down Expand Up @@ -95,6 +96,7 @@ func NewGauge(name string) *Gauge {
// With implements Gauge.
func (g *Gauge) With(labelValues ...string) metrics.Gauge {
return &Gauge{
Name: g.Name,
bits: atomic.LoadUint64(&g.bits),
lvs: g.lvs.With(labelValues...),
}
Expand Down Expand Up @@ -150,8 +152,9 @@ func NewHistogram(name string, buckets int) *Histogram {
// With implements Histogram.
func (h *Histogram) With(labelValues ...string) metrics.Histogram {
return &Histogram{
lvs: h.lvs.With(labelValues...),
h: h.h,
Name: h.Name,
lvs: h.lvs.With(labelValues...),
h: h.h,
}
}

Expand Down
18 changes: 15 additions & 3 deletions metrics/generic/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import (
)

func TestCounter(t *testing.T) {
counter := generic.NewCounter("my_counter").With("label", "counter").(*generic.Counter)
name := "my_counter"
counter := generic.NewCounter(name).With("label", "counter").(*generic.Counter)
if want, have := name, counter.Name; want != have {
t.Errorf("Name: want %q, have %q", want, have)
}
value := func() float64 { return counter.Value() }
if err := teststat.TestCounter(counter, value); err != nil {
t.Fatal(err)
Expand All @@ -36,15 +40,23 @@ func TestValueReset(t *testing.T) {
}

func TestGauge(t *testing.T) {
gauge := generic.NewGauge("my_gauge").With("label", "gauge").(*generic.Gauge)
name := "my_gauge"
gauge := generic.NewGauge(name).With("label", "gauge").(*generic.Gauge)
if want, have := name, gauge.Name; want != have {
t.Errorf("Name: want %q, have %q", want, have)
}
value := func() float64 { return gauge.Value() }
if err := teststat.TestGauge(gauge, value); err != nil {
t.Fatal(err)
}
}

func TestHistogram(t *testing.T) {
histogram := generic.NewHistogram("my_histogram", 50).With("label", "histogram").(*generic.Histogram)
name := "my_histogram"
histogram := generic.NewHistogram(name, 50).With("label", "histogram").(*generic.Histogram)
if want, have := name, histogram.Name; want != have {
t.Errorf("Name: want %q, have %q", want, have)
}
quantiles := func() (float64, float64, float64, float64) {
return histogram.Quantile(0.50), histogram.Quantile(0.90), histogram.Quantile(0.95), histogram.Quantile(0.99)
}
Expand Down