Skip to content

Commit

Permalink
[Logs UI] Add constraint check (#186872)
Browse files Browse the repository at this point in the history
Add constraint check to limit max number of buckets that can be
requested at once.

(cherry picked from commit 2daa13d)
  • Loading branch information
flash1293 committed Jul 1, 2024
1 parent c204436 commit d3cf798
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ import { TIMESTAMP_FIELD, TIEBREAKER_FIELD } from '../../../../common/constants'

const TIMESTAMP_FORMAT = 'epoch_millis';

const MAX_BUCKETS = 1000;

function getBucketIntervalStarts(
startTimestamp: number,
endTimestamp: number,
bucketSize: number
): Date[] {
// estimated number of buckets
const bucketCount = Math.ceil((endTimestamp - startTimestamp) / bucketSize);
if (bucketCount > MAX_BUCKETS) {
throw new Error(`Requested too many buckets: ${bucketCount} > ${MAX_BUCKETS}`);
}
return timeMilliseconds(new Date(startTimestamp), new Date(endTimestamp), bucketSize);
}

export class LogsSharedKibanaLogEntriesAdapter implements LogEntriesAdapter {
constructor(private readonly framework: KibanaFramework) {}

Expand Down Expand Up @@ -134,11 +149,7 @@ export class LogsSharedKibanaLogEntriesAdapter implements LogEntriesAdapter {
bucketSize: number,
filterQuery?: LogEntryQuery
): Promise<LogSummaryBucket[]> {
const bucketIntervalStarts = timeMilliseconds(
new Date(startTimestamp),
new Date(endTimestamp),
bucketSize
);
const bucketIntervalStarts = getBucketIntervalStarts(startTimestamp, endTimestamp, bucketSize);

const query = {
allow_no_indices: true,
Expand Down

0 comments on commit d3cf798

Please sign in to comment.