Skip to content

Commit b70966a

Browse files
committed
[Metrics UI] Filter out APM nodes from the inventory view
1 parent 48d8944 commit b70966a

File tree

5 files changed

+63
-38
lines changed

5 files changed

+63
-38
lines changed

x-pack/plugins/infra/common/http_api/metrics_api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export const MetricsAPISeriesRT = rt.intersection([
7878
]);
7979

8080
export const MetricsAPIResponseRT = rt.type({
81-
series: rt.array(MetricsAPISeriesRT),
81+
series: rt.array(
82+
rt.intersection([MetricsAPISeriesRT, rt.partial({ metricsets: rt.array(rt.string) })])
83+
),
8284
info: MetricsAPIPageInfoRT,
8385
});
8486

x-pack/plugins/infra/server/lib/metrics/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ export const query = async (
9191
return {
9292
series: groupings.buckets.map((bucket) => {
9393
const keys = Object.values(bucket.key);
94-
return convertHistogramBucketsToTimeseries(
94+
const metricsetNames = bucket.metricsets.buckets.map((m) => m.key);
95+
const timeseries = convertHistogramBucketsToTimeseries(
9596
keys,
9697
options,
9798
bucket.histogram.buckets,
9899
bucketSize * 1000
99100
);
101+
return { ...timeseries, metricsets: metricsetNames };
100102
}),
101103
info: {
102104
afterKey: returnAfterKey ? afterKey : null,

x-pack/plugins/infra/server/lib/metrics/lib/create_aggregations.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export const createAggregations = (options: MetricsAPIRequest) => {
2525
},
2626
aggregations: createMetricsAggregations(options),
2727
},
28+
metricsets: {
29+
terms: {
30+
field: 'metricset.name',
31+
},
32+
},
2833
};
2934

3035
if (Array.isArray(options.groupBy) && options.groupBy.length) {

x-pack/plugins/infra/server/lib/metrics/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ export const HistogramResponseRT = rt.type({
6363
histogram: rt.type({
6464
buckets: rt.array(HistogramBucketRT),
6565
}),
66+
metricsets: rt.type({
67+
buckets: rt.array(
68+
rt.type({
69+
key: rt.string,
70+
doc_count: rt.number,
71+
})
72+
),
73+
}),
6674
});
6775

6876
const GroupingBucketRT = rt.intersection([

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

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
SnapshotRequest,
1717
SnapshotNodePath,
1818
SnapshotNodeMetric,
19+
SnapshotNode,
1920
} from '../../../../common/http_api';
2021
import { META_KEY } from './constants';
2122
import { InfraSource } from '../../../lib/sources';
@@ -47,42 +48,49 @@ export const transformMetricsApiResponseToSnapshotResponse = (
4748
source: InfraSource,
4849
metricsApiResponse: MetricsAPIResponse
4950
): SnapshotNodeResponse => {
50-
const nodes = metricsApiResponse.series.map((series) => {
51-
const node = {
52-
metrics: options.metrics
53-
.filter((m) => m.id !== META_KEY)
54-
.map((metric) => {
55-
const name = metric.id as SnapshotMetricType;
56-
const timeseries = {
57-
id: name,
58-
columns: [
59-
{ name: 'timestamp', type: 'date' as MetricsExplorerColumnType },
60-
{ name: 'metric_0', type: 'number' as MetricsExplorerColumnType },
61-
],
62-
rows: series.rows.map((row) => {
63-
return { timestamp: row.timestamp, metric_0: get(row, metric.id, null) };
64-
}),
65-
};
66-
const maxValue = calculateMax(timeseries.rows);
67-
const avg = calculateAvg(timeseries.rows);
68-
const value = getLastValue(timeseries.rows);
69-
const nodeMetric: SnapshotNodeMetric = { name, max: maxValue, value, avg };
70-
if (snapshotRequest.includeTimeseries) {
71-
nodeMetric.timeseries = timeseries;
72-
}
73-
return nodeMetric;
74-
}),
75-
path:
76-
series.keys?.map((key) => {
77-
return { value: key, label: key } as SnapshotNodePath;
78-
}) ?? [],
79-
name: '',
80-
};
51+
const nodes = metricsApiResponse.series
52+
.map((series) => {
53+
const node = {
54+
metrics: options.metrics
55+
.filter((m) => m.id !== META_KEY)
56+
.map((metric) => {
57+
const name = metric.id as SnapshotMetricType;
58+
const timeseries = {
59+
id: name,
60+
columns: [
61+
{ name: 'timestamp', type: 'date' as MetricsExplorerColumnType },
62+
{ name: 'metric_0', type: 'number' as MetricsExplorerColumnType },
63+
],
64+
rows: series.rows.map((row) => {
65+
return { timestamp: row.timestamp, metric_0: get(row, metric.id, null) };
66+
}),
67+
};
68+
const maxValue = calculateMax(timeseries.rows);
69+
const avg = calculateAvg(timeseries.rows);
70+
const value = getLastValue(timeseries.rows);
71+
const nodeMetric: SnapshotNodeMetric = { name, max: maxValue, value, avg };
72+
if (snapshotRequest.includeTimeseries) {
73+
nodeMetric.timeseries = timeseries;
74+
}
75+
return nodeMetric;
76+
}),
77+
path:
78+
series.keys?.map((key) => {
79+
return { value: key, label: key } as SnapshotNodePath;
80+
}) ?? [],
81+
name: '',
82+
};
8183

82-
const path = applyMetadataToLastPath(series, node, snapshotRequest, source);
83-
const lastPath = last(path);
84-
const name = (lastPath && lastPath.label) || 'N/A';
85-
return { ...node, path, name };
86-
});
84+
const isNoData = node.metrics.every((m) => m.value === null);
85+
const isAPMNode = series.metricsets?.includes('app');
86+
if (isNoData && isAPMNode) return null;
87+
88+
const path = applyMetadataToLastPath(series, node, snapshotRequest, source);
89+
const lastPath = last(path);
90+
const name = (lastPath && lastPath.label) || 'N/A';
91+
92+
return { ...node, path, name };
93+
})
94+
.filter((n) => n !== null) as SnapshotNode[];
8795
return { nodes, interval: `${metricsApiResponse.info.interval}s` };
8896
};

0 commit comments

Comments
 (0)