Skip to content

Commit d8a0688

Browse files
[7.x] [APM] Service inventory redesign (#76744) (#77353)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 0eac8ae commit d8a0688

File tree

66 files changed

+1809
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1809
-440
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { getSeverity, severity } from './getSeverity';
7+
import { getSeverity, Severity } from './anomaly_detection';
88

99
describe('getSeverity', () => {
1010
describe('when score is undefined', () => {
@@ -15,25 +15,25 @@ describe('getSeverity', () => {
1515

1616
describe('when score < 25', () => {
1717
it('returns warning', () => {
18-
expect(getSeverity(10)).toEqual(severity.warning);
18+
expect(getSeverity(10)).toEqual(Severity.warning);
1919
});
2020
});
2121

2222
describe('when score is between 25 and 50', () => {
2323
it('returns minor', () => {
24-
expect(getSeverity(40)).toEqual(severity.minor);
24+
expect(getSeverity(40)).toEqual(Severity.minor);
2525
});
2626
});
2727

2828
describe('when score is between 50 and 75', () => {
2929
it('returns major', () => {
30-
expect(getSeverity(60)).toEqual(severity.major);
30+
expect(getSeverity(60)).toEqual(Severity.major);
3131
});
3232
});
3333

3434
describe('when score is 75 or more', () => {
3535
it('returns critical', () => {
36-
expect(getSeverity(100)).toEqual(severity.critical);
36+
expect(getSeverity(100)).toEqual(Severity.critical);
3737
});
3838
});
3939
});

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import { i18n } from '@kbn/i18n';
8+
import { EuiTheme } from '../../../legacy/common/eui_styled_components';
89

910
export interface ServiceAnomalyStats {
1011
transactionType?: string;
@@ -13,6 +14,82 @@ export interface ServiceAnomalyStats {
1314
jobId?: string;
1415
}
1516

17+
export enum Severity {
18+
critical = 'critical',
19+
major = 'major',
20+
minor = 'minor',
21+
warning = 'warning',
22+
}
23+
24+
// TODO: Replace with `getSeverity` from:
25+
// https://github.com/elastic/kibana/blob/0f964f66916480f2de1f4b633e5afafc08cf62a0/x-pack/plugins/ml/common/util/anomaly_utils.ts#L129
26+
export function getSeverity(score?: number) {
27+
if (typeof score !== 'number') {
28+
return undefined;
29+
} else if (score < 25) {
30+
return Severity.warning;
31+
} else if (score >= 25 && score < 50) {
32+
return Severity.minor;
33+
} else if (score >= 50 && score < 75) {
34+
return Severity.major;
35+
} else if (score >= 75) {
36+
return Severity.critical;
37+
} else {
38+
return undefined;
39+
}
40+
}
41+
42+
export function getSeverityColor(theme: EuiTheme, severity?: Severity) {
43+
switch (severity) {
44+
case Severity.warning:
45+
return theme.eui.euiColorVis0;
46+
case Severity.minor:
47+
case Severity.major:
48+
return theme.eui.euiColorVis5;
49+
case Severity.critical:
50+
return theme.eui.euiColorVis9;
51+
default:
52+
return;
53+
}
54+
}
55+
56+
export function getSeverityLabel(severity?: Severity) {
57+
switch (severity) {
58+
case Severity.critical:
59+
return i18n.translate(
60+
'xpack.apm.servicesTable.serviceHealthStatus.critical',
61+
{
62+
defaultMessage: 'Critical',
63+
}
64+
);
65+
66+
case Severity.major:
67+
case Severity.minor:
68+
return i18n.translate(
69+
'xpack.apm.servicesTable.serviceHealthStatus.warning',
70+
{
71+
defaultMessage: 'Warning',
72+
}
73+
);
74+
75+
case Severity.warning:
76+
return i18n.translate(
77+
'xpack.apm.servicesTable.serviceHealthStatus.healthy',
78+
{
79+
defaultMessage: 'Healthy',
80+
}
81+
);
82+
83+
default:
84+
return i18n.translate(
85+
'xpack.apm.servicesTable.serviceHealthStatus.unknown',
86+
{
87+
defaultMessage: 'Unknown',
88+
}
89+
);
90+
}
91+
}
92+
1693
export const ML_ERRORS = {
1794
INVALID_LICENSE: i18n.translate(
1895
'xpack.apm.anomaly_detection.error.invalid_license',

x-pack/plugins/apm/common/service_map.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { License } from '../../licensing/common/license';
88
import * as serviceMap from './service_map';
99

1010
describe('service map helpers', () => {
11-
describe('isValidPlatinumLicense', () => {
11+
describe('isActivePlatinumLicense', () => {
1212
describe('with an expired license', () => {
1313
it('returns false', () => {
1414
const license = new License({
@@ -22,7 +22,7 @@ describe('service map helpers', () => {
2222
signature: 'test signature',
2323
});
2424

25-
expect(serviceMap.isValidPlatinumLicense(license)).toEqual(false);
25+
expect(serviceMap.isActivePlatinumLicense(license)).toEqual(false);
2626
});
2727
});
2828

@@ -39,7 +39,7 @@ describe('service map helpers', () => {
3939
signature: 'test signature',
4040
});
4141

42-
expect(serviceMap.isValidPlatinumLicense(license)).toEqual(false);
42+
expect(serviceMap.isActivePlatinumLicense(license)).toEqual(false);
4343
});
4444
});
4545

@@ -56,7 +56,7 @@ describe('service map helpers', () => {
5656
signature: 'test signature',
5757
});
5858

59-
expect(serviceMap.isValidPlatinumLicense(license)).toEqual(true);
59+
expect(serviceMap.isActivePlatinumLicense(license)).toEqual(true);
6060
});
6161
});
6262

@@ -73,7 +73,7 @@ describe('service map helpers', () => {
7373
signature: 'test signature',
7474
});
7575

76-
expect(serviceMap.isValidPlatinumLicense(license)).toEqual(true);
76+
expect(serviceMap.isActivePlatinumLicense(license)).toEqual(true);
7777
});
7878
});
7979

@@ -90,7 +90,7 @@ describe('service map helpers', () => {
9090
signature: 'test signature',
9191
});
9292

93-
expect(serviceMap.isValidPlatinumLicense(license)).toEqual(true);
93+
expect(serviceMap.isActivePlatinumLicense(license)).toEqual(true);
9494
});
9595
});
9696
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface ServiceNodeStats {
4646
avgErrorRate: number | null;
4747
}
4848

