in src/shippers/elastic_v3/server/src/server_shipper.ts [195:238]
private checkConnectivity() {
let backoff = 1 * MINUTE;
merge(
timer(0, 1 * MINUTE),
// Also react to opt-in changes to avoid being stalled for 1 minute for the first connectivity check.
// More details in: https://github.com/elastic/kibana/issues/135647
this.isOptedIn$
)
.pipe(
takeUntil(this.shutdown$),
filter(() => this.isOptedIn$.value === true && this.firstTimeOffline !== null),
// Using exhaustMap here because one request at a time is enough to check the connectivity.
exhaustMap(async () => {
const { ok } = await fetch(this.url, {
method: 'OPTIONS',
});
if (!ok) {
throw new Error(`Failed to connect to ${this.url}`);
}
this.firstTimeOffline = null;
backoff = 1 * MINUTE;
}),
retryWhen((errors) =>
errors.pipe(
takeUntil(this.shutdown$),
tap(() => {
if (!this.firstTimeOffline) {
this.firstTimeOffline = Date.now();
} else if (Date.now() - this.firstTimeOffline > 24 * HOUR) {
this.internalQueue.length = 0;
}
backoff = backoff * 2;
if (backoff > 1 * HOUR) {
backoff = 1 * HOUR;
}
}),
delayWhen(() => timer(backoff))
)
)
)
.subscribe();
}