Skip to content

Commit

Permalink
added rum service
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Jul 3, 2020
1 parent bbda3f9 commit a483d99
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function RumOverview() {
(callApmApi) => {
if (start && end) {
return callApmApi({
pathname: '/api/apm/services',
pathname: '/api/apm/rum-client/services',
params: {
query: {
start,
Expand All @@ -68,11 +68,7 @@ export function RumOverview() {
<LocalUIFilters {...localUIFiltersConfig} showCount={true}>
{!isRumServiceRoute && (
<>
<ServiceNameFilter
serviceNames={
data?.items?.map((service) => service.serviceName) ?? []
}
/>
<ServiceNameFilter serviceNames={data ?? []} />
<EuiSpacer size="xl" />
<EuiHorizontalRule margin="none" />{' '}
</>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions x-pack/plugins/apm/server/lib/rum_client/get_rum_services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { getRumOverviewProjection } from '../../../common/projections/rum_overview';
import { mergeProjection } from '../../../common/projections/util/merge_projection';
import {
Setup,
SetupTimeRange,
SetupUIFilters,
} from '../helpers/setup_request';

export async function getRumServices({
setup,
}: {
setup: Setup & SetupTimeRange & SetupUIFilters;
}) {
const projection = getRumOverviewProjection({
setup,
});

const params = mergeProjection(projection, {
body: {
size: 0,
query: {
bool: projection.body.query.bool,
},
aggs: {
services: {
terms: {
field: 'service.name',
size: 1000,
},
},
},
},
});

const { client } = setup;

const response = await client.search(params);

const result = response.aggregations?.services.buckets ?? [];

return result.map(({ key }) => key);
}
10 changes: 10 additions & 0 deletions x-pack/plugins/apm/server/lib/rum_client/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { getClientMetrics } from './get_client_metrics';
import { getPageViewTrends } from './get_page_view_trends';
import { getPageLoadDistribution } from './get_page_load_distribution';
import { getRumServices } from './get_rum_services';

describe('rum client dashboard queries', () => {
let mock: SearchParamsMock;
Expand Down Expand Up @@ -49,4 +50,13 @@ describe('rum client dashboard queries', () => {
);
expect(mock.params).toMatchSnapshot();
});

it('fetches rum services', async () => {
mock = await inspectSearchParams((setup) =>
getRumServices({
setup,
})
);
expect(mock.params).toMatchSnapshot();
});
});
2 changes: 2 additions & 0 deletions x-pack/plugins/apm/server/routes/create_apm_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import {
rumPageViewsTrendRoute,
rumPageLoadDistributionRoute,
rumPageLoadDistBreakdownRoute,
rumServicesRoute,
} from './rum_client';
import {
observabilityDashboardHasDataRoute,
Expand Down Expand Up @@ -167,6 +168,7 @@ const createApmApi = () => {
.add(rumPageLoadDistributionRoute)
.add(rumPageLoadDistBreakdownRoute)
.add(rumClientMetricsRoute)
.add(rumServicesRoute)

// Observability dashboard
.add(observabilityDashboardHasDataRoute)
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/apm/server/routes/rum_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { rangeRt, uiFiltersRt } from './default_api_types';
import { getPageViewTrends } from '../lib/rum_client/get_page_view_trends';
import { getPageLoadDistribution } from '../lib/rum_client/get_page_load_distribution';
import { getPageLoadDistBreakdown } from '../lib/rum_client/get_pl_dist_breakdown';
import { getRumServices } from '../lib/rum_client/get_rum_services';

export const percentileRangeRt = t.partial({
minPercentile: t.string,
Expand Down Expand Up @@ -91,3 +92,15 @@ export const rumPageViewsTrendRoute = createRoute(() => ({
return getPageViewTrends({ setup, breakdowns });
},
}));

export const rumServicesRoute = createRoute(() => ({
path: '/api/apm/rum-client/services',
params: {
query: t.intersection([uiFiltersRt, rangeRt]),
},
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

return getRumServices({ setup });
},
}));

0 comments on commit a483d99

Please sign in to comment.