From 28800ef35ef27d1a2107d2e6d2bcb94a538b61fa Mon Sep 17 00:00:00 2001 From: Achyut Jhunjhunwala Date: Thu, 27 Jul 2023 13:49:05 +0200 Subject: [PATCH] [APM] Add range query to terms enum call (#162614) Closes https://github.com/elastic/kibana/issues/159202 --- .../app/storage_explorer/services_table/index.tsx | 4 +++- .../get_service_names_from_terms_enum.ts | 13 +++++++++++++ .../apm/server/routes/storage_explorer/route.ts | 11 +++++++++-- .../tests/storage_explorer/get_services.spec.ts | 2 ++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/apm/public/components/app/storage_explorer/services_table/index.tsx b/x-pack/plugins/apm/public/components/app/storage_explorer/services_table/index.tsx index cbe7d908c8acc..b9ed2e6730275 100644 --- a/x-pack/plugins/apm/public/components/app/storage_explorer/services_table/index.tsx +++ b/x-pack/plugins/apm/public/components/app/storage_explorer/services_table/index.tsx @@ -112,12 +112,14 @@ export function ServicesTable() { environment, kuery, indexLifecyclePhase, + start, + end, }, }, }); } }, - [environment, kuery, indexLifecyclePhase, useOptimizedSorting] + [useOptimizedSorting, environment, kuery, indexLifecyclePhase, start, end] ); const serviceStatisticsFetch = useProgressiveFetcher( diff --git a/x-pack/plugins/apm/server/routes/services/get_services/get_service_names_from_terms_enum.ts b/x-pack/plugins/apm/server/routes/services/get_services/get_service_names_from_terms_enum.ts index 0e40a35c1bb6b..1a40ce8ee88e4 100644 --- a/x-pack/plugins/apm/server/routes/services/get_services/get_service_names_from_terms_enum.ts +++ b/x-pack/plugins/apm/server/routes/services/get_services/get_service_names_from_terms_enum.ts @@ -15,10 +15,14 @@ export async function getServiceNamesFromTermsEnum({ apmEventClient, environment, maxNumberOfServices, + start, + end, }: { apmEventClient: APMEventClient; environment: Environment; maxNumberOfServices: number; + start: number; + end: number; }) { if (environment !== ENVIRONMENT_ALL.value) { return []; @@ -36,6 +40,15 @@ export async function getServiceNamesFromTermsEnum({ }, size: maxNumberOfServices, field: SERVICE_NAME, + index_filter: { + range: { + ['@timestamp']: { + gte: start, + lte: end, + format: 'epoch_millis', + }, + }, + }, } ); diff --git a/x-pack/plugins/apm/server/routes/storage_explorer/route.ts b/x-pack/plugins/apm/server/routes/storage_explorer/route.ts index 3a862ab90aca4..39eb0f6f65881 100644 --- a/x-pack/plugins/apm/server/routes/storage_explorer/route.ts +++ b/x-pack/plugins/apm/server/routes/storage_explorer/route.ts @@ -323,7 +323,12 @@ const storageExplorerGetServices = createApmServerRoute({ tags: ['access:apm'], }, params: t.type({ - query: t.intersection([indexLifecyclePhaseRt, environmentRt, kueryRt]), + query: t.intersection([ + indexLifecyclePhaseRt, + environmentRt, + kueryRt, + rangeRt, + ]), }), handler: async ( resources @@ -333,7 +338,7 @@ const storageExplorerGetServices = createApmServerRoute({ }>; }> => { const { - query: { environment, kuery, indexLifecyclePhase }, + query: { environment, kuery, indexLifecyclePhase, start, end }, } = resources.params; if ( @@ -352,6 +357,8 @@ const storageExplorerGetServices = createApmServerRoute({ apmEventClient, environment, maxNumberOfServices: 500, + start, + end, }); return { diff --git a/x-pack/test/apm_api_integration/tests/storage_explorer/get_services.spec.ts b/x-pack/test/apm_api_integration/tests/storage_explorer/get_services.spec.ts index de421ed149827..4a1f59925a018 100644 --- a/x-pack/test/apm_api_integration/tests/storage_explorer/get_services.spec.ts +++ b/x-pack/test/apm_api_integration/tests/storage_explorer/get_services.spec.ts @@ -37,6 +37,8 @@ export default function ApiTest({ getService }: FtrProviderContext) { environment, kuery, indexLifecyclePhase, + start, + end, }, }, });