Skip to content

Commit e5a5263

Browse files
committed
Add tests for fs for filtering out APM nodes
1 parent 5b009a6 commit e5a5263

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

x-pack/plugins/infra/server/routes/snapshot/lib/get_nodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ESSearchClient } from '../../../lib/metrics/types';
1010
import { InfraSource } from '../../../lib/sources';
1111
import { transformRequestToMetricsAPIRequest } from './transform_request_to_metrics_api_request';
1212
import { queryAllData } from './query_all_data';
13-
import { transformMetricsApiResponseToSnapshotResponse } from './trasform_metrics_ui_response';
13+
import { transformMetricsApiResponseToSnapshotResponse } from './transform_metrics_ui_response';
1414
import { copyMissingMetrics } from './copy_missing_metrics';
1515
import { LogQueryFields } from '../../../services/log_queries/get_log_query_fields';
1616

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { transformMetricsApiResponseToSnapshotResponse } from './transform_metrics_ui_response';
9+
10+
jest.mock('./apply_metadata_to_last_path', () => ({
11+
applyMetadataToLastPath: (series: any) => [{ label: series.id }],
12+
}));
13+
14+
const now = 1630597319235;
15+
16+
describe('transformMetricsApiResponseToSnapshotResponse', () => {
17+
test('filters out nodes from APM which report no data', () => {
18+
const result = transformMetricsApiResponseToSnapshotResponse(
19+
{
20+
// @ts-ignore
21+
metrics: [{ id: 'cpu' }],
22+
},
23+
{
24+
includeTimeseries: false,
25+
nodeType: 'host',
26+
},
27+
{},
28+
{
29+
info: {
30+
interval: 60,
31+
},
32+
series: [
33+
{
34+
metricsets: ['app'],
35+
id: 'apm-node-with-no-data',
36+
columns: [],
37+
rows: [
38+
{
39+
timestamp: now,
40+
cpu: null,
41+
},
42+
],
43+
},
44+
{
45+
metricsets: ['app'],
46+
id: 'apm-node-with-data',
47+
columns: [],
48+
rows: [
49+
{
50+
timestamp: now,
51+
cpu: 1.0,
52+
},
53+
],
54+
},
55+
{
56+
metricsets: ['cpu'],
57+
id: 'metricbeat-node',
58+
columns: [],
59+
rows: [
60+
{
61+
timestamp: now,
62+
cpu: 1.0,
63+
},
64+
],
65+
},
66+
],
67+
}
68+
);
69+
const nodeNames = result.nodes.map((n) => n.name);
70+
expect(nodeNames).toEqual(expect.arrayContaining(['metricbeat-node', 'apm-node-with-data']));
71+
expect(nodeNames).not.toEqual(expect.arrayContaining(['apm-node']));
72+
});
73+
});

x-pack/plugins/infra/server/routes/snapshot/lib/trasform_metrics_ui_response.ts renamed to x-pack/plugins/infra/server/routes/snapshot/lib/transform_metrics_ui_response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const transformMetricsApiResponseToSnapshotResponse = (
8787

8888
const path = applyMetadataToLastPath(series, node, snapshotRequest, source);
8989
const lastPath = last(path);
90-
const name = (lastPath && lastPath.label) || 'N/A';
90+
const name = lastPath?.label ?? 'N/A';
9191

9292
return { ...node, path, name };
9393
})

0 commit comments

Comments
 (0)