Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Misc] Add option to remove annoying logs #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
Expand Down Expand Up @@ -183,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)
Expand Down Expand Up @@ -361,10 +373,13 @@ 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
break
}
}
}
Expand Down