49-
export function isValidPlatinumLicense(license: ILicense) {
49+
export function isActivePlatinumLicense(license: ILicense) {
5050
return license.isActive && license.hasAtLeast('platinum');
5151
}
5252

x-pack/plugins/apm/public/components/app/ServiceMap/Popover/AnomalyDetection.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ import { useTheme } from '../../../../hooks/useTheme';
1818
import { fontSize, px } from '../../../../style/variables';
1919
import { asInteger, asDuration } from '../../../../utils/formatters';
2020
import { MLJobLink } from '../../../shared/Links/MachineLearningLinks/MLJobLink';
21-
import { getSeverityColor, popoverWidth } from '../cytoscapeOptions';
21+
import { popoverWidth } from '../cytoscapeOptions';
2222
import { TRANSACTION_REQUEST } from '../../../../../common/transaction_types';
23-
import { ServiceAnomalyStats } from '../../../../../common/anomaly_detection';
24-
import { getSeverity } from './getSeverity';
23+
import {
24+
getSeverity,
25+
getSeverityColor,
26+
ServiceAnomalyStats,
27+
} from '../../../../../common/anomaly_detection';
2528

2629
const HealthStatusTitle = styled(EuiTitle)`
2730
display: inline;

x-pack/plugins/apm/public/components/app/ServiceMap/Popover/getSeverity.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

x-pack/plugins/apm/public/components/app/ServiceMap/cytoscapeOptions.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,15 @@ import {
1111
} from '../../../../common/elasticsearch_fieldnames';
1212
import { EuiTheme } from '../../../../../observability/public';
1313
import { defaultIcon, iconForNode } from './icons';
14-
import { ServiceAnomalyStats } from '../../../../common/anomaly_detection';
15-
import { severity, getSeverity } from './Popover/getSeverity';
14+
import {
15+
getSeverity,
16+
getSeverityColor,
17+
ServiceAnomalyStats,
18+
Severity,
19+
} from '../../../../common/anomaly_detection';
1620

1721
export const popoverWidth = 280;
1822

19-
export function getSeverityColor(theme: EuiTheme, nodeSeverity?: string) {
20-
switch (nodeSeverity) {
21-
case severity.warning:
22-
return theme.eui.euiColorVis0;
23-
case severity.minor:
24-
case severity.major:
25-
return theme.eui.euiColorVis5;
26-
case severity.critical:
27-
return theme.eui.euiColorVis9;
28-
default:
29-
return;
30-
}
31-
}
32-
3323
function getNodeSeverity(el: cytoscape.NodeSingular) {
3424
const serviceAnomalyStats: ServiceAnomalyStats | undefined = el.data(
3525
'serviceAnomalyStats'
@@ -60,7 +50,7 @@ const getBorderStyle: cytoscape.Css.MapperFunction<
6050
cytoscape.Css.LineStyle
6151
> = (el: cytoscape.NodeSingular) => {
6252
const nodeSeverity = getNodeSeverity(el);
63-
if (nodeSeverity === severity.critical) {
53+
if (nodeSeverity === Severity.critical) {
6454
return 'double';
6555
} else {
6656
return 'solid';
@@ -70,9 +60,9 @@ const getBorderStyle: cytoscape.Css.MapperFunction<
7060
function getBorderWidth(el: cytoscape.NodeSingular) {
7161
const nodeSeverity = getNodeSeverity(el);
7262

73-
if (nodeSeverity === severity.minor || nodeSeverity === severity.major) {
63+
if (nodeSeverity === Severity.minor || nodeSeverity === Severity.major) {
7464
return 4;
75-
} else if (nodeSeverity === severity.critical) {
65+
} else if (nodeSeverity === Severity.critical) {
7666
return 8;
7767
} else {
7868
return 4;

x-pack/plugins/apm/public/components/app/ServiceMap/icons.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,29 @@
55
*/
66

77
import cytoscape from 'cytoscape';
8-
import { getNormalizedAgentName } from '../../../../common/agent_name';
98
import {
109
AGENT_NAME,
1110
SPAN_SUBTYPE,
1211
SPAN_TYPE,
1312
} from '../../../../common/elasticsearch_fieldnames';
1413
import awsIcon from './icons/aws.svg';
1514
import cassandraIcon from './icons/cassandra.svg';
16-
import darkIcon from './icons/dark.svg';
1715
import databaseIcon from './icons/database.svg';
1816
import defaultIconImport from './icons/default.svg';
1917
import documentsIcon from './icons/documents.svg';
20-
import dotNetIcon from './icons/dot-net.svg';
2118
import elasticsearchIcon from './icons/elasticsearch.svg';
2219
import globeIcon from './icons/globe.svg';
23-
import goIcon from './icons/go.svg';
2420
import graphqlIcon from './icons/graphql.svg';
2521
import grpcIcon from './icons/grpc.svg';
2622
import handlebarsIcon from './icons/handlebars.svg';
27-
import javaIcon from './icons/java.svg';
2823
import kafkaIcon from './icons/kafka.svg';
2924
import mongodbIcon from './icons/mongodb.svg';
3025
import mysqlIcon from './icons/mysql.svg';
31-
import nodeJsIcon from './icons/nodejs.svg';
32-
import phpIcon from './icons/php.svg';
3326
import postgresqlIcon from './icons/postgresql.svg';
34-
import pythonIcon from './icons/python.svg';
3527
import redisIcon from './icons/redis.svg';
36-
import rubyIcon from './icons/ruby.svg';
37-
import rumJsIcon from './icons/rumjs.svg';
3828
import websocketIcon from './icons/websocket.svg';
29+
import javaIcon from '../../shared/AgentIcon/icons/java.svg';
30+
import { getAgentIcon } from '../../shared/AgentIcon/get_agent_icon';
3931

4032
export const defaultIcon = defaultIconImport;
4133

@@ -74,23 +66,6 @@ const typeIcons: { [key: string]: { [key: string]: string } } = {
7466
},
7567
};
7668

77-
const agentIcons: { [key: string]: string } = {
78-
dark: darkIcon,
79-
dotnet: dotNetIcon,
80-
go: goIcon,
81-
java: javaIcon,
82-
'js-base': rumJsIcon,
83-
nodejs: nodeJsIcon,
84-
php: phpIcon,
85-
python: pythonIcon,
86-
ruby: rubyIcon,
87-
};
88-
89-
function getAgentIcon(agentName?: string) {
90-
const normalizedAgentName = getNormalizedAgentName(agentName);
91-
return normalizedAgentName && agentIcons[normalizedAgentName];
92-
}
93-
9469
function getSpanIcon(type?: string, subtype?: string) {
9570
if (!type) {
9671
return;

x-pack/plugins/apm/public/components/app/ServiceMap/icons/dark.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
99
import { useTheme } from '../../../hooks/useTheme';
1010
import {
1111
invalidLicenseMessage,
12-
isValidPlatinumLicense,
12+
isActivePlatinumLicense,
1313
} from '../../../../common/service_map';
1414
import { useFetcher } from '../../../hooks/useFetcher';
1515
import { useLicense } from '../../../hooks/useLicense';
@@ -36,7 +36,7 @@ export function ServiceMap({ serviceName }: ServiceMapProps) {
3636

3737
const { data = { elements: [] } } = useFetcher(() => {
3838
// When we don't have a license or a valid license, don't make the request.
39-
if (!license || !isValidPlatinumLicense(license)) {
39+
if (!license || !isActivePlatinumLicense(license)) {
4040
return;
4141
}
4242

@@ -66,7 +66,7 @@ export function ServiceMap({ serviceName }: ServiceMapProps) {
6666
return null;
6767
}
6868

69-
return isValidPlatinumLicense(license) ? (
69+
return isActivePlatinumLicense(license) ? (
7070
<div
7171
style={{
7272
height: height - parseInt(theme.eui.gutterTypes.gutterLarge, 10),

0 commit comments

Comments
 (0)