Skip to content

Commit

Permalink
[Telemetry] Add cluster stat timeout (elastic#195793)
Browse files Browse the repository at this point in the history
## Summary

Increase cluster-stat timeout.

Closes elastic#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)
  • Loading branch information
thomasneirynck authored Oct 15, 2024
1 parent 2c21adb commit 65c7208
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@

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 () => {
const response = { cluster_uuid: '1234' };
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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
);
}

/**
Expand Down

0 comments on commit 65c7208

Please sign in to comment.