Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 7839c01

Browse files
committed
Merge pull request #136 from willglynn/prefixed_child_registry
Add NewPrefixedChildRegistry()
2 parents 9655675 + 33c33c5 commit 7839c01

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

registry.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ func NewPrefixedRegistry(prefix string) Registry {
157157
}
158158
}
159159

160+
func NewPrefixedChildRegistry(parent Registry, prefix string) Registry {
161+
return &PrefixedRegistry{
162+
underlying: parent,
163+
prefix: prefix,
164+
}
165+
}
166+
160167
// Call the given function for each registered metric.
161168
func (r *PrefixedRegistry) Each(fn func(string, interface{})) {
162169
r.underlying.Each(fn)

registry_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ func TestRegistryGetOrRegisterWithLazyInstantiation(t *testing.T) {
117117
}
118118
}
119119

120+
func TestPrefixedChildRegistryGetOrRegister(t *testing.T) {
121+
r := NewRegistry()
122+
pr := NewPrefixedChildRegistry(r, "prefix.")
123+
124+
_ = pr.GetOrRegister("foo", NewCounter)
125+
126+
r.Each(func(name string, m interface{}) {
127+
if name != "prefix.foo" {
128+
t.Fatal(name)
129+
}
130+
})
131+
}
132+
120133
func TestPrefixedRegistryGetOrRegister(t *testing.T) {
121134
r := NewPrefixedRegistry("prefix.")
122135

0 commit comments

Comments
 (0)