Skip to content

Commit e3d0846

Browse files
committed
feat: add semconv schema support for host metrics formulas and charts
1 parent 9bea302 commit e3d0846

File tree

17 files changed

+731
-563
lines changed

17 files changed

+731
-563
lines changed

x-pack/solutions/observability/plugins/infra/public/components/asset_details/hooks/use_host_metrics_charts.ts

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
import { i18n } from '@kbn/i18n';
99
import { findInventoryModel } from '@kbn/metrics-data-access-plugin/common';
10-
import { useMemo } from 'react';
1110
import useAsync from 'react-use/lib/useAsync';
11+
import type { SchemaTypes } from '../../../../common/http_api/shared/schema_type';
12+
import { usePluginConfig } from '../../../containers/plugin_config_context';
1213
import type { HostMetricTypes } from '../charts/types';
1314
import { useChartSeriesColor } from './use_chart_series_color';
1415

@@ -21,8 +22,15 @@ export const useHostCharts = ({
2122
dataViewId?: string;
2223
overview?: boolean;
2324
}) => {
25+
const config = usePluginConfig();
26+
2427
const { value: charts = [], error } = useAsync(async () => {
25-
const hostCharts = await getHostsCharts({ metric, overview });
28+
const hostCharts = await getHostsCharts({
29+
metric,
30+
overview,
31+
schema: config.featureFlags.hostOtelEnabled ? 'semconv' : 'ecs',
32+
});
33+
2634
return hostCharts.map((chart) => ({
2735
...chart,
2836
...(dataViewId && {
@@ -31,7 +39,7 @@ export const useHostCharts = ({
3139
},
3240
}),
3341
}));
34-
}, [dataViewId, metric, overview]);
42+
}, [config.featureFlags.hostOtelEnabled, dataViewId, metric, overview]);
3543

3644
return { charts, error };
3745
};
@@ -43,18 +51,25 @@ export const useKubernetesCharts = ({
4351
dataViewId?: string;
4452
overview?: boolean;
4553
}) => {
46-
const model = useMemo(() => findInventoryModel('host'), []);
54+
const model = findInventoryModel('host');
55+
const config = usePluginConfig();
4756

4857
const { value: charts = [], error } = useAsync(async () => {
49-
const { kibernetesNode } = await model.metrics.getCharts();
58+
const { kubernetesNode } = await model.metrics.getCharts({
59+
schema: config.featureFlags.hostOtelEnabled ? 'semconv' : 'ecs',
60+
});
61+
62+
if (!kubernetesNode) {
63+
return [];
64+
}
5065

5166
const items = overview
52-
? [kibernetesNode.xy.nodeCpuCapacity, kibernetesNode.xy.nodeMemoryCapacity]
67+
? [kubernetesNode.xy.nodeCpuCapacity, kubernetesNode.xy.nodeMemoryCapacity]
5368
: [
54-
kibernetesNode.xy.nodeCpuCapacity,
55-
kibernetesNode.xy.nodeMemoryCapacity,
56-
kibernetesNode.xy.nodeDiskCapacity,
57-
kibernetesNode.xy.nodePodCapacity,
69+
kubernetesNode.xy.nodeCpuCapacity,
70+
kubernetesNode.xy.nodeMemoryCapacity,
71+
kubernetesNode.xy.nodeDiskCapacity,
72+
kubernetesNode.xy.nodePodCapacity,
5873
];
5974

6075
return items.map((chart) => {
@@ -67,7 +82,7 @@ export const useKubernetesCharts = ({
6782
}),
6883
};
6984
});
70-
}, [dataViewId, overview, model.metrics]);
85+
}, [model.metrics, config.featureFlags.hostOtelEnabled, overview, dataViewId]);
7186

