|
@@ -167,14 +167,28 @@ func NewPrefixedChildRegistry(parent Registry, prefix string) Registry {
|
|
|
|
|
|
|
|
// Call the given function for each registered metric.
|
|
// Call the given function for each registered metric.
|
|
|
func (r *PrefixedRegistry) Each(fn func(string, interface{})) {
|
|
func (r *PrefixedRegistry) Each(fn func(string, interface{})) {
|
|
|
- wrappedFn := func(name string, iface interface{}) {
|
|
|
|
|
- if strings.HasPrefix(name, r.prefix) {
|
|
|
|
|
- fn(name, iface)
|
|
|
|
|
- } else {
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ wrappedFn := func (prefix string) func(string, interface{}) {
|
|
|
|
|
+ return func(name string, iface interface{}) {
|
|
|
|
|
+ if strings.HasPrefix(name,prefix) {
|
|
|
|
|
+ fn(name, iface)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- r.underlying.Each(wrappedFn)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ baseRegistry, prefix := walkRegistries(r, "")
|
|
|
|
|
+ baseRegistry.Each(wrappedFn(prefix))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func walkRegistries(registry Registry, prefix string) (Registry, string) {
|
|
|
|
|
+ switch r := registry.(type) {
|
|
|
|
|
+ case *PrefixedRegistry:
|
|
|
|
|
+ return walkRegistries(r.underlying, r.prefix + prefix)
|
|
|
|
|
+ case *StandardRegistry:
|
|
|
|
|
+ return r, prefix
|
|
|
|
|
+ }
|
|
|
|
|
+ return nil, ""
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Get the metric by the given name or nil if none is registered.
|
|
// Get the metric by the given name or nil if none is registered.
|