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. + } + ); } /**