Skip to content

Commit

Permalink
[APM] Use consistent filtering for fetching mobile data (#144453)
Browse files Browse the repository at this point in the history
* [APM] Use consistent filtering for fetching mobile data

* Clean up console logs
  • Loading branch information
kpatticha authored Nov 2, 2022
1 parent 21472f8 commit 57dce56
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type MobileFilter =
interface Props {
end: string;
environment: Environment;
transactionType?: string;
kuery: string;
start: string;
filters: Record<MobileFilter['key'], string | undefined>;
Expand All @@ -32,6 +33,7 @@ const ALL_OPTION = {
export function MobileFilters({
end,
environment,
transactionType,
kuery,
start,
filters,
Expand All @@ -45,12 +47,12 @@ export function MobileFilters({
{
params: {
path: { serviceName },
query: { end, environment, kuery, start },
query: { end, environment, kuery, start, transactionType },
},
}
);
},
[end, environment, kuery, serviceName, start]
[end, environment, kuery, serviceName, start, transactionType]
);

function toSelectOptions(items?: string[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function ServiceOverviewMobileCharts({
device,
osVersion,
appVersion,
transactionType,
},
} = useApmParams('/services/{serviceName}/overview');

Expand All @@ -75,6 +76,7 @@ export function ServiceOverviewMobileCharts({
start={start}
end={end}
environment={environment}
transactionType={transactionType}
kuery={kuery}
filters={{
device,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import { useMemo } from 'react';
import { type QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { isNil, isEmpty } from 'lodash';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { environmentQuery } from '../../../../../common/utils/environment_query';
import { useApmParams } from '../../../../hooks/use_apm_params';
import {
SERVICE_NAME,
TRANSACTION_TYPE,
PROCESSOR_EVENT,
HOST_OS_VERSION,
DEVICE_MODEL_NAME,
NETWORK_CONNECTION_TYPE,
Expand Down Expand Up @@ -48,7 +46,6 @@ export function useFiltersForMobileCharts() {
return useMemo(
() =>
[
...termQuery(PROCESSOR_EVENT, ProcessorEvent.transaction),
...termQuery(SERVICE_NAME, serviceName),
...termQuery(TRANSACTION_TYPE, transactionType),
...termQuery(HOST_OS_VERSION, osVersion),
Expand Down
20 changes: 10 additions & 10 deletions x-pack/plugins/apm/server/routes/mobile/get_mobile_filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ import {
kqlQuery,
rangeQuery,
} from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import {
DEVICE_MODEL_NAME,
HOST_OS_VERSION,
NETWORK_CONNECTION_TYPE,
SERVICE_NAME,
SERVICE_VERSION,
TRANSACTION_TYPE,
} from '../../../common/elasticsearch_fieldnames';
import { environmentQuery } from '../../../common/utils/environment_query';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
import {
getDocumentTypeFilterForTransactions,
getProcessorEventForTransactions,
} from '../../lib/helpers/transactions';

type MobileFiltersTypes =
| 'device'
Expand All @@ -40,22 +38,26 @@ export async function getMobileFilters({
kuery,
apmEventClient,
serviceName,
transactionType,
environment,
start,
end,
searchAggregatedTransactions,
}: {
kuery: string;
apmEventClient: APMEventClient;
serviceName: string;
transactionType?: string;
environment: string;
start: number;
end: number;
searchAggregatedTransactions: boolean;
}): Promise<MobileFilters> {
const response = await apmEventClient.search('get_mobile_filters', {
apm: {
events: [getProcessorEventForTransactions(searchAggregatedTransactions)],
events: [
ProcessorEvent.error,
ProcessorEvent.metric,
ProcessorEvent.transaction,
],
},
body: {
track_total_hits: false,
Expand All @@ -64,12 +66,10 @@ export async function getMobileFilters({
bool: {
filter: [
...termQuery(SERVICE_NAME, serviceName),
...termQuery(TRANSACTION_TYPE, transactionType),
...rangeQuery(start, end),
...environmentQuery(environment),
...kqlQuery(kuery),
...getDocumentTypeFilterForTransactions(
searchAggregatedTransactions
),
],
},
},
Expand Down
28 changes: 12 additions & 16 deletions x-pack/plugins/apm/server/routes/mobile/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import * as t from 'io-ts';
import { getApmEventClient } from '../../lib/helpers/get_apm_event_client';
import { setupRequest } from '../../lib/helpers/setup_request';
import { getSearchTransactionsEvents } from '../../lib/helpers/transactions';
import { createApmServerRoute } from '../apm_routes/create_apm_server_route';
import { environmentRt, kueryRt, rangeRt } from '../default_api_types';
import { getMobileFilters } from './get_mobile_filters';
Expand All @@ -19,36 +17,34 @@ const mobileFilters = createApmServerRoute({
path: t.type({
serviceName: t.string,
}),
query: t.intersection([kueryRt, rangeRt, environmentRt]),
query: t.intersection([
kueryRt,
rangeRt,
environmentRt,
t.partial({
transactionType: t.string,
}),
]),
}),
options: { tags: ['access:apm'] },
handler: async (
resources
): Promise<{
mobileFilters: Awaited<ReturnType<typeof getMobileFilters>>;
}> => {
const [setup, apmEventClient] = await Promise.all([
setupRequest(resources),
getApmEventClient(resources),
]);
const apmEventClient = await getApmEventClient(resources);
const { params } = resources;
const { serviceName } = params.path;
const { kuery, environment, start, end } = params.query;
const searchAggregatedTransactions = await getSearchTransactionsEvents({
apmEventClient,
config: setup.config,
kuery,
start,
end,
});
const { kuery, environment, start, end, transactionType } = params.query;

const filters = await getMobileFilters({
kuery,
environment,
transactionType,
start,
end,
serviceName,
apmEventClient,
searchAggregatedTransactions,
});
return { mobileFilters: filters };
},
Expand Down

0 comments on commit 57dce56

Please sign in to comment.