From b0b0584b55b7b48057d806436ba7fe69da7f1567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Marcondes?= <55978943+cauemarcondes@users.noreply.github.com> Date: Mon, 5 Jul 2021 16:15:50 -0400 Subject: [PATCH] [APM] When using search bar UI should fall back to transactions (#103987) * adding kuery bar to search transactions metrics * addressig PR comments * fixing api test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../helpers/aggregated_transactions/index.ts | 10 +++- x-pack/plugins/apm/server/routes/services.ts | 35 +++++++----- x-pack/plugins/apm/server/routes/traces.ts | 7 ++- .../plugins/apm/server/routes/transactions.ts | 55 ++++++++++--------- .../tests/services/top_services.ts | 7 --- 5 files changed, 62 insertions(+), 52 deletions(-) diff --git a/x-pack/plugins/apm/server/lib/helpers/aggregated_transactions/index.ts b/x-pack/plugins/apm/server/lib/helpers/aggregated_transactions/index.ts index 8bfb137c1689c..60ce36a85235e 100644 --- a/x-pack/plugins/apm/server/lib/helpers/aggregated_transactions/index.ts +++ b/x-pack/plugins/apm/server/lib/helpers/aggregated_transactions/index.ts @@ -6,7 +6,7 @@ */ import { SearchAggregatedTransactionSetting } from '../../../../common/aggregated_transactions'; -import { rangeQuery } from '../../../../server/utils/queries'; +import { kqlQuery, rangeQuery } from '../../../../server/utils/queries'; import { ProcessorEvent } from '../../../../common/processor_event'; import { TRANSACTION_DURATION, @@ -19,10 +19,12 @@ export async function getHasAggregatedTransactions({ start, end, apmEventClient, + kuery, }: { start?: number; end?: number; apmEventClient: APMEventClient; + kuery?: string; }) { const response = await apmEventClient.search( 'get_has_aggregated_transactions', @@ -36,6 +38,7 @@ export async function getHasAggregatedTransactions({ filter: [ { exists: { field: TRANSACTION_DURATION_HISTOGRAM } }, ...(start && end ? rangeQuery(start, end) : []), + ...kqlQuery(kuery), ], }, }, @@ -56,19 +59,22 @@ export async function getSearchAggregatedTransactions({ start, end, apmEventClient, + kuery, }: { config: APMConfig; start?: number; end?: number; apmEventClient: APMEventClient; + kuery?: string; }): Promise { const searchAggregatedTransactions = config['xpack.apm.searchAggregatedTransactions']; if ( + kuery || searchAggregatedTransactions === SearchAggregatedTransactionSetting.auto ) { - return getHasAggregatedTransactions({ start, end, apmEventClient }); + return getHasAggregatedTransactions({ start, end, apmEventClient, kuery }); } return ( diff --git a/x-pack/plugins/apm/server/routes/services.ts b/x-pack/plugins/apm/server/routes/services.ts index 4384d2be78ca0..3329119726bb5 100644 --- a/x-pack/plugins/apm/server/routes/services.ts +++ b/x-pack/plugins/apm/server/routes/services.ts @@ -51,9 +51,10 @@ const servicesRoute = createApmServerRoute({ const setup = await setupRequest(resources); const { params, logger } = resources; const { environment, kuery } = params.query; - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); return getServices({ environment, @@ -405,9 +406,10 @@ const serviceThroughputRoute = createApmServerRoute({ comparisonStart, comparisonEnd, } = params.query; - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); const { start, end } = setup; @@ -477,9 +479,10 @@ const serviceInstancesMainStatisticsRoute = createApmServerRoute({ comparisonEnd, } = params.query; - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); const { start, end } = setup; @@ -552,9 +555,10 @@ const serviceInstancesDetailedStatisticsRoute = createApmServerRoute({ latencyAggregationType, } = params.query; - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); return getServiceInstancesDetailedStatisticsPeriods({ environment, @@ -593,9 +597,10 @@ export const serviceInstancesMetadataDetails = createApmServerRoute({ const { serviceName, serviceNodeName } = resources.params.path; const { transactionType, environment, kuery } = resources.params.query; - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); return await getServiceInstanceMetadataDetails({ searchAggregatedTransactions, diff --git a/x-pack/plugins/apm/server/routes/traces.ts b/x-pack/plugins/apm/server/routes/traces.ts index 7fce04644f220..bed7252dd20fd 100644 --- a/x-pack/plugins/apm/server/routes/traces.ts +++ b/x-pack/plugins/apm/server/routes/traces.ts @@ -26,9 +26,10 @@ const tracesRoute = createApmServerRoute({ const setup = await setupRequest(resources); const { params } = resources; const { environment, kuery } = params.query; - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); return getTransactionGroupList( { environment, kuery, type: 'top_traces', searchAggregatedTransactions }, diff --git a/x-pack/plugins/apm/server/routes/transactions.ts b/x-pack/plugins/apm/server/routes/transactions.ts index bcc554e552fc3..c20de31847e8a 100644 --- a/x-pack/plugins/apm/server/routes/transactions.ts +++ b/x-pack/plugins/apm/server/routes/transactions.ts @@ -56,9 +56,10 @@ const transactionGroupsRoute = createApmServerRoute({ const { serviceName } = params.path; const { environment, kuery, transactionType } = params.query; - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); return getTransactionGroupList( { @@ -95,16 +96,16 @@ const transactionGroupsMainStatisticsRoute = createApmServerRoute({ handler: async (resources) => { const { params } = resources; const setup = await setupRequest(resources); - - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); - const { path: { serviceName }, query: { environment, kuery, latencyAggregationType, transactionType }, } = params; + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); + return getServiceTransactionGroups({ environment, kuery, @@ -140,11 +141,6 @@ const transactionGroupsDetailedStatisticsRoute = createApmServerRoute({ }, handler: async (resources) => { const setup = await setupRequest(resources); - - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); - const { params } = resources; const { @@ -161,6 +157,11 @@ const transactionGroupsDetailedStatisticsRoute = createApmServerRoute({ }, } = params; + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); + return await getServiceTransactionGroupDetailedStatisticsPeriods({ environment, kuery, @@ -208,9 +209,10 @@ const transactionLatencyChartsRoute = createApmServerRoute({ comparisonEnd, } = params.query; - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); const options = { environment, @@ -276,9 +278,10 @@ const transactionThroughputChartsRoute = createApmServerRoute({ transactionName, } = params.query; - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); return await getThroughputCharts({ environment, @@ -327,9 +330,10 @@ const transactionChartsDistributionRoute = createApmServerRoute({ traceId = '', } = params.query; - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); return getTransactionDistribution({ environment, @@ -411,9 +415,10 @@ const transactionChartsErrorRateRoute = createApmServerRoute({ comparisonEnd, } = params.query; - const searchAggregatedTransactions = await getSearchAggregatedTransactions( - setup - ); + const searchAggregatedTransactions = await getSearchAggregatedTransactions({ + ...setup, + kuery, + }); return getErrorRatePeriods({ environment, diff --git a/x-pack/test/apm_api_integration/tests/services/top_services.ts b/x-pack/test/apm_api_integration/tests/services/top_services.ts index 37f7b09e8b7d2..9c687fc74acce 100644 --- a/x-pack/test/apm_api_integration/tests/services/top_services.ts +++ b/x-pack/test/apm_api_integration/tests/services/top_services.ts @@ -286,13 +286,6 @@ export default function ApiTest({ getService }: FtrProviderContext) { expect(unfilteredServiceNames).to.eql(filteredServiceNames); - expect( - filteredResponse.body.items.every((item) => { - // make sure it did not query transaction data - return isEmpty(item.avgResponseTime); - }) - ).to.be(true); - expect(filteredResponse.body.items.every((item) => !!item.agentName)).to.be(true); }); }