[APM] Performance fix for 'cardinality' telemetry task (#144061)

* Performance fix for 'cardinality' telemetry task

* Make timeout/index required for telemetry searches

* Fix tests

Co-authored-by: Dario Gieselaar <dario.gieselaar@elastic.co>
This commit is contained in:
Colton Myers 2022-10-27 12:03:29 -06:00 committed by GitHub
parent 756916db3f
commit a5c8ebe00d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View file

@ -17,7 +17,11 @@ type ISavedObjectsClient = Pick<SavedObjectsClient, 'find'>;
type TelemetryTaskExecutor = (params: {
indices: ApmIndicesConfig;
search<TSearchRequest extends ESSearchRequest>(
search<
TSearchRequest extends ESSearchRequest & { index: string | string[] } & {
body: { timeout: string };
}
>(
params: TSearchRequest
): Promise<ESSearchResponse<unknown, TSearchRequest>>;
indicesStats(

View file

@ -434,7 +434,7 @@ describe('data telemetry collection tasks', () => {
}
});
expect(await task?.executor({ search } as any)).toEqual({
expect(await task?.executor({ search, indices } as any)).toEqual({
cardinality: {
client: { geo: { country_iso_code: { rum: { '1d': 5 } } } },
transaction: { name: { all_agents: { '1d': 3 }, rum: { '1d': 1 } } },

View file

@ -148,6 +148,7 @@ export const tasks: TelemetryTask[] = [
await search({
index: indices.transaction,
body: {
timeout,
query: {
bool: {
filter: [
@ -355,6 +356,7 @@ export const tasks: TelemetryTask[] = [
const response = await search({
index: [indices.transaction],
body: {
timeout,
query: {
bool: {
filter: [{ range: { '@timestamp': { gte: 'now-1d' } } }],
@ -1032,8 +1034,9 @@ export const tasks: TelemetryTask[] = [
},
{
name: 'cardinality',
executor: async ({ search }) => {
executor: async ({ indices, search }) => {
const allAgentsCardinalityResponse = await search({
index: [indices.transaction],
body: {
size: 0,
timeout,
@ -1058,6 +1061,7 @@ export const tasks: TelemetryTask[] = [
});
const rumAgentCardinalityResponse = await search({
index: [indices.transaction],
body: {
size: 0,
timeout,