7287
return { charts, error };
7388
};
@@ -89,10 +104,12 @@ export const useHostKpiCharts = ({
89104
getSubtitle?: (formulaValue: string) => string;
90105
}) => {
91106
seriesColor = useChartSeriesColor(seriesColor);
92-
107+
const config = usePluginConfig();
93108
const { value: charts = [] } = useAsync(async () => {
94109
const model = findInventoryModel('host');
95-
const { cpu, memory, disk } = await model.metrics.getCharts();
110+
const { cpu, memory, disk } = await model.metrics.getCharts({
111+
schema: config.featureFlags.hostOtelEnabled ? 'semconv' : 'ecs',
112+
});
96113

97114
return [
98115
cpu.metric.cpuUsage,
@@ -110,20 +127,23 @@ export const useHostKpiCharts = ({
110127
},
111128
}),
112129
}));
113-
}, [dataViewId, seriesColor, getSubtitle]);
130+
}, [dataViewId, seriesColor, getSubtitle, config.featureFlags.hostOtelEnabled]);
114131

115132
return charts;
116133
};
117134

118135
const getHostsCharts = async ({
119136
metric,
120137
overview,
138+
schema,
121139
}: {
122140
metric: HostMetricTypes;
123141
overview?: boolean;
142+
schema: SchemaTypes;
124143
}) => {
125144
const model = findInventoryModel('host');
126-
const { cpu, memory, network, disk, logs } = await model.metrics.getCharts();
145+
146+
const { cpu, memory, network, disk, logs } = await model.metrics.getCharts({ schema });
127147

128148
switch (metric) {
129149
case 'cpu':

x-pack/solutions/observability/plugins/infra/public/pages/metrics/hosts/hooks/use_metrics_charts.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88
import useAsync from 'react-use/lib/useAsync';
99
import type { LensBreakdownConfig } from '@kbn/lens-embeddable-utils/config_builder';
1010
import { findInventoryModel } from '@kbn/metrics-data-access-plugin/common';
11+
import { usePluginConfig } from '../../../../containers/plugin_config_context';
1112
import { PAGE_SIZE_OPTIONS } from '../constants';
1213

1314
export const useMetricsCharts = ({ dataViewId }: { dataViewId?: string }) => {
15+
const config = usePluginConfig();
16+
1417
const { value: charts = [] } = useAsync(async () => {
1518
const model = findInventoryModel('host');
16-
const { cpu, disk, memory, network } = await model.metrics.getCharts();
19+
const { cpu, disk, memory, network } = await model.metrics.getCharts({
20+
schema: config.featureFlags.hostOtelEnabled ? 'semconv' : 'ecs',
21+
});
1722

1823
return [
1924
cpu.xy.cpuUsage,
@@ -47,7 +52,7 @@ export const useMetricsCharts = ({ dataViewId }: { dataViewId?: string }) => {
4752
},
4853
}),
4954
}));
50-
}, [dataViewId]);
55+
}, [dataViewId, config.featureFlags.hostOtelEnabled]);
5156

5257
return charts;
5358
};

x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/host/metrics/charts/cpu.ts

Lines changed: 112 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -14,120 +14,123 @@ import {
1414
DEFAULT_XY_LEGEND,
1515
DEFAULT_XY_YBOUNDS,
1616
} from '../../../shared/charts/constants';
17+
import type { FormulasCatalog } from '../../../shared/metrics/types';
1718
import type { LensConfigWithId } from '../../../types';
18-
import { formulas } from '../formulas';
19+
import type { HostFormulas } from '../formulas';
1920

