Skip to content

Commit

Permalink
[8.8] [APM] Fix query to mobile transactions main statistics (#155895) (
Browse files Browse the repository at this point in the history
#156152)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[APM] Fix query to mobile transactions main statistics
(#155895)](#155895)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Miriam","email":"31922082+MiriamAparicio@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-04-28T09:35:45Z","message":"[APM]
Fix query to mobile transactions main statistics (#155895)\n\nWhen
splitting the query to mobile transactions main statistics,
the\r\nsessions were left in the errors query and should have been
retrieved in\r\nthe transactions events. This PR fix this
issue","sha":"67b211001fe50d3d2f2430689402f1bab8224294","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:APM","release_note:skip","v8.8.0","v8.9.0"],"number":155895,"url":"https://github.com/elastic/kibana/pull/155895","mergeCommit":{"message":"[APM]
Fix query to mobile transactions main statistics (#155895)\n\nWhen
splitting the query to mobile transactions main statistics,
the\r\nsessions were left in the errors query and should have been
retrieved in\r\nthe transactions events. This PR fix this
issue","sha":"67b211001fe50d3d2f2430689402f1bab8224294"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/155895","number":155895,"mergeCommit":{"message":"[APM]
Fix query to mobile transactions main statistics (#155895)\n\nWhen
splitting the query to mobile transactions main statistics,
the\r\nsessions were left in the errors query and should have been
retrieved in\r\nthe transactions events. This PR fix this
issue","sha":"67b211001fe50d3d2f2430689402f1bab8224294"}}]}] BACKPORT-->

Co-authored-by: Miriam <31922082+MiriamAparicio@users.noreply.github.com>
  • Loading branch information
kibanamachine and MiriamAparicio authored Apr 28, 2023
1 parent c7cc732 commit f3a5c3c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ type MobileDetailedStatisticsByField =
APIReturnType<'GET /internal/apm/mobile-services/{serviceName}/detailed_statistics'>;

export function getColumns({
agentName,
detailedStatisticsLoading,
detailedStatistics,
comparisonEnabled,
offset,
}: {
agentName?: string;
detailedStatisticsLoading: boolean;
detailedStatistics: MobileDetailedStatisticsByField;
comparisonEnabled?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ export interface MobileMainStatisticsResponse {
name: string | number;
latency: number | null;
throughput: number;
crashRate?: number;
crashRate: number;
}>;
}

type MergedQueriesResponse = Array<{
name: string | number;
latency: number | null;
throughput: number;
sessions: number;
crashes?: number;
}>;

export async function getMobileMainStatisticsByField({
kuery,
apmEventClient,
Expand All @@ -55,7 +63,7 @@ export async function getMobileMainStatisticsByField({
}: Props) {
async function getMobileTransactionEventStatistics() {
const response = await apmEventClient.search(
`get_mobile_main_statistics_by_field`,
`get_mobile_transaction_events_main_statistics_by_field`,
{
apm: {
sources: [
Expand Down Expand Up @@ -90,6 +98,11 @@ export async function getMobileMainStatisticsByField({
field: TRANSACTION_DURATION,
},
},
sessions: {
cardinality: {
field: SESSION_ID,
},
},
},
},
},
Expand All @@ -110,66 +123,59 @@ export async function getMobileMainStatisticsByField({
end,
value: bucket.doc_count,
}),
sessions: bucket.sessions.value,
};
}) ?? []
);
}

async function getMobileErrorEventStatistics() {
const response = await apmEventClient.search(
`get_mobile_transaction_events_main_statistics_by_field`,
{
apm: {
sources: [
{
documentType: ApmDocumentType.ErrorEvent,
rollupInterval: RollupInterval.None,
},
],
const response = await apmEventClient.search(`get_mobile_crashes`, {
apm: {
sources: [
{
documentType: ApmDocumentType.ErrorEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,
size: 0,
query: {
bool: {
filter: [
...termQuery(SERVICE_NAME, serviceName),
...rangeQuery(start, end),
...environmentQuery(environment),
...kqlQuery(kuery),
],
},
},
body: {
track_total_hits: false,
size: 0,
query: {
bool: {
filter: [
...termQuery(SERVICE_NAME, serviceName),
...rangeQuery(start, end),
...environmentQuery(environment),
...kqlQuery(kuery),
],
aggs: {
main_statistics: {
terms: {
field,
size: 1000,
},
},
aggs: {
main_statistics: {
terms: {
field,
size: 1000,
},
aggs: {
sessions: {
cardinality: {
field: SESSION_ID,
},
},
crashes: {
filter: {
term: {
[ERROR_TYPE]: 'crash',
},
aggs: {
crashes: {
filter: {
term: {
[ERROR_TYPE]: 'crash',
},
},
},
},
},
},
}
);
},
});
return (
response.aggregations?.main_statistics.buckets.map((bucket) => {
return {
name: bucket.key,
crashRate: bucket.crashes.doc_count / bucket.sessions.value ?? 0,
crashes: bucket.crashes.doc_count ?? 0,
};
}) ?? []
);
Expand All @@ -180,7 +186,19 @@ export async function getMobileMainStatisticsByField({
getMobileErrorEventStatistics(),
]);

const mainStatistics = merge(transactioEventStatistics, errorEventStatistics);
const mainStatisticsMerged: MergedQueriesResponse = merge(
transactioEventStatistics,
errorEventStatistics
);

const mainStatistics = mainStatisticsMerged.map((item) => {
return {
name: item.name,
latency: item.latency,
throughput: item.throughput,
crashRate: item.crashes ? item.crashes / item.sessions : 0,
};
});

return { mainStatistics };
}

0 comments on commit f3a5c3c

Please sign in to comment.