forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Metrics UI] Filter out APM nodes from the inventory view (elastic#11…
…0300) (elastic#111074) * [Metrics UI] Filter out APM nodes from the inventory view * Update jest snapshots * Add tests for fs for filtering out APM nodes Co-authored-by: Zacqary Adam Xeper <[email protected]>
- Loading branch information
1 parent
8955d54
commit 38a1f7f
Showing
9 changed files
with
204 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/infra/server/lib/metrics/lib/__snapshots__/create_aggregations.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
x-pack/plugins/infra/server/routes/snapshot/lib/transform_metrics_ui_response.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { transformMetricsApiResponseToSnapshotResponse } from './transform_metrics_ui_response'; | ||
|
||
jest.mock('./apply_metadata_to_last_path', () => ({ | ||
applyMetadataToLastPath: (series: any) => [{ label: series.id }], | ||
})); | ||
|
||
const now = 1630597319235; | ||
|
||
describe('transformMetricsApiResponseToSnapshotResponse', () => { | ||
test('filters out nodes from APM which report no data', () => { | ||
const result = transformMetricsApiResponseToSnapshotResponse( | ||
{ | ||
// @ts-ignore | ||
metrics: [{ id: 'cpu' }], | ||
}, | ||
{ | ||
includeTimeseries: false, | ||
nodeType: 'host', | ||
}, | ||
{}, | ||
{ | ||
info: { | ||
interval: 60, | ||
}, | ||
series: [ | ||
{ | ||
metricsets: ['app'], | ||
id: 'apm-node-with-no-data', | ||
columns: [], | ||
rows: [ | ||
{ | ||
timestamp: now, | ||
cpu: null, | ||
}, | ||
], | ||
}, | ||
{ | ||
metricsets: ['app'], | ||
id: 'apm-node-with-data', | ||
columns: [], | ||
rows: [ | ||
{ | ||
timestamp: now, | ||
cpu: 1.0, | ||
}, | ||
], | ||
}, | ||
{ | ||
metricsets: ['cpu'], | ||
id: 'metricbeat-node', | ||
columns: [], | ||
rows: [ | ||
{ | ||
timestamp: now, | ||
cpu: 1.0, | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
); | ||
const nodeNames = result.nodes.map((n) => n.name); | ||
expect(nodeNames).toEqual(expect.arrayContaining(['metricbeat-node', 'apm-node-with-data'])); | ||
expect(nodeNames).not.toEqual(expect.arrayContaining(['apm-node'])); | ||
}); | ||
}); |
96 changes: 96 additions & 0 deletions
96
x-pack/plugins/infra/server/routes/snapshot/lib/transform_metrics_ui_response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { get, max, sum, last, isNumber } from 'lodash'; | ||
import { SnapshotMetricType } from '../../../../common/inventory_models/types'; | ||
import { | ||
MetricsAPIResponse, | ||
SnapshotNodeResponse, | ||
MetricsAPIRequest, | ||
MetricsExplorerColumnType, | ||
MetricsAPIRow, | ||
SnapshotRequest, | ||
SnapshotNodePath, | ||
SnapshotNodeMetric, | ||
SnapshotNode, | ||
} from '../../../../common/http_api'; | ||
import { META_KEY } from './constants'; | ||
import { InfraSource } from '../../../lib/sources'; | ||
import { applyMetadataToLastPath } from './apply_metadata_to_last_path'; | ||
|
||
const getMetricValue = (row: MetricsAPIRow) => { | ||
if (!isNumber(row.metric_0)) return null; | ||
const value = row.metric_0; | ||
return isFinite(value) ? value : null; | ||
}; | ||
|
||
const calculateMax = (rows: MetricsAPIRow[]) => { | ||
return max(rows.map(getMetricValue)) || 0; | ||
}; | ||
|
||
const calculateAvg = (rows: MetricsAPIRow[]): number => { | ||
return sum(rows.map(getMetricValue)) / rows.length || 0; | ||
}; | ||
|
||
const getLastValue = (rows: MetricsAPIRow[]) => { | ||
const row = last(rows); | ||
if (!row) return null; | ||
return getMetricValue(row); | ||
}; | ||
|
||
export const transformMetricsApiResponseToSnapshotResponse = ( | ||
options: MetricsAPIRequest, | ||
snapshotRequest: SnapshotRequest, | ||
source: InfraSource, | ||
metricsApiResponse: MetricsAPIResponse | ||
): SnapshotNodeResponse => { | ||
const nodes = metricsApiResponse.series | ||
.map((series) => { | ||
const node = { | ||
metrics: options.metrics | ||
.filter((m) => m.id !== META_KEY) | ||
.map((metric) => { | ||
const name = metric.id as SnapshotMetricType; | ||
const timeseries = { | ||
id: name, | ||
columns: [ | ||
{ name: 'timestamp', type: 'date' as MetricsExplorerColumnType }, | ||
{ name: 'metric_0', type: 'number' as MetricsExplorerColumnType }, | ||
], | ||
rows: series.rows.map((row) => { | ||
return { timestamp: row.timestamp, metric_0: get(row, metric.id, null) }; | ||
}), | ||
}; | ||
const maxValue = calculateMax(timeseries.rows); | ||
const avg = calculateAvg(timeseries.rows); | ||
const value = getLastValue(timeseries.rows); | ||
const nodeMetric: SnapshotNodeMetric = { name, max: maxValue, value, avg }; | ||
if (snapshotRequest.includeTimeseries) { | ||
nodeMetric.timeseries = timeseries; | ||
} | ||
return nodeMetric; | ||
}), | ||
path: | ||
series.keys?.map((key) => { | ||
return { value: key, label: key } as SnapshotNodePath; | ||
}) ?? [], | ||
name: '', | ||
}; | ||
|
||
const isNoData = node.metrics.every((m) => m.value === null); | ||
const isAPMNode = series.metricsets?.includes('app'); | ||
if (isNoData && isAPMNode) return null; | ||
|
||
const path = applyMetadataToLastPath(series, node, snapshotRequest, source); | ||
const lastPath = last(path); | ||
const name = lastPath?.label ?? 'N/A'; | ||
|
||
return { ...node, path, name }; | ||
}) | ||
.filter((n) => n !== null) as SnapshotNode[]; | ||
return { nodes, interval: `${metricsApiResponse.info.interval}s` }; | ||
}; |
88 changes: 0 additions & 88 deletions
88
x-pack/plugins/infra/server/routes/snapshot/lib/trasform_metrics_ui_response.ts
This file was deleted.
Oops, something went wrong.