Skip to content

Commit

Permalink
[APM] Fix mobile indices (#149230)
Browse files Browse the repository at this point in the history
## Summary

Refactor mobile endpoints and fix indices
- rename `getSessionsChart` to `getMobileSessions`
- rename `getHttpRequestsChart` to `getMobileHttpRequests` 
- split queries for `mobile_stats` instead of queries all indices.
Extend `getMobileSessions` and `getMobileHttpRequests` so they can be
used in `mobile_stats`
- remove the metrics 'crashCount` and `maxLoadTime` since they are not
captured yet

related: #146615

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
kpatticha and kibanamachine authored Jan 24, 2023
1 parent 95c2493 commit 199f115
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
import { usePreviousPeriodLabel } from '../../../../hooks/use_previous_period_text';

const INITIAL_STATE = {
currentPeriod: [],
previousPeriod: [],
currentPeriod: { timeseries: [] },
previousPeriod: { timeseries: [] },
};

export function HttpRequestsChart({
Expand Down Expand Up @@ -89,7 +89,7 @@ export function HttpRequestsChart({

const timeseries = [
{
data: data.currentPeriod,
data: data.currentPeriod.timeseries,
type: 'linemark',
color: currentPeriodColor,
title: i18n.translate('xpack.apm.transactions.httpRequestsTitle', {
Expand All @@ -99,7 +99,7 @@ export function HttpRequestsChart({
...(comparisonEnabled
? [
{
data: data.previousPeriod,
data: data.previousPeriod.timeseries,
type: 'area',
color: previousPeriodColor,
title: previousPeriodLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {
import { usePreviousPeriodLabel } from '../../../../hooks/use_previous_period_text';

const INITIAL_STATE = {
currentPeriod: [],
previousPeriod: [],
currentPeriod: { timeseries: [] },
previousPeriod: { timeseries: [] },
};

type SessionsChart =
Expand Down Expand Up @@ -95,7 +95,7 @@ export function SessionsChart({

const timeseries = [
{
data: data.currentPeriod,
data: data.currentPeriod.timeseries,
type: 'linemark',
color: currentPeriodColor,
title: i18n.translate('xpack.apm.transactions.sessionsChartTitle', {
Expand All @@ -105,7 +105,7 @@ export function SessionsChart({
...(comparisonEnabled
? [
{
data: data.previousPeriod,
data: data.previousPeriod.timeseries,
type: 'area',
color: previousPeriodColor,
title: previousPeriodLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export function MobileStats({
defaultMessage: 'Crash Rate',
}),
icon: getIcon('bug'),
value: data?.crashCount?.value ?? NaN,
value: 'N/A',
valueFormatter: (value: number) => valueFormatter(value, 'cpm'),
trend: data?.maxLoadTime?.timeseries,
trend: [],
trendShape: MetricTrendShape.Area,
},
{
Expand All @@ -85,9 +85,9 @@ export function MobileStats({
defaultMessage: 'Slowest App load time',
}),
icon: getIcon('visGauge'),
value: data?.maxLoadTime?.value ?? NaN,
value: 'N/A',
valueFormatter: (value: number) => valueFormatter(value, 's'),
trend: data?.maxLoadTime.timeseries,
trend: [],
trendShape: MetricTrendShape.Area,
},
{
Expand All @@ -96,9 +96,9 @@ export function MobileStats({
defaultMessage: 'Sessions',
}),
icon: getIcon('timeslider'),
value: data?.sessions?.value ?? NaN,
value: data?.currentPeriod?.sessions?.value ?? NaN,
valueFormatter: (value: number) => valueFormatter(value),
trend: data?.sessions.timeseries,
trend: data?.currentPeriod?.sessions?.timeseries,
trendShape: MetricTrendShape.Area,
},
{
Expand All @@ -107,9 +107,9 @@ export function MobileStats({
defaultMessage: 'HTTP requests',
}),
icon: getIcon('kubernetesPod'),
value: data?.requests?.value ?? NaN,
value: data?.currentPeriod?.requests?.value ?? NaN,
valueFormatter: (value: number) => valueFormatter(value),
trend: data?.requests.timeseries,
trend: data?.currentPeriod?.requests?.timeseries ?? [],
trendShape: MetricTrendShape.Area,
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ export async function getMobileFilters({
}): Promise<MobileFilters> {
const response = await apmEventClient.search('get_mobile_filters', {
apm: {
events: [
ProcessorEvent.error,
ProcessorEvent.metric,
ProcessorEvent.transaction,
ProcessorEvent.span,
],
events: [ProcessorEvent.transaction],
},
body: {
track_total_hits: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ import {
SERVICE_NAME,
TRANSACTION_NAME,
SERVICE_TARGET_TYPE,
METRICSET_NAME,
} from '../../../common/es_fields/apm';
import { environmentQuery } from '../../../common/utils/environment_query';
import { getOffsetInMs } from '../../../common/utils/get_offset_in_ms';
import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
import { getBucketSize } from '../../lib/helpers/get_bucket_size';
import { Coordinate } from '../../../typings/timeseries';
import { Maybe } from '../../../typings/common';

export interface HttpRequestsTimeseries {
currentPeriod: Coordinate[];
previousPeriod: Coordinate[];
currentPeriod: { timeseries: Coordinate[]; value: Maybe<number> };
previousPeriod: { timeseries: Coordinate[]; value: Maybe<number> };
}
interface Props {
apmEventClient: APMEventClient;
Expand Down Expand Up @@ -60,6 +62,12 @@ async function getHttpRequestsTimeseries({
minBucketSize: 60,
});

const aggs = {
requests: {
filter: { term: { [SERVICE_TARGET_TYPE]: 'http' } },
},
};

const response = await apmEventClient.search('get_http_requests_chart', {
apm: { events: [ProcessorEvent.metric] },
body: {
Expand All @@ -69,6 +77,7 @@ async function getHttpRequestsTimeseries({
bool: {
filter: [
{ exists: { field: SERVICE_TARGET_TYPE } },
...termQuery(METRICSET_NAME, 'service_destination'),
...termQuery(SERVICE_NAME, serviceName),
...termQuery(TRANSACTION_NAME, transactionName),
...rangeQuery(startWithOffset, endWithOffset),
Expand All @@ -85,27 +94,28 @@ async function getHttpRequestsTimeseries({
min_doc_count: 0,
extended_bounds: { min: startWithOffset, max: endWithOffset },
},
aggs: {
requests: {
filter: { term: { [SERVICE_TARGET_TYPE]: 'http' } },
},
},
aggs,
},
...aggs,
},
},
});

return (
const timeseries =
response?.aggregations?.timeseries.buckets.map((bucket) => {
return {
x: bucket.key,
y: bucket.doc_count ?? 0,
y: bucket.requests.doc_count,
};
}) ?? []
);
}) ?? [];

return {
timeseries,
value: response.aggregations?.requests?.doc_count,
};
}

export async function getHttpRequestsChart({
export async function getMobileHttpRequests({
kuery,
apmEventClient,
serviceName,
Expand Down Expand Up @@ -136,7 +146,7 @@ export async function getHttpRequestsChart({
end,
offset,
})
: [];
: { timeseries: [], value: null };

const [currentPeriod, previousPeriod] = await Promise.all([
currentPeriodPromise,
Expand All @@ -145,9 +155,12 @@ export async function getHttpRequestsChart({

return {
currentPeriod,
previousPeriod: offsetPreviousPeriodCoordinates({
currentPeriodTimeseries: currentPeriod,
previousPeriodTimeseries: previousPeriod,
}),
previousPeriod: {
timeseries: offsetPreviousPeriodCoordinates({
currentPeriodTimeseries: currentPeriod.timeseries,
previousPeriodTimeseries: previousPeriod.timeseries,
}),
value: previousPeriod?.value,
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import { getOffsetInMs } from '../../../common/utils/get_offset_in_ms';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
import { getBucketSize } from '../../lib/helpers/get_bucket_size';
import { Coordinate } from '../../../typings/timeseries';
import { Maybe } from '../../../typings/common';

export interface SessionsTimeseries {
currentPeriod: Coordinate[];
previousPeriod: Coordinate[];
currentPeriod: { timeseries: Coordinate[]; value: Maybe<number> };
previousPeriod: { timeseries: Coordinate[]; value: Maybe<number> };
}

interface Props {
Expand Down Expand Up @@ -61,13 +62,15 @@ async function getSessionTimeseries({
minBucketSize: 60,
});

const response = await apmEventClient.search('get_sessions_chart', {
const aggs = {
sessions: {
cardinality: { field: SESSION_ID },
},
};

const response = await apmEventClient.search('get_mobile_sessions', {
apm: {
events: [
ProcessorEvent.transaction,
ProcessorEvent.error,
ProcessorEvent.span,
],
events: [ProcessorEvent.transaction],
},
body: {
track_total_hits: false,
Expand All @@ -92,27 +95,28 @@ async function getSessionTimeseries({
min_doc_count: 0,
extended_bounds: { min: startWithOffset, max: endWithOffset },
},
aggs: {
sessions: {
cardinality: { field: SESSION_ID },
},
},
aggs,
},
...aggs,
},
},
});

return (
const timeseries =
response?.aggregations?.timeseries.buckets.map((bucket) => {
return {
x: bucket.key,
y: bucket.doc_count ?? 0,
y: bucket.sessions.value,
};
}) ?? []
);
}) ?? [];

return {
timeseries,
value: response.aggregations?.sessions?.value,
};
}

export async function getSessionsChart({
export async function getMobileSessions({
kuery,
apmEventClient,
serviceName,
Expand Down Expand Up @@ -143,7 +147,7 @@ export async function getSessionsChart({
end,
offset,
})
: [];
: { timeseries: [], value: null };

const [currentPeriod, previousPeriod] = await Promise.all([
currentPeriodPromise,
Expand All @@ -152,9 +156,12 @@ export async function getSessionsChart({

return {
currentPeriod,
previousPeriod: offsetPreviousPeriodCoordinates({
currentPeriodTimeseries: currentPeriod,
previousPeriodTimeseries: previousPeriod,
}),
previousPeriod: {
timeseries: offsetPreviousPeriodCoordinates({
currentPeriodTimeseries: currentPeriod.timeseries,
previousPeriodTimeseries: previousPeriod.timeseries,
}),
value: previousPeriod?.value,
},
};
}
Loading

0 comments on commit 199f115

Please sign in to comment.