Skip to content

Commit

Permalink
[APM] When using search bar UI should fall back to transactions (#103987
Browse files Browse the repository at this point in the history
)

* adding kuery bar to search transactions metrics

* addressig PR comments

* fixing api test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
cauemarcondes and kibanamachine authored Jul 5, 2021
1 parent f9c5227 commit b0b0584
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -36,6 +38,7 @@ export async function getHasAggregatedTransactions({
filter: [
{ exists: { field: TRANSACTION_DURATION_HISTOGRAM } },
...(start && end ? rangeQuery(start, end) : []),
...kqlQuery(kuery),
],
},
},
Expand All @@ -56,19 +59,22 @@ export async function getSearchAggregatedTransactions({
start,
end,
apmEventClient,
kuery,
}: {
config: APMConfig;
start?: number;
end?: number;
apmEventClient: APMEventClient;
kuery?: string;
}): Promise<boolean> {
const searchAggregatedTransactions =
config['xpack.apm.searchAggregatedTransactions'];

if (
kuery ||
searchAggregatedTransactions === SearchAggregatedTransactionSetting.auto
) {
return getHasAggregatedTransactions({ start, end, apmEventClient });
return getHasAggregatedTransactions({ start, end, apmEventClient, kuery });
}

return (
Expand Down
35 changes: 20 additions & 15 deletions x-pack/plugins/apm/server/routes/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -552,9 +555,10 @@ const serviceInstancesDetailedStatisticsRoute = createApmServerRoute({
latencyAggregationType,
} = params.query;

const searchAggregatedTransactions = await getSearchAggregatedTransactions(
setup
);
const searchAggregatedTransactions = await getSearchAggregatedTransactions({
...setup,
kuery,
});

return getServiceInstancesDetailedStatisticsPeriods({
environment,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions x-pack/plugins/apm/server/routes/traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
55 changes: 30 additions & 25 deletions x-pack/plugins/apm/server/routes/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -140,11 +141,6 @@ const transactionGroupsDetailedStatisticsRoute = createApmServerRoute({
},
handler: async (resources) => {
const setup = await setupRequest(resources);

const searchAggregatedTransactions = await getSearchAggregatedTransactions(
setup
);

const { params } = resources;

const {
Expand All @@ -161,6 +157,11 @@ const transactionGroupsDetailedStatisticsRoute = createApmServerRoute({
},
} = params;

const searchAggregatedTransactions = await getSearchAggregatedTransactions({
...setup,
kuery,
});

return await getServiceTransactionGroupDetailedStatisticsPeriods({
environment,
kuery,
Expand Down Expand Up @@ -208,9 +209,10 @@ const transactionLatencyChartsRoute = createApmServerRoute({
comparisonEnd,
} = params.query;

const searchAggregatedTransactions = await getSearchAggregatedTransactions(
setup
);
const searchAggregatedTransactions = await getSearchAggregatedTransactions({
...setup,
kuery,
});

const options = {
environment,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -327,9 +330,10 @@ const transactionChartsDistributionRoute = createApmServerRoute({
traceId = '',
} = params.query;

const searchAggregatedTransactions = await getSearchAggregatedTransactions(
setup
);
const searchAggregatedTransactions = await getSearchAggregatedTransactions({
...setup,
kuery,
});

return getTransactionDistribution({
environment,
Expand Down Expand Up @@ -411,9 +415,10 @@ const transactionChartsErrorRateRoute = createApmServerRoute({
comparisonEnd,
} = params.query;

const searchAggregatedTransactions = await getSearchAggregatedTransactions(
setup
);
const searchAggregatedTransactions = await getSearchAggregatedTransactions({
...setup,
kuery,
});

return getErrorRatePeriods({
environment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down

0 comments on commit b0b0584

Please sign in to comment.