Skip to content

Commit 96b4ad8

Browse files
authored
Merge pull request #1656 from yue9944882/jittering-informer-client-timeout
Feat: Jittering informer client-side watch timeout between 5~10 minutes
2 parents 9b936f3 + 5dd7c0a commit 96b4ad8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

spring/src/main/java/io/kubernetes/client/spring/extended/controller/config/KubernetesInformerProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
@ConfigurationProperties("kubernetes.informer")
2020
public class KubernetesInformerProperties {
2121

22-
private Duration clientReadTimeout = ReflectorRunnable.REFLECTOR_WATCH_CLIENTSIDE_TIMEOUT;
22+
private Duration clientReadTimeout = ReflectorRunnable.REFLECTOR_WATCH_CLIENTSIDE_MAX_TIMEOUT;
2323

2424
public Duration getClientReadTimeout() {
2525
return clientReadTimeout;

util/src/main/java/io/kubernetes/client/informer/cache/ReflectorRunnable.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class ReflectorRunnable<
3939

4040
public static Duration REFLECTOR_WATCH_CLIENTSIDE_TIMEOUT = Duration.ofMinutes(5);
4141

42+
public static Duration REFLECTOR_WATCH_CLIENTSIDE_MAX_TIMEOUT = Duration.ofMinutes(5 * 2);
43+
4244
private static final Logger log = LoggerFactory.getLogger(ReflectorRunnable.class);
4345

4446
private String lastSyncResourceVersion;
@@ -110,12 +112,16 @@ public void run() {
110112
log.debug(
111113
"{}#Start watch with resource version {}", apiTypeClass, lastSyncResourceVersion);
112114
}
115+
116+
long jitteredWatchTimeoutSeconds =
117+
Double.valueOf(REFLECTOR_WATCH_CLIENTSIDE_TIMEOUT.getSeconds() * (1 + Math.random()))
118+
.longValue();
113119
Watchable<ApiType> newWatch =
114120
listerWatcher.watch(
115121
new CallGeneratorParams(
116122
Boolean.TRUE,
117123
lastSyncResourceVersion,
118-
Long.valueOf(REFLECTOR_WATCH_CLIENTSIDE_TIMEOUT.getSeconds()).intValue()));
124+
Long.valueOf(jitteredWatchTimeoutSeconds).intValue()));
119125

120126
synchronized (this) {
121127
if (!isActive.get()) {

0 commit comments

Comments
 (0)