20-
const cpuUsageBreakdown: LensConfigWithId = {
21-
id: 'cpuUsageBreakdown',
22-
chartType: 'xy',
23-
title: CPU_USAGE_LABEL,
24-
layers: [
25-
{
26-
seriesType: 'area',
27-
type: 'series',
28-
xAxis: '@timestamp',
29-
yAxis: [
30-
formulas.cpuUsageIowait,
31-
formulas.cpuUsageIrq,
32-
formulas.cpuUsageNice,
33-
formulas.cpuUsageSoftirq,
34-
formulas.cpuUsageSteal,
35-
formulas.cpuUsageUser,
36-
formulas.cpuUsageSystem,
37-
],
38-
},
39-
],
40-
...DEFAULT_XY_FITTING_FUNCTION,
41-
...DEFAULT_XY_LEGEND,
42-
...DEFAULT_XY_YBOUNDS,
43-
...DEFAULT_XY_HIDDEN_AXIS_TITLE,
44-
};
21+
export const init = (formulas: FormulasCatalog<HostFormulas>) => {
22+
const cpuUsageBreakdown: LensConfigWithId = {
23+
id: 'cpuUsageBreakdown',
24+
chartType: 'xy',
25+
title: CPU_USAGE_LABEL,
26+
layers: [
27+
{
28+
seriesType: 'area',
29+
type: 'series',
30+
xAxis: '@timestamp',
31+
yAxis: [
32+
formulas.get('cpuUsageIowait'),
33+
formulas.get('cpuUsageIrq'),
34+
formulas.get('cpuUsageNice'),
35+
formulas.get('cpuUsageSoftirq'),
36+
formulas.get('cpuUsageSteal'),
37+
formulas.get('cpuUsageUser'),
38+
formulas.get('cpuUsageSystem'),
39+
],
40+
},
41+
],
42+
...DEFAULT_XY_FITTING_FUNCTION,
43+
...DEFAULT_XY_LEGEND,
44+
...DEFAULT_XY_YBOUNDS,
45+
...DEFAULT_XY_HIDDEN_AXIS_TITLE,
46+
};
4547

46-
const loadBreakdown: LensConfigWithId = {
47-
id: 'loadBreakdown',
48-
chartType: 'xy',
49-
title: LOAD_LABEL,
50-
layers: [
51-
{
52-
seriesType: 'area',
53-
type: 'series',
54-
xAxis: '@timestamp',
55-
yAxis: [formulas.load1m, formulas.load5m, formulas.load15m],
56-
},
57-
],
58-
...DEFAULT_XY_FITTING_FUNCTION,
59-
...DEFAULT_XY_LEGEND,
60-
...DEFAULT_XY_HIDDEN_AXIS_TITLE,
61-
};
48+
const loadBreakdown: LensConfigWithId = {
49+
id: 'loadBreakdown',
50+
chartType: 'xy',
51+
title: LOAD_LABEL,
52+
layers: [
53+
{
54+
seriesType: 'area',
55+
type: 'series',
56+
xAxis: '@timestamp',
57+
yAxis: [formulas.get('load1m'), formulas.get('load5m'), formulas.get('load15m')],
58+
},
59+
],
60+
...DEFAULT_XY_FITTING_FUNCTION,
61+
...DEFAULT_XY_LEGEND,
62+
...DEFAULT_XY_HIDDEN_AXIS_TITLE,
63+
};
6264

63-
const cpuUsageXY: LensConfigWithId = {
64-
id: 'cpuUsage',
65-
chartType: 'xy',
66-
title: formulas.cpuUsage.label ?? '',
67-
layers: [
68-
{
69-
seriesType: 'line',
70-
type: 'series',
71-
xAxis: '@timestamp',
72-
yAxis: [formulas.cpuUsage],
73-
},
74-
],
75-
...DEFAULT_XY_FITTING_FUNCTION,
76-
...DEFAULT_XY_HIDDEN_LEGEND,
77-
...DEFAULT_XY_HIDDEN_AXIS_TITLE,
78-
...DEFAULT_XY_YBOUNDS,
79-
};
65+
const cpuUsageXY: LensConfigWithId = {
66+
id: 'cpuUsage',
67+
chartType: 'xy',
68+
title: formulas.get('cpuUsage').label ?? '',
69+
layers: [
70+
{
71+
seriesType: 'line',
72+
type: 'series',
73+
xAxis: '@timestamp',
74+
yAxis: [formulas.get('cpuUsage')],
75+
},
76+
],
77+
...DEFAULT_XY_FITTING_FUNCTION,
78+
...DEFAULT_XY_HIDDEN_LEGEND,
79+
...DEFAULT_XY_HIDDEN_AXIS_TITLE,
80+
...DEFAULT_XY_YBOUNDS,
81+
};
8082

81-
const normalizedLoad1mXY: LensConfigWithId = {
82-
id: 'normalizedLoad1m',
83-
chartType: 'xy',
84-
title: formulas.normalizedLoad1m.label ?? '',
85-
layers: [
86-
{
87-
seriesType: 'line',
88-
type: 'series',
89-
xAxis: '@timestamp',
90-
yAxis: [formulas.normalizedLoad1m],
91-
},
92-
{
93-
type: 'reference',
94-
yAxis: [
95-
{
96-
value: '1',
97-
},
98-
],
99-
},
100-
],
101-
...DEFAULT_XY_FITTING_FUNCTION,
102-
...DEFAULT_XY_HIDDEN_LEGEND,
103-
...DEFAULT_XY_HIDDEN_AXIS_TITLE,
104-
};
83+
const normalizedLoad1mXY: LensConfigWithId = {
84+
id: 'normalizedLoad1m',
85+
chartType: 'xy',
86+
title: formulas.get('normalizedLoad1m').label ?? '',
87+
layers: [
88+
{
89+
seriesType: 'line',
90+
type: 'series',
91+
xAxis: '@timestamp',
92+
yAxis: [formulas.get('normalizedLoad1m')],
93+
},
94+
{
95+
type: 'reference',
96+
yAxis: [
97+
{
98+
value: '1',
99+
},
100+
],
101+
},
102+
],
103+
...DEFAULT_XY_FITTING_FUNCTION,
104+
...DEFAULT_XY_HIDDEN_LEGEND,
105+
...DEFAULT_XY_HIDDEN_AXIS_TITLE,
106+
};
105107

106-
const cpuUsageMetric: LensConfigWithId = {
107-
id: 'cpuUsage',
108-
chartType: 'metric',
109-
title: formulas.cpuUsage.label ?? '',
110-
trendLine: true,
111-
...formulas.cpuUsage,
112-
};
108+
const cpuUsageMetric: LensConfigWithId = {
109+
id: 'cpuUsage',
110+
chartType: 'metric',
111+
title: formulas.get('cpuUsage').label ?? '',
112+
trendLine: true,
113+
...formulas.get('cpuUsage'),
114+
};
113115

114-
const normalizedLoad1mMetric: LensConfigWithId = {
115-
id: 'normalizedLoad1m',
116-
chartType: 'metric',
117-
title: formulas.normalizedLoad1m.label ?? '',
118-
trendLine: true,
119-
...formulas.normalizedLoad1m,
120-
};
116+
const normalizedLoad1mMetric: LensConfigWithId = {
117+
id: 'normalizedLoad1m',
118+
chartType: 'metric',
119+
title: formulas.get('normalizedLoad1m').label ?? '',
120+
trendLine: true,
121+
...formulas.get('normalizedLoad1m'),
122+
};
121123

122-
export const cpu = {
123-
xy: {
124-
cpuUsageBreakdown,
125-
loadBreakdown,
126-
cpuUsage: cpuUsageXY,
127-
normalizedLoad1m: normalizedLoad1mXY,
128-
},
129-
metric: {
130-
cpuUsage: cpuUsageMetric,
131-
normalizedLoad1m: normalizedLoad1mMetric,
132-
},
133-
} as const;
124+
return {
125+
xy: {
126+
cpuUsageBreakdown,
127+
loadBreakdown,
128+
cpuUsage: cpuUsageXY,
129+
normalizedLoad1m: normalizedLoad1mXY,
130+
},
131+
metric: {
132+
cpuUsage: cpuUsageMetric,
133+
normalizedLoad1m: normalizedLoad1mMetric,
134+
},
135+
};
136+
};

0 commit comments

Comments
 (0)