From 65c72082906236fc5563e01cbaec20bd4d9983bb Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 15 Oct 2024 11:01:46 -0400 Subject: [PATCH] [Telemetry] Add cluster stat timeout (#195793) ## Summary Increase cluster-stat timeout. Closes https://github.com/elastic/kibana/issues/192129 ~~This is a draft. Will discuss with @rudolf if this is the direction we'd like to go.~~ ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels) --- .../server/telemetry_collection/constants.ts | 1 + .../get_cluster_stats.test.ts | 9 ++++++--- .../telemetry_collection/get_cluster_stats.ts | 16 +++++++++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/plugins/telemetry/server/telemetry_collection/constants.ts b/src/plugins/telemetry/server/telemetry_collection/constants.ts index 41629ec71c2e8..cac34967e87a3 100644 --- a/src/plugins/telemetry/server/telemetry_collection/constants.ts +++ b/src/plugins/telemetry/server/telemetry_collection/constants.ts @@ -11,3 +11,4 @@ * The timeout used by each request, whenever a timeout can be specified. */ export const TIMEOUT = '30s'; +export const CLUSTER_STAT_TIMEOUT = '60s'; diff --git a/src/plugins/telemetry/server/telemetry_collection/get_cluster_stats.test.ts b/src/plugins/telemetry/server/telemetry_collection/get_cluster_stats.test.ts index 16cf7b70b9df2..a517fa48e94f9 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_cluster_stats.test.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_cluster_stats.test.ts @@ -9,7 +9,7 @@ import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; import { getClusterStats } from './get_cluster_stats'; -import { TIMEOUT } from './constants'; +import { CLUSTER_STAT_TIMEOUT } from './constants'; describe('get_cluster_stats', () => { it('uses the esClient to get the response from the `cluster.stats` API', async () => { @@ -17,12 +17,15 @@ describe('get_cluster_stats', () => { const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; esClient.cluster.stats.mockImplementationOnce( // @ts-expect-error the method only cares about the response body - async (_params = { timeout: TIMEOUT }) => { + async (_params = { timeout: CLUSTER_STAT_TIMEOUT }) => { return response; } ); const result = await getClusterStats(esClient); - expect(esClient.cluster.stats).toHaveBeenCalledWith({ timeout: TIMEOUT }); + expect(esClient.cluster.stats).toHaveBeenCalledWith( + { timeout: CLUSTER_STAT_TIMEOUT, include_remotes: true }, + { requestTimeout: CLUSTER_STAT_TIMEOUT } + ); expect(result).toStrictEqual(response); }); }); diff --git a/src/plugins/telemetry/server/telemetry_collection/get_cluster_stats.ts b/src/plugins/telemetry/server/telemetry_collection/get_cluster_stats.ts index 20624cb0ea516..35afcacc3d0b5 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_cluster_stats.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_cluster_stats.ts @@ -9,15 +9,25 @@ import { ClusterDetailsGetter } from '@kbn/telemetry-collection-manager-plugin/server'; import { ElasticsearchClient } from '@kbn/core/server'; -import { TIMEOUT } from './constants'; +import { CLUSTER_STAT_TIMEOUT } from './constants'; /** * Get the cluster stats from the connected cluster. * - * This is the equivalent to GET /_cluster/stats?timeout=30s. + * This is the equivalent to GET /_cluster/stats?timeout=60s&include_remotes=true */ export async function getClusterStats(esClient: ElasticsearchClient) { - return await esClient.cluster.stats({ timeout: TIMEOUT }); + return await esClient.cluster.stats( + { + timeout: CLUSTER_STAT_TIMEOUT, + + // @ts-expect-error + include_remotes: true, + }, + { + requestTimeout: CLUSTER_STAT_TIMEOUT, // enforce that Kibana would wait at least as long for ES to complete. + } + ); } /**