From 7009a2e0d34441ed6a7023bb56e62e8b779cecaa Mon Sep 17 00:00:00 2001 From: Readper Tsai Date: Wed, 26 Jun 2019 02:15:16 +0800 Subject: [PATCH 1/2] [Misc] Add option to remove annoying logs --- client.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 173f038..9ec0037 100644 --- a/client.go +++ b/client.go @@ -81,6 +81,14 @@ func Stat(counter stats.Client) func(*clientImpl) error { } } +// NoMatchingLogs skip matching logs +func NoMatchingLogs() func(*clientImpl) error { + return func(c *clientImpl) error { + c.noMatchingLogs = true + return nil + } +} + // watchRetryTime defines the retry number of watch var watchRetryTime = flag.Uint("csi_config_client_etcd_retry", uint(5), "etcd watch failed retry times, 0 for unlimited retry") @@ -107,8 +115,9 @@ type clientImpl struct { // listers is a map from path to all listers. listers map[string]*lister // listerLock protects listers - listerLock sync.Mutex - stopCh chan bool + listerLock sync.Mutex + stopCh chan bool + noMatchingLogs bool } // init start monitoring the config file @@ -361,7 +370,9 @@ func (c *clientImpl) fireFileChangeEvent(info *ConfigInfo) { for _, regch := range listeners { for _, f := range info.ModFiles { - logrus.Infof("Matching listener <%v> vs file <%v>", regch, f) + if !c.noMatchingLogs { + logrus.Infof("Matching listener <%v> vs file <%v>", regch, f) + } if regch.regex.Match([]byte(f.Path)) { logrus.Infof("Matched listener <%v> vs file <%v>", regch, f) *regch.ch <- f From c82ba721b27c376d48dc347b23bec4a254c6f2d1 Mon Sep 17 00:00:00 2001 From: Readper Tsai Date: Wed, 26 Jun 2019 02:26:39 +0800 Subject: [PATCH 2/2] reduce more logs --- client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client.go b/client.go index 9ec0037..069cb9e 100644 --- a/client.go +++ b/client.go @@ -192,6 +192,9 @@ func (c *clientImpl) loop(infoPath string, initErr chan error) { // empty cache for _, f := range info.ModFiles { + if _, ok := c.cache[f.Path]; !ok { + continue + } logrus.Infof("delete %v from cache", f.Path) c.cacheLock.Lock() delete(c.cache, f.Path) @@ -376,6 +379,7 @@ func (c *clientImpl) fireFileChangeEvent(info *ConfigInfo) { if regch.regex.Match([]byte(f.Path)) { logrus.Infof("Matched listener <%v> vs file <%v>", regch, f) *regch.ch <- f + break } } }