@@ -193,10 +193,7 @@ func newTimeBucketWatchers(clock clock.Clock) *watcherBookmarkTimeBuckets {
193
193
// adds a watcher to the bucket, if the deadline is before the start, it will be
194
194
// added to the first one.
195
195
func (t * watcherBookmarkTimeBuckets ) addWatcher (w * cacheWatcher ) bool {
196
- nextTime , ok := w .nextBookmarkTime (t .clock .Now ())
197
- if ! ok {
198
- return false
199
- }
196
+ nextTime := w .nextBookmarkTime (t .clock .Now ())
200
197
bucketID := nextTime .Unix ()
201
198
t .lock .Lock ()
202
199
defer t .lock .Unlock ()
@@ -1240,13 +1237,26 @@ func (c *cacheWatcher) add(event *watchCacheEvent, timer *time.Timer) bool {
1240
1237
}
1241
1238
}
1242
1239
1243
- func (c * cacheWatcher ) nextBookmarkTime (now time.Time ) (time.Time , bool ) {
1244
- // For now we return 2s before deadline (and maybe +infinity is now already passed this time)
1245
- // but it gives us extensibility for the future(false when deadline is not set).
1240
+ // bookmarkHeartbeatFrequency defines how frequently bookmarks should be
1241
+ // under regular conditions.
1242
+ const bookmarkHeartbeatFrequency = time .Minute
1243
+
1244
+ func (c * cacheWatcher ) nextBookmarkTime (now time.Time ) time.Time {
1245
+ // We try to send bookmarks:
1246
+ // (a) roughly every minute
1247
+ // (b) right before the watcher timeout - for now we simply set it 2s before
1248
+ // the deadline
1249
+ // The former gives us periodicity if the watch breaks due to unexpected
1250
+ // conditions, the later ensures that on timeout the watcher is as close to
1251
+ // now as possible - this covers 99% of cases.
1252
+ heartbeatTime := now .Add (bookmarkHeartbeatFrequency )
1246
1253
if c .deadline .IsZero () {
1247
- return c .deadline , false
1254
+ return heartbeatTime
1255
+ }
1256
+ if pretimeoutTime := c .deadline .Add (- 2 * time .Second ); pretimeoutTime .Before (heartbeatTime ) {
1257
+ return pretimeoutTime
1248
1258
}
1249
- return c . deadline . Add ( - 2 * time . Second ), true
1259
+ return heartbeatTime
1250
1260
}
1251
1261
1252
1262
func getEventObject (object runtime.Object ) runtime.Object {
0 commit comments