From 86d5bd866b3d1efcc4f0e2a9d2737d5693bbabb3 Mon Sep 17 00:00:00 2001 From: remote-v2ray Date: Mon, 3 Feb 2020 13:53:14 +0800 Subject: [PATCH] add UnregisterCounter method to stats manager --- app/stats/stats.go | 12 ++++++++++++ features/stats/stats.go | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/app/stats/stats.go b/app/stats/stats.go index d06cc39c..c7f58831 100644 --- a/app/stats/stats.go +++ b/app/stats/stats.go @@ -63,6 +63,18 @@ func (m *Manager) RegisterCounter(name string) (stats.Counter, error) { return c, nil } +func (m *Manager) UnregisterCounter(name string) error { + m.access.Lock() + defer m.access.Unlock() + + if _, found := m.counters[name]; !found { + return newError("Counter ", name, " was not found.") + } + newError("remove counter ", name).AtDebug().WriteToLog() + delete(m.counters, name) + return nil +} + func (m *Manager) GetCounter(name string) stats.Counter { m.access.RLock() defer m.access.RUnlock() diff --git a/features/stats/stats.go b/features/stats/stats.go index fed80eb8..267416e6 100644 --- a/features/stats/stats.go +++ b/features/stats/stats.go @@ -24,6 +24,7 @@ type Manager interface { // RegisterCounter registers a new counter to the manager. The identifier string must not be emtpy, and unique among other counters. RegisterCounter(string) (Counter, error) + UnregisterCounter(string) error // GetCounter returns a counter by its identifier. GetCounter(string) Counter } @@ -58,6 +59,11 @@ func (NoopManager) RegisterCounter(string) (Counter, error) { return nil, newError("not implemented") } +// UnregisterCounter implements Manager. +func (NoopManager) UnregisterCounter(string) error { + return newError("not implemented") +} + // GetCounter implements Manager. func (NoopManager) GetCounter(string) Counter { return nil