From fe8d8d50f02b4587b7fc45f06c0b72aec9ae6167 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 4 May 2021 16:14:27 -0400 Subject: [PATCH 1/5] adjust data types for uiFilters and range in apm requests --- x-pack/plugins/apm/server/routes/default_api_types.ts | 2 +- x-pack/plugins/apm/server/routes/rum_client.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/apm/server/routes/default_api_types.ts b/x-pack/plugins/apm/server/routes/default_api_types.ts index 3181a3dbce7ac..c3d5e295ec36d 100644 --- a/x-pack/plugins/apm/server/routes/default_api_types.ts +++ b/x-pack/plugins/apm/server/routes/default_api_types.ts @@ -8,7 +8,7 @@ import * as t from 'io-ts'; import { isoToEpochRt } from '@kbn/io-ts-utils'; -export const rangeRt = t.type({ +export const rangeRt = t.partial({ start: isoToEpochRt, end: isoToEpochRt, }); diff --git a/x-pack/plugins/apm/server/routes/rum_client.ts b/x-pack/plugins/apm/server/routes/rum_client.ts index c723f2c266ca9..56538167d8540 100644 --- a/x-pack/plugins/apm/server/routes/rum_client.ts +++ b/x-pack/plugins/apm/server/routes/rum_client.ts @@ -38,7 +38,7 @@ export const percentileRangeRt = t.partial({ maxPercentile: t.string, }); -const uiFiltersRt = t.type({ uiFilters: t.string }); +const uiFiltersRt = t.partial({ uiFilters: t.string }); const uxQueryRt = t.intersection([ uiFiltersRt, From 44aee1abb10050336fab139f191471fee8c8a9bd Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 12 May 2021 09:16:52 -0400 Subject: [PATCH 2/5] update has_rum_data api query types --- x-pack/plugins/apm/server/routes/default_api_types.ts | 2 +- x-pack/plugins/apm/server/routes/rum_client.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/apm/server/routes/default_api_types.ts b/x-pack/plugins/apm/server/routes/default_api_types.ts index c3d5e295ec36d..3181a3dbce7ac 100644 --- a/x-pack/plugins/apm/server/routes/default_api_types.ts +++ b/x-pack/plugins/apm/server/routes/default_api_types.ts @@ -8,7 +8,7 @@ import * as t from 'io-ts'; import { isoToEpochRt } from '@kbn/io-ts-utils'; -export const rangeRt = t.partial({ +export const rangeRt = t.type({ start: isoToEpochRt, end: isoToEpochRt, }); diff --git a/x-pack/plugins/apm/server/routes/rum_client.ts b/x-pack/plugins/apm/server/routes/rum_client.ts index 56538167d8540..bf58c7fcf39b2 100644 --- a/x-pack/plugins/apm/server/routes/rum_client.ts +++ b/x-pack/plugins/apm/server/routes/rum_client.ts @@ -7,6 +7,7 @@ import * as t from 'io-ts'; import { jsonRt } from '@kbn/io-ts-utils'; +import { isoToEpochRt } from '@kbn/io-ts-utils'; import { LocalUIFilterName } from '../../common/ui_filter'; import { Setup, @@ -38,7 +39,7 @@ export const percentileRangeRt = t.partial({ maxPercentile: t.string, }); -const uiFiltersRt = t.partial({ uiFilters: t.string }); +const uiFiltersRt = t.type({ uiFilters: t.string }); const uxQueryRt = t.intersection([ uiFiltersRt, @@ -264,7 +265,11 @@ const rumJSErrors = createApmServerRoute({ const rumHasDataRoute = createApmServerRoute({ endpoint: 'GET /api/apm/observability_overview/has_rum_data', params: t.partial({ - query: t.intersection([uiFiltersRt, rangeRt]), + query: t.partial({ + uiFilters: t.string, + start: isoToEpochRt, + end: isoToEpochRt, + }), }), options: { tags: ['access:apm'] }, handler: async (resources) => { From 0d334c80a81d697413c373bd33a8fff8fdd0c349 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 12 May 2021 11:41:24 -0400 Subject: [PATCH 3/5] update hasRumData setup type --- x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts b/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts index 8de2e4e1cca42..d51e21e14350e 100644 --- a/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts +++ b/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts @@ -14,7 +14,11 @@ import { ProcessorEvent } from '../../../common/processor_event'; import { rangeQuery } from '../../../server/utils/queries'; import { TRANSACTION_PAGE_LOAD } from '../../../common/transaction_types'; -export async function hasRumData({ setup }: { setup: Setup & SetupTimeRange }) { +export async function hasRumData({ + setup, +}: { + setup: Setup & Partial; +}) { try { const { start, end } = setup; @@ -31,7 +35,7 @@ export async function hasRumData({ setup }: { setup: Setup & SetupTimeRange }) { }, aggs: { services: { - filter: rangeQuery(start, end)[0], + ...(start && end ? { filter: rangeQuery(start, end)[0] } : {}), aggs: { mostTraffic: { terms: { From 9eed989b0e8e323fa4f2f8da8a12e26b7dd75198 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Fri, 14 May 2021 08:57:26 -0400 Subject: [PATCH 4/5] update has_rum_data query to account for undefined start and end --- .../apm/server/lib/rum_client/has_rum_data.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts b/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts index d51e21e14350e..ef277c4ab4b63 100644 --- a/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts +++ b/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts @@ -35,7 +35,18 @@ export async function hasRumData({ }, aggs: { services: { - ...(start && end ? { filter: rangeQuery(start, end)[0] } : {}), + ...(start && end + ? { filter: rangeQuery(start, end)[0] } + : { + // accounts for scenarios in which start and end are undefined + filter: { + range: { + '@timestamp': { + format: 'epoch_millis', + }, + }, + }, + }), aggs: { mostTraffic: { terms: { From 4ee8cf48dfc1369c3e082de95c554781747078e2 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Fri, 14 May 2021 10:09:55 -0400 Subject: [PATCH 5/5] update observability rangeQuery helper to account for undefined start and end --- .../apm/server/lib/rum_client/has_rum_data.ts | 13 +------------ .../plugins/observability/server/utils/queries.ts | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts b/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts index ef277c4ab4b63..87136fc0538a6 100644 --- a/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts +++ b/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts @@ -35,18 +35,7 @@ export async function hasRumData({ }, aggs: { services: { - ...(start && end - ? { filter: rangeQuery(start, end)[0] } - : { - // accounts for scenarios in which start and end are undefined - filter: { - range: { - '@timestamp': { - format: 'epoch_millis', - }, - }, - }, - }), + filter: rangeQuery(start, end)[0], aggs: { mostTraffic: { terms: { diff --git a/x-pack/plugins/observability/server/utils/queries.ts b/x-pack/plugins/observability/server/utils/queries.ts index 584719532ddee..9e1c110e77587 100644 --- a/x-pack/plugins/observability/server/utils/queries.ts +++ b/x-pack/plugins/observability/server/utils/queries.ts @@ -8,7 +8,7 @@ import { QueryContainer } from '@elastic/elasticsearch/api/types'; import { esKuery } from '../../../../../src/plugins/data/server'; -export function rangeQuery(start: number, end: number, field = '@timestamp'): QueryContainer[] { +export function rangeQuery(start?: number, end?: number, field = '@timestamp'): QueryContainer[] { return [ { range: {