mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[EBT] Explicit empty-array check to avoid HTTP requests (#135638)
This commit is contained in:
parent
789e2e9ceb
commit
c3371d4308
1 changed files with 11 additions and 6 deletions
|
@ -21,6 +21,7 @@ import {
|
|||
tap,
|
||||
delayWhen,
|
||||
takeUntil,
|
||||
map,
|
||||
} from 'rxjs';
|
||||
import type {
|
||||
AnalyticsClientInitContext,
|
||||
|
@ -227,16 +228,20 @@ export class ElasticV3ServerShipper implements IShipper {
|
|||
(this.internalQueue.length > 0 &&
|
||||
(this.shutdown$.isStopped || Date.now() - this.lastBatchSent >= 10 * MINUTE)) ||
|
||||
(Date.now() - this.lastBatchSent >= 10 * SECOND &&
|
||||
(this.internalQueue.length === 1000 ||
|
||||
(this.internalQueue.length === MAX_NUMBER_OF_EVENTS_IN_INTERNAL_QUEUE ||
|
||||
this.getQueueByteSize(this.internalQueue) >= 10 * KIB))
|
||||
),
|
||||
|
||||
// Send the events
|
||||
concatMap(async () => {
|
||||
// Send the events:
|
||||
// 1. Set lastBatchSent and retrieve the events to send (clearing the queue) in a synchronous operation to avoid race conditions.
|
||||
map(() => {
|
||||
this.lastBatchSent = Date.now();
|
||||
const eventsToSend = this.getEventsToSend();
|
||||
await this.sendEvents(eventsToSend);
|
||||
})
|
||||
return this.getEventsToSend();
|
||||
}),
|
||||
// 2. Skip empty buffers
|
||||
filter((events) => events.length > 0),
|
||||
// 3. Actually send the events
|
||||
concatMap(async (eventsToSend) => await this.sendEvents(eventsToSend))
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue