From d7c99c901a8cc98aec7e41bda225ec41d3c81f7c Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Wed, 9 Sep 2020 11:26:23 +0800 Subject: [PATCH 1/4] Fix: app/stats.Manager does not implement features/stats.Manager (#171) --- 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 7bb56b28..ce9e3692 100644 --- a/app/stats/stats.go +++ b/app/stats/stats.go @@ -126,6 +126,18 @@ func (m *Manager) RegisterCounter(name string) (stats.Counter, error) { return c, nil } +// UnregisterCounter implements stats.Manager. +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 +} + // GetCounter implements stats.Manager. func (m *Manager) GetCounter(name string) stats.Counter { m.access.RLock() diff --git a/features/stats/stats.go b/features/stats/stats.go index 2a0acec2..6ac0da26 100644 --- a/features/stats/stats.go +++ b/features/stats/stats.go @@ -38,6 +38,7 @@ type Manager interface { // RegisterCounter registers a new counter to the manager. The identifier string must not be empty, and unique among other counters. RegisterCounter(string) (Counter, error) + UnregisterCounter(string) error // GetCounter returns a counter by its identifier. GetCounter(string) Counter @@ -87,6 +88,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 From 0406cd896bd91e4ed596bab6fca6bb17b640decf Mon Sep 17 00:00:00 2001 From: Vigilans Date: Wed, 9 Sep 2020 11:33:29 +0800 Subject: [PATCH 2/4] Add UnregisterChannel & Modify unregistering logic --- app/stats/stats.go | 20 ++++++++++++++++---- features/stats/stats.go | 10 +++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/stats/stats.go b/app/stats/stats.go index ce9e3692..7e2122df 100644 --- a/app/stats/stats.go +++ b/app/stats/stats.go @@ -130,11 +130,11 @@ func (m *Manager) RegisterCounter(name string) (stats.Counter, error) { 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.") + + if _, found := m.counters[name]; found { + newError("remove counter ", name).AtDebug().WriteToLog() + delete(m.counters, name) } - newError("remove counter ", name).AtDebug().WriteToLog() - delete(m.counters, name) return nil } @@ -176,6 +176,18 @@ func (m *Manager) RegisterChannel(name string) (stats.Channel, error) { return c, nil } +// UnregisterChannel implements stats.Manager. +func (m *Manager) UnregisterChannel(name string) error { + m.access.Lock() + defer m.access.Unlock() + + if _, found := m.channels[name]; found { + newError("remove channel ", name).AtDebug().WriteToLog() + delete(m.channels, name) + } + return nil +} + // GetChannel implements stats.Manager. func (m *Manager) GetChannel(name string) stats.Channel { m.access.RLock() diff --git a/features/stats/stats.go b/features/stats/stats.go index 6ac0da26..a27b441c 100644 --- a/features/stats/stats.go +++ b/features/stats/stats.go @@ -38,12 +38,15 @@ type Manager interface { // RegisterCounter registers a new counter to the manager. The identifier string must not be empty, and unique among other counters. RegisterCounter(string) (Counter, error) + // UnregisterCounter unregisters a counter from the manager by its identifier. UnregisterCounter(string) error // GetCounter returns a counter by its identifier. GetCounter(string) Counter // RegisterChannel registers a new channel to the manager. The identifier string must not be empty, and unique among other channels. RegisterChannel(string) (Channel, error) + // UnregisterCounter unregisters a channel from the manager by its identifier. + UnregisterChannel(string) error // GetChannel returns a channel by its identifier. GetChannel(string) Channel } @@ -90,7 +93,7 @@ func (NoopManager) RegisterCounter(string) (Counter, error) { // UnregisterCounter implements Manager. func (NoopManager) UnregisterCounter(string) error { - return newError("not implemented") + return nil } // GetCounter implements Manager. @@ -103,6 +106,11 @@ func (NoopManager) RegisterChannel(string) (Channel, error) { return nil, newError("not implemented") } +// UnregisterChannel implements Manager. +func (NoopManager) UnregisterChannel(string) error { + return nil +} + // GetChannel implements Manager. func (NoopManager) GetChannel(string) Channel { return nil From c4d46e776f76e9ee65f4fd3aab5b7dab689ce218 Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Wed, 9 Sep 2020 13:56:17 +0800 Subject: [PATCH 3/4] Test: run on changes to go.mod & go.sum (#174) --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cc6f0617..e8faea1b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,11 +5,15 @@ on: branches: [master] paths: - "**/*.go" + - "go.mod" + - "go.sum" pull_request: branches: [master] types: [opened, synchronize, reopened] paths: - "**/*.go" + - "go.mod" + - "go.sum" jobs: test: From cc25eb12f49043f97121b6572079a9037ab2bc97 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Sep 2020 05:59:40 +0000 Subject: [PATCH 4/4] Bump google.golang.org/grpc from 1.31.1 to 1.32.0 Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.31.1 to 1.32.0. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.31.1...v1.32.0) Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 61a94558..be3148b1 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( golang.org/x/net v0.0.0-20200822124328-c89045814202 golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a - google.golang.org/grpc v1.31.1 + google.golang.org/grpc v1.32.0 google.golang.org/protobuf v1.25.0 h12.io/socks v1.0.1 ) diff --git a/go.sum b/go.sum index 8c4942a7..32160f70 100644 --- a/go.sum +++ b/go.sum @@ -116,6 +116,8 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.31.1 h1:SfXqXS5hkufcdZ/mHtYCh53P2b+92WQq/DZcKLgsFRs= google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0= +google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=