/** * Copyright 2019 Splunk, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"): you may * not use this file except in compliance with the License. You may obtain * a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ interface HTTPResponse { code?: string; } interface IngestService { postEvents(buf?: Event[]): Promise; } interface Event { } /** * The default batch size for the EventBatcher. */ export declare const DEFAULT_BATCH_SIZE = 1040000; /** * The default batch count for the EventBatcher. */ export declare const DEFAULT_BATCH_COUNT = 500; /** * Provides the ability to keep a growing number of events queued up and sends them to * the ingest service. * The events are flushed on a periodic interval or when the set capacity has been reached. */ export declare class EventBatcher { private ingest; private readonly batchSize; private readonly batchCount; private readonly timeout; private queue; private timer; private promiseQueue; /** * @param ingest The proxy for the Ingest service API. * @param batchSize The size of events, in bytes. * @param batchCount The number of events. * @param timeout The interval to send the events and flush the queue, in milliseconds. */ constructor(ingest: IngestService, batchSize: number, batchCount: number, timeout: any); /** * Adds a new event to the array and sends all of the events if the event limits are met. * * @param event A single event. */ add: (event: Event) => Promise; /** * Creates a periodic task to send all of the events. * * @return The timer that was created. */ private setTimer; /** * Resets the timer and updates the timer ID. */ private resetTimer; /** * Cleans up the events and timer. * @return A promise to be completed when the events are accepted by the service. */ flush: () => Promise; /** * Processes the events in the queue and sends them to the HTTP Event Collector (HEC) * when the queue limits are met or exceeded. * If the events are sent, a promise is returned. Otherwise, the event is queued until the limit is reached. * A timer runs periodically to ensure that events do not stay queued too long. * * @return `null` if the event has not yet been sent. */ private run; /** * Performs a flush operation if the queue is not empty. */ stop: () => Promise<{} | HTTPResponse>; /** * Stops the timer. */ private stopTimer; } export {};