From 50d89958910ab6fa9b8c4f4f40c53e89ad6dbbe1 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 1 Jul 2024 17:11:47 +0200 Subject: [PATCH] [8.14] [Logs UI] Add constraint check (#186872) (#187256) # Backport This will backport the following commits from `main` to `8.14`: - [[Logs UI] Add constraint check (#186872)](https://github.com/elastic/kibana/pull/186872) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Joe Reuter --- .../log_entries/kibana_log_entries_adapter.ts | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/observability_solution/logs_shared/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts b/x-pack/plugins/observability_solution/logs_shared/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts index e4eed9b61d349..10b19ebb5d472 100644 --- a/x-pack/plugins/observability_solution/logs_shared/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts +++ b/x-pack/plugins/observability_solution/logs_shared/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts @@ -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) {} @@ -134,11 +149,7 @@ export class LogsSharedKibanaLogEntriesAdapter implements LogEntriesAdapter { bucketSize: number, filterQuery?: LogEntryQuery ): Promise { - const bucketIntervalStarts = timeMilliseconds( - new Date(startTimestamp), - new Date(endTimestamp), - bucketSize - ); + const bucketIntervalStarts = getBucketIntervalStarts(startTimestamp, endTimestamp, bucketSize); const query = { allow_no_indices: true,