Skip to content

Commit

Permalink
scopes: fix bug with tag inheritance. (#45)
Browse files Browse the repository at this point in the history
A new untagged scope did not correctly inherit its parents tags.
  • Loading branch information
diegs authored Oct 2, 2018
1 parent acc84a6 commit 7054f86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func (s *statStore) NewPerInstanceTimer(name string, tags map[string]string) Tim
}

func (s subScope) Scope(name string) Scope {
return &subScope{registry: s.registry, name: fmt.Sprintf("%s.%s", s.name, name)}
return s.ScopeWithTags(name, nil)
}

func (s subScope) ScopeWithTags(name string, tags map[string]string) Scope {
Expand Down
11 changes: 6 additions & 5 deletions tcp_sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,16 @@ func TestScopesWithTags(t *testing.T) {

ascope := store.ScopeWithTags("a", map[string]string{"x": "a", "y": "a"})
bscope := ascope.ScopeWithTags("b", map[string]string{"x": "b", "z": "b"})
counter := bscope.NewCounter("c")
dscope := bscope.Scope("d")
counter := dscope.NewCounter("c")
counter.Inc()
timer := bscope.NewTimer("t")
timer := dscope.NewTimer("t")
timer.AddValue(1)
gauge := bscope.NewGauge("g")
gauge := dscope.NewGauge("g")
gauge.Set(1)
store.Flush()

expected := "a.b.t.__x=b.__y=a.__z=b:1.000000|ms\na.b.c.__x=b.__y=a.__z=b:1|c\na.b.g.__x=b.__y=a.__z=b:1|g\n"
expected := "a.b.d.t.__x=b.__y=a.__z=b:1.000000|ms\na.b.d.c.__x=b.__y=a.__z=b:1|c\na.b.d.g.__x=b.__y=a.__z=b:1|g\n"
if expected != sink.record {
t.Errorf("Expected: '%s' Got: '%s'", expected, sink.record)
}
Expand All @@ -321,7 +322,7 @@ func TestScopesAndMetricsWithTags(t *testing.T) {
gauge.Set(1)
store.Flush()

expected := "a.b.t.__x=m.__z=m:1.000000|ms\na.b.c.__x=m.__z=m:1|c\na.b.g.__x=m.__z=m:1|g\n"
expected := "a.b.t.__x=m.__y=a.__z=m:1.000000|ms\na.b.c.__x=m.__y=a.__z=m:1|c\na.b.g.__x=m.__y=a.__z=m:1|g\n"
if expected != sink.record {
t.Errorf("Expected: '%s' Got: '%s'", expected, sink.record)
}
Expand Down

0 comments on commit 7054f86

Please sign in to comment.