Skip to content

Commit a6cebee

Browse files
committed
Add verbosity to watch logs
1 parent 3e088d4 commit a6cebee

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

pkg/engine/watchermanager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ func (r *watcherManager) WatchPackageRevisions(ctx context.Context, filter repos
8181
r.watchers[i] = w
8282
inserted = true
8383
active += 1
84-
klog.Infof("watcher %p finished with: %v and is replaced by watcher %p", watcher, err, w)
84+
klog.V(3).Infof("watcher %p finished with: %v and is replaced by watcher %p", watcher, err, w)
8585
} else {
8686
r.watchers[i] = nil
87-
klog.Infof("watcher %p finished with: %v and is removed", watcher, err)
87+
klog.V(3).Infof("watcher %p finished with: %v and is removed", watcher, err)
8888
}
8989
} else {
9090
active += 1
@@ -102,7 +102,7 @@ func (r *watcherManager) WatchPackageRevisions(ctx context.Context, filter repos
102102
r.watchers = append(r.watchers, w)
103103
}
104104

105-
klog.Infof("added watcher %p; there are now %d active watchers and %d slots", w, active, len(r.watchers))
105+
klog.V(3).Infof("added watcher %p; there are now %d active watchers and %d slots", w, active, len(r.watchers))
106106
return nil
107107
}
108108

pkg/registry/porch/watch.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package porch
1717
import (
1818
"context"
1919
"fmt"
20+
"regexp"
2021
"sync"
2122

2223
"github.com/nephio-project/porch/pkg/engine"
@@ -97,10 +98,16 @@ type packageReader interface {
9798
// listAndWatch implements watch by doing a list, then sending any observed changes.
9899
// This is not a compliant implementation of watch, but it is a good-enough start for most controllers.
99100
// One trick is that we start the watch _before_ we perform the list, so we don't miss changes that happen immediately after the list.
101+
var contextErrorRegex = regexp.MustCompile(`context (deadline exceeded|canceled)`)
102+
100103
func (w *watcher) listAndWatch(ctx context.Context, r packageReader, filter repository.ListPackageRevisionFilter) {
101104
if err := w.listAndWatchInner(ctx, r, filter); err != nil {
102105
// TODO: We need to populate the object on this error
103-
klog.Warningf("sending error to watch stream: %v", err)
106+
if contextErrorRegex.MatchString(err.Error()) {
107+
klog.V(3).Infof("sending error to watch stream: %v", err)
108+
} else {
109+
klog.Warningf("sending error to watch stream: %v", err)
110+
}
104111
ev := watch.Event{
105112
Type: watch.Error,
106113
}
@@ -195,7 +202,7 @@ func (w *watcher) listAndWatchInner(ctx context.Context, r packageReader, filter
195202
w.sendWatchEvent(ev)
196203
}
197204

198-
klog.Infof("watch %p: moving watch into streaming mode after sentAdd %d, sentBacklog %d, sentNewBacklog %d", w, sentAdd, sentBacklog, sentNewBacklog)
205+
klog.V(3).Infof("watch %p: moving watch into streaming mode after sentAdd %d, sentBacklog %d, sentNewBacklog %d", w, sentAdd, sentBacklog, sentNewBacklog)
199206
w.eventCallback = func(eventType watch.EventType, pr repository.PackageRevision) bool {
200207
if w.done {
201208
return false

0 commit comments

Comments
 (0)