Skip to content

Commit

Permalink
APM observability fetch data
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jun 23, 2020
1 parent be59683 commit 679ccd7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 38 deletions.
42 changes: 22 additions & 20 deletions x-pack/plugins/apm/public/services/rest/observability_dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,56 @@
*/

import { i18n } from '@kbn/i18n';
import { FetchData } from '../../../../observability/public/typings/data_handler';
import { sum } from 'lodash';
import {
ApmFetchDataResponse,
FetchData,
} from '../../../../observability/public/typings/data_handler';
import { callApmApi } from './createCallApmApi';

export const fetchData: FetchData = async ({
export const fetchData: FetchData<ApmFetchDataResponse> = async ({
startTime,
endTime,
bucketSize,
}) => {
const serviceCountPromise = callApmApi({
pathname: '/api/apm/observability-dashboard/service-count',
const data = await callApmApi({
pathname: '/api/apm/observability-dashboard',
params: { query: { start: startTime, end: endTime, bucketSize } },
});

const transactionCoordinatesPromise = callApmApi({
pathname: '/api/apm/observability-dashboard/transactions',
params: { query: { start: startTime, end: endTime, bucketSize } },
});

const [serviceCount, transactionCoordinates] = await Promise.all([
serviceCountPromise,
transactionCoordinatesPromise,
]);
const { serviceCount, transactionCoordinates } = data;

return {
title: i18n.translate('xpack.apm.observabilityDashboard.title', {
defaultMessage: 'APM',
}),
appLink: '/app/apm',
stats: [
{
stats: {
services: {
label: i18n.translate(
'xpack.apm.observabilityDashboard.stats.services',
{ defaultMessage: 'Services' }
),
value: serviceCount,
},
],
series: [
{
key: 'transactions',
transactions: {
label: i18n.translate(
'xpack.apm.observabilityDashboard.stats.transactions',
{ defaultMessage: 'Transactions' }
),
value: sum(transactionCoordinates.map((coordinates) => coordinates.y)),
},
},
series: {
transactions: {
label: i18n.translate(
'xpack.apm.observabilityDashboard.chart.transactions',
{ defaultMessage: 'Transactions' }
),
color: 'euiColorVis1',
coordinates: transactionCoordinates,
},
],
},
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { rangeFilter } from '../../../common/utils/range_filter';
import { SERVICE_NAME } from '../../../common/elasticsearch_fieldnames';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { rangeFilter } from '../helpers/range_filter';

export async function getServiceCount({
setup,
Expand Down
6 changes: 2 additions & 4 deletions x-pack/plugins/apm/server/routes/create_apm_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ import {
} from './rum_client';
import {
observabilityDashboardHasDataRoute,
observabilityDashboardServiceCountRoute,
observabilityDashboardTransactionsRoute,
observabilityDashboardDataRoute,
} from './observability_dashboard';

const createApmApi = () => {
Expand Down Expand Up @@ -169,8 +168,7 @@ const createApmApi = () => {

// Observability dashboard
.add(observabilityDashboardHasDataRoute)
.add(observabilityDashboardServiceCountRoute)
.add(observabilityDashboardTransactionsRoute);
.add(observabilityDashboardDataRoute);

return api;
};
Expand Down
19 changes: 6 additions & 13 deletions x-pack/plugins/apm/server/routes/observability_dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,20 @@ export const observabilityDashboardHasDataRoute = createRoute(() => ({
},
}));

export const observabilityDashboardServiceCountRoute = createRoute(() => ({
path: '/api/apm/observability-dashboard/service-count',
params: {
query: t.intersection([rangeRt, t.type({ bucketSize: t.string })]),
},
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
return await getServiceCount({ setup });
},
}));
export const observabilityDashboardTransactionsRoute = createRoute(() => ({
path: '/api/apm/observability-dashboard/transactions',
export const observabilityDashboardDataRoute = createRoute(() => ({
path: '/api/apm/observability-dashboard',
params: {
query: t.intersection([rangeRt, t.type({ bucketSize: t.string })]),
},
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { bucketSize } = context.params.query;
return await getTransactionCoordinates({
const serviceCount = await getServiceCount({ setup });
const transactionCoordinates = await getTransactionCoordinates({
setup,
bucketSize,
});

return { serviceCount, transactionCoordinates };
},
}));

0 comments on commit 679ccd7

Please sign in to comment.