Skip to content

Commit ba48a9f

Browse files
[RUM Dashboard] Added service name filter (#70349)
Co-authored-by: Elastic Machine <[email protected]>
1 parent 3305b22 commit ba48a9f

File tree

8 files changed

+145
-16
lines changed

8 files changed

+145
-16
lines changed

x-pack/plugins/apm/common/agent_name.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ export function isAgentName(agentName: string): agentName is AgentName {
3030
return AGENT_NAMES.includes(agentName as AgentName);
3131
}
3232

33+
export const RUM_AGENTS = ['js-base', 'rum-js'];
34+
3335
export function isRumAgentName(
34-
agentName: string | undefined
36+
agentName?: string
3537
): agentName is 'js-base' | 'rum-js' {
36-
return agentName === 'js-base' || agentName === 'rum-js';
38+
return RUM_AGENTS.includes(agentName!);
3739
}
3840

3941
export function isJavaAgentName(

x-pack/plugins/apm/public/components/app/RumDashboard/ClientMetrics/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ const ClFlexGroup = styled(EuiFlexGroup)`
2222
export function ClientMetrics() {
2323
const { urlParams, uiFilters } = useUrlParams();
2424

25-
const { start, end } = urlParams;
25+
const { start, end, serviceName } = urlParams;
2626

2727
const { data, status } = useFetcher(
2828
(callApmApi) => {
29-
if (start && end) {
29+
if (start && end && serviceName) {
3030
return callApmApi({
3131
pathname: '/api/apm/rum/client-metrics',
3232
params: {
@@ -35,7 +35,7 @@ export function ClientMetrics() {
3535
});
3636
}
3737
},
38-
[start, end, uiFilters]
38+
[start, end, serviceName, uiFilters]
3939
);
4040

4141
const STAT_STYLE = { width: '240px' };

x-pack/plugins/apm/public/components/app/RumDashboard/PageLoadDistribution/index.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface PercentileRange {
2727
export const PageLoadDistribution = () => {
2828
const { urlParams, uiFilters } = useUrlParams();
2929

30-
const { start, end } = urlParams;
30+
const { start, end, serviceName } = urlParams;
3131

3232
const [percentileRange, setPercentileRange] = useState<PercentileRange>({
3333
min: null,
@@ -38,7 +38,7 @@ export const PageLoadDistribution = () => {
3838

3939
const { data, status } = useFetcher(
4040
(callApmApi) => {
41-
if (start && end) {
41+
if (start && end && serviceName) {
4242
return callApmApi({
4343
pathname: '/api/apm/rum-client/page-load-distribution',
4444
params: {
@@ -57,7 +57,14 @@ export const PageLoadDistribution = () => {
5757
});
5858
}
5959
},
60-
[end, start, uiFilters, percentileRange.min, percentileRange.max]
60+
[
61+
end,
62+
start,
63+
serviceName,
64+
uiFilters,
65+
percentileRange.min,
66+
percentileRange.max,
67+
]
6168
);
6269

6370
const onPercentileChange = (min: number, max: number) => {

x-pack/plugins/apm/public/components/app/RumDashboard/PageLoadDistribution/use_breakdowns.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ interface Props {
1717
export const useBreakdowns = ({ percentileRange, field, value }: Props) => {
1818
const { urlParams, uiFilters } = useUrlParams();
1919

20-
const { start, end } = urlParams;
20+
const { start, end, serviceName } = urlParams;
2121

2222
const { min: minP, max: maxP } = percentileRange ?? {};
2323

2424
return useFetcher(
2525
(callApmApi) => {
26-
if (start && end && field && value) {
26+
if (start && end && serviceName && field && value) {
2727
return callApmApi({
2828
pathname: '/api/apm/rum-client/page-load-distribution/breakdown',
2929
params: {
@@ -43,6 +43,6 @@ export const useBreakdowns = ({ percentileRange, field, value }: Props) => {
4343
});
4444
}
4545
},
46-
[end, start, uiFilters, field, value, minP, maxP]
46+
[end, start, serviceName, uiFilters, field, value, minP, maxP]
4747
);
4848
};

x-pack/plugins/apm/public/components/app/RumDashboard/PageViewsTrend/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import { BreakdownItem } from '../../../../../typings/ui_filters';
1616
export const PageViewsTrend = () => {
1717
const { urlParams, uiFilters } = useUrlParams();
1818

19-
const { start, end } = urlParams;
19+
const { start, end, serviceName } = urlParams;
2020

2121
const [breakdowns, setBreakdowns] = useState<BreakdownItem[]>([]);
2222

2323
const { data, status } = useFetcher(
2424
(callApmApi) => {
25-
if (start && end) {
25+
if (start && end && serviceName) {
2626
return callApmApi({
2727
pathname: '/api/apm/rum-client/page-view-trends',
2828
params: {
@@ -40,7 +40,7 @@ export const PageViewsTrend = () => {
4040
});
4141
}
4242
},
43-
[end, start, uiFilters, breakdowns]
43+
[end, start, serviceName, uiFilters, breakdowns]
4444
);
4545

4646
const onBreakdownChange = (values: BreakdownItem[]) => {

x-pack/plugins/apm/public/components/app/RumDashboard/index.tsx

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui';
7+
import {
8+
EuiFlexGroup,
9+
EuiFlexItem,
10+
EuiHorizontalRule,
11+
EuiSpacer,
12+
} from '@elastic/eui';
813
import React, { useMemo } from 'react';
914
import { useTrackPageview } from '../../../../../observability/public';
1015
import { LocalUIFilters } from '../../shared/LocalUIFilters';
1116
import { PROJECTION } from '../../../../common/projections/typings';
1217
import { RumDashboard } from './RumDashboard';
18+
import { ServiceNameFilter } from '../../shared/LocalUIFilters/ServiceNameFilter';
19+
import { useUrlParams } from '../../../hooks/useUrlParams';
20+
import { useFetcher } from '../../../hooks/useFetcher';
21+
import { RUM_AGENTS } from '../../../../common/agent_name';
1322

1423
export function RumOverview() {
1524
useTrackPageview({ app: 'apm', path: 'rum_overview' });
@@ -24,12 +33,42 @@ export function RumOverview() {
2433
return config;
2534
}, []);
2635

36+
const {
37+
urlParams: { start, end },
38+
} = useUrlParams();
39+
40+
const { data } = useFetcher(
41+
(callApmApi) => {
42+
if (start && end) {
43+
return callApmApi({
44+
pathname: '/api/apm/services',
45+
params: {
46+
query: {
47+
start,
48+
end,
49+
uiFilters: JSON.stringify({ agentName: RUM_AGENTS }),
50+
},
51+
},
52+
});
53+
}
54+
},
55+
[start, end]
56+
);
57+
2758
return (
2859
<>
2960
<EuiSpacer />
3061
<EuiFlexGroup>
3162
<EuiFlexItem grow={1}>
32-
<LocalUIFilters {...localUIFiltersConfig} showCount={true} />
63+
<LocalUIFilters {...localUIFiltersConfig} showCount={true}>
64+
<ServiceNameFilter
65+
serviceNames={
66+
data?.items?.map((service) => service.serviceName) ?? []
67+
}
68+
/>
69+
<EuiSpacer size="xl" />
70+
<EuiHorizontalRule margin="none" />
71+
</LocalUIFilters>
3372
</EuiFlexItem>
3473
<EuiFlexItem grow={7}>
3574
<RumDashboard />
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React, { useEffect } from 'react';
8+
import {
9+
EuiTitle,
10+
EuiHorizontalRule,
11+
EuiSpacer,
12+
EuiSelect,
13+
} from '@elastic/eui';
14+
import { i18n } from '@kbn/i18n';
15+
import { useUrlParams } from '../../../../hooks/useUrlParams';
16+
import { history } from '../../../../utils/history';
17+
import { fromQuery, toQuery } from '../../Links/url_helpers';
18+
19+
interface Props {
20+
serviceNames: string[];
21+
}
22+
23+
const ServiceNameFilter = ({ serviceNames }: Props) => {
24+
const {
25+
urlParams: { serviceName },
26+
} = useUrlParams();
27+
28+
const options = serviceNames.map((type) => ({
29+
text: type,
30+
value: type,
31+
}));
32+
33+
const updateServiceName = (serviceN: string) => {
34+
const newLocation = {
35+
...history.location,
36+
search: fromQuery({
37+
...toQuery(history.location.search),
38+
serviceName: serviceN,
39+
}),
40+
};
41+
history.push(newLocation);
42+
};
43+
44+
useEffect(() => {
45+
if (!serviceName && serviceNames.length > 0) {
46+
updateServiceName(serviceNames[0]);
47+
}
48+
}, [serviceNames, serviceName]);
49+
50+
return (
51+
<>
52+
<EuiTitle size="xxxs" textTransform="uppercase">
53+
<h4>
54+
{i18n.translate('xpack.apm.localFilters.titles.serviceName', {
55+
defaultMessage: 'Service name',
56+
})}
57+
</h4>
58+
</EuiTitle>
59+
<EuiSpacer size="s" />
60+
<EuiHorizontalRule margin="none" />
61+
<EuiSpacer size="s" />
62+
<EuiSelect
63+
options={options}
64+
value={serviceName}
65+
compressed={true}
66+
onChange={(event) => {
67+
updateServiceName(event.target.value);
68+
}}
69+
/>
70+
</>
71+
);
72+
};
73+
74+
export { ServiceNameFilter };

x-pack/plugins/apm/server/lib/ui_filters/local_ui_filters/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
USER_AGENT_DEVICE,
1717
USER_AGENT_OS,
1818
CLIENT_GEO_COUNTRY_ISO_CODE,
19+
SERVICE_NAME,
1920
} from '../../../../common/elasticsearch_fieldnames';
2021

2122
const filtersByName = {
@@ -85,6 +86,12 @@ const filtersByName = {
8586
}),
8687
fieldName: USER_AGENT_OS,
8788
},
89+
serviceName: {
90+
title: i18n.translate('xpack.apm.localFilters.titles.serviceName', {
91+
defaultMessage: 'Service name',
92+
}),
93+
fieldName: SERVICE_NAME,
94+
},
8895
};
8996

9097
export type LocalUIFilterName = keyof typeof filtersByName;

0 commit comments

Comments
 (0)