@@ -171,10 +171,7 @@ func newTimeBucketWatchers(clock clock.Clock) *watcherBookmarkTimeBuckets {
171
171
// adds a watcher to the bucket, if the deadline is before the start, it will be
172
172
// added to the first one.
173
173
func (t * watcherBookmarkTimeBuckets ) addWatcher (w * cacheWatcher ) bool {
174
- nextTime , ok := w .nextBookmarkTime (t .clock .Now ())
175
- if ! ok {
176
- return false
177
- }
174
+ nextTime := w .nextBookmarkTime (t .clock .Now ())
178
175
bucketID := nextTime .Unix ()
179
176
t .lock .Lock ()
180
177
defer t .lock .Unlock ()
@@ -1219,13 +1216,26 @@ func (c *cacheWatcher) add(event *watchCacheEvent, timer *time.Timer) bool {
1219
1216
}
1220
1217
}
1221
1218
1222
- func (c * cacheWatcher ) nextBookmarkTime (now time.Time ) (time.Time , bool ) {
1223
- // For now we return 2s before deadline (and maybe +infinity is now already passed this time)
1224
- // but it gives us extensibility for the future(false when deadline is not set).
1219
+ // bookmarkHeartbeatFrequency defines how frequently bookmarks should be
1220
+ // under regular conditions.
1221
+ const bookmarkHeartbeatFrequency = time .Minute
1222
+
1223
+ func (c * cacheWatcher ) nextBookmarkTime (now time.Time ) time.Time {
1224
+ // We try to send bookmarks:
1225
+ // (a) roughly every minute
1226
+ // (b) right before the watcher timeout - for now we simply set it 2s before
1227
+ // the deadline
1228
+ // The former gives us periodicity if the watch breaks due to unexpected
1229
+ // conditions, the later ensures that on timeout the watcher is as close to
1230
+ // now as possible - this covers 99% of cases.
1231
+ heartbeatTime := now .Add (bookmarkHeartbeatFrequency )
1225
1232
if c .deadline .IsZero () {
1226
- return c .deadline , false
1233
+ return heartbeatTime
1234
+ }
1235
+ if pretimeoutTime := c .deadline .Add (- 2 * time .Second ); pretimeoutTime .Before (heartbeatTime ) {
1236
+ return pretimeoutTime
1227
1237
}
1228
- return c . deadline . Add ( - 2 * time . Second ), true
1238
+ return heartbeatTime
1229
1239
}
1230
1240
1231
1241
func getEventObject (object runtime.Object ) runtime.Object {
0 commit comments