From f309f35656b5202c6019f621590bf25cc4ce1687 Mon Sep 17 00:00:00 2001 From: neptunian Date: Thu, 6 Oct 2022 10:59:34 -0400 Subject: [PATCH 01/22] remove lens, add snapshot api --- x-pack/plugins/infra/kibana.json | 3 +- .../plugins/infra/public/apps/metrics_app.tsx | 1 - .../metrics/hosts/components/hosts_table.tsx | 502 +----------------- .../pages/metrics/hosts/hosts_content.tsx | 35 +- x-pack/plugins/infra/public/types.ts | 2 - 5 files changed, 29 insertions(+), 514 deletions(-) diff --git a/x-pack/plugins/infra/kibana.json b/x-pack/plugins/infra/kibana.json index 4290fb0382cc6..2226c89ab90f6 100644 --- a/x-pack/plugins/infra/kibana.json +++ b/x-pack/plugins/infra/kibana.json @@ -15,8 +15,7 @@ "triggersActionsUi", "observability", "ruleRegistry", - "unifiedSearch", - "lens" + "unifiedSearch" ], "optionalPlugins": ["ml", "home", "embeddable", "osquery"], "server": true, diff --git a/x-pack/plugins/infra/public/apps/metrics_app.tsx b/x-pack/plugins/infra/public/apps/metrics_app.tsx index ce8123b5f2223..159c6dab7a66e 100644 --- a/x-pack/plugins/infra/public/apps/metrics_app.tsx +++ b/x-pack/plugins/infra/public/apps/metrics_app.tsx @@ -47,7 +47,6 @@ export const renderApp = ( return () => { core.chrome.docTitle.reset(); ReactDOM.unmountComponentAtNode(element); - plugins.data.search.session.clear(); }; }; diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx index 74f2468eb4c45..9797b6e731f42 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx @@ -5,516 +5,22 @@ * 2.0. */ -import { useKibana } from '@kbn/kibana-react-plugin/public'; -import { TypedLensByValueInput } from '@kbn/lens-plugin/public'; import type { Query, TimeRange } from '@kbn/es-query'; import React from 'react'; import type { DataView } from '@kbn/data-views-plugin/public'; -import { InfraClientStartDeps } from '../../../../types'; - -const getLensHostsTable = ( - metricsDataView: DataView, - query: Query -): TypedLensByValueInput['attributes'] => - ({ - visualizationType: 'lnsDatatable', - title: 'Lens visualization', - references: [ - { - id: metricsDataView.id, - name: 'indexpattern-datasource-current-indexpattern', - type: 'index-pattern', - }, - { - id: metricsDataView.id, - name: 'indexpattern-datasource-layer-cbe5d8a0-381d-49bf-b8ac-f8f312ec7129', - type: 'index-pattern', - }, - ], - state: { - datasourceStates: { - indexpattern: { - layers: { - 'cbe5d8a0-381d-49bf-b8ac-f8f312ec7129': { - columns: { - '8d17458d-31af-41d1-a23c-5180fd960bee': { - label: 'Name', - dataType: 'string', - operationType: 'terms', - scale: 'ordinal', - sourceField: 'host.name', - isBucketed: true, - params: { - size: 10000, - orderBy: { - type: 'column', - columnId: '467de550-9186-4e18-8cfa-bce07087801a', - }, - orderDirection: 'desc', - otherBucket: true, - missingBucket: false, - parentFormat: { - id: 'terms', - }, - }, - customLabel: true, - }, - '155fc728-d010-498e-8126-0bc46cad2be2': { - label: 'Operating system', - dataType: 'string', - operationType: 'terms', - scale: 'ordinal', - sourceField: 'host.os.type', - isBucketed: true, - params: { - size: 10000, - orderBy: { - type: 'column', - columnId: '467de550-9186-4e18-8cfa-bce07087801a', - }, - orderDirection: 'desc', - otherBucket: false, - missingBucket: false, - parentFormat: { - id: 'terms', - }, - }, - customLabel: true, - }, - '467de550-9186-4e18-8cfa-bce07087801a': { - label: '# of CPUs', - dataType: 'number', - operationType: 'max', - sourceField: 'system.cpu.cores', - isBucketed: false, - scale: 'ratio', - params: { - emptyAsNull: true, - }, - customLabel: true, - }, - '3eca2307-228e-4842-a023-57e15c8c364d': { - label: 'Disk latency (avg.)', - dataType: 'number', - operationType: 'formula', - isBucketed: false, - scale: 'ratio', - params: { - formula: 'average(system.diskio.io.time) / 1000', - isFormulaBroken: false, - format: { - id: 'number', - params: { - decimals: 0, - suffix: 'ms', - }, - }, - }, - references: ['3eca2307-228e-4842-a023-57e15c8c364dX1'], - customLabel: true, - }, - '0a9bd0fa-9966-489b-8c95-70997a7aad4c': { - label: 'Memory total (avg.)', - dataType: 'number', - operationType: 'formula', - isBucketed: false, - scale: 'ratio', - params: { - formula: 'average(system.memory.total)', - isFormulaBroken: false, - format: { - id: 'bytes', - params: { - decimals: 0, - }, - }, - }, - references: ['0a9bd0fa-9966-489b-8c95-70997a7aad4cX0'], - customLabel: true, - }, - 'fe5a4d7d-6f48-45ab-974c-96bc864ac36f': { - label: 'Memory usage (avg.)', - dataType: 'number', - operationType: 'formula', - isBucketed: false, - scale: 'ratio', - params: { - formula: 'average(system.memory.used.pct)', - isFormulaBroken: false, - format: { - id: 'percent', - params: { - decimals: 0, - }, - }, - }, - references: ['fe5a4d7d-6f48-45ab-974c-96bc864ac36fX0'], - customLabel: true, - }, - '0a9bd0fa-9966-489b-8c95-70997a7aad4cX0': { - label: 'Part of Memory Total (avg)', - dataType: 'number', - operationType: 'average', - sourceField: 'system.memory.total', - isBucketed: false, - scale: 'ratio', - params: { - emptyAsNull: false, - }, - customLabel: true, - }, - 'fe5a4d7d-6f48-45ab-974c-96bc864ac36fX0': { - label: 'Part of Memory Usage (avg)', - dataType: 'number', - operationType: 'average', - sourceField: 'system.memory.used.pct', - isBucketed: false, - scale: 'ratio', - params: { - emptyAsNull: false, - }, - customLabel: true, - }, - '3eca2307-228e-4842-a023-57e15c8c364dX0': { - label: 'Part of Disk Latency (avg ms)', - dataType: 'number', - operationType: 'average', - sourceField: 'system.diskio.io.time', - isBucketed: false, - scale: 'ratio', - params: { - emptyAsNull: false, - }, - customLabel: true, - }, - '3eca2307-228e-4842-a023-57e15c8c364dX1': { - label: 'Part of Disk Latency (avg ms)', - dataType: 'number', - operationType: 'math', - isBucketed: false, - scale: 'ratio', - params: { - tinymathAst: { - type: 'function', - name: 'divide', - args: ['3eca2307-228e-4842-a023-57e15c8c364dX0', 1000], - location: { - min: 0, - max: 37, - }, - text: 'average(system.diskio.io.time) / 1000', - }, - }, - references: ['3eca2307-228e-4842-a023-57e15c8c364dX0'], - customLabel: true, - }, - '02e9d54c-bbe0-42dc-839c-55080a29838dX0': { - label: 'Part of RX (avg)', - dataType: 'number', - operationType: 'average', - sourceField: 'host.network.ingress.bytes', - isBucketed: false, - scale: 'ratio', - filter: { - query: 'host.network.ingress.bytes: *', - language: 'kuery', - }, - params: { - emptyAsNull: false, - }, - customLabel: true, - }, - '02e9d54c-bbe0-42dc-839c-55080a29838dX1': { - label: 'Part of RX (avg)', - dataType: 'number', - operationType: 'max', - sourceField: 'metricset.period', - isBucketed: false, - scale: 'ratio', - filter: { - query: 'host.network.ingress.bytes: *', - language: 'kuery', - }, - params: { - emptyAsNull: false, - }, - customLabel: true, - }, - '02e9d54c-bbe0-42dc-839c-55080a29838dX2': { - label: 'Part of RX (avg)', - dataType: 'number', - operationType: 'math', - isBucketed: false, - scale: 'ratio', - params: { - tinymathAst: { - type: 'function', - name: 'divide', - args: [ - { - type: 'function', - name: 'multiply', - args: ['02e9d54c-bbe0-42dc-839c-55080a29838dX0', 8], - location: { - min: 1, - max: 40, - }, - text: 'average(host.network.ingress.bytes) * 8', - }, - { - type: 'function', - name: 'divide', - args: ['02e9d54c-bbe0-42dc-839c-55080a29838dX1', 1000], - location: { - min: 45, - max: 73, - }, - text: 'max(metricset.period) / 1000', - }, - ], - location: { - min: 0, - max: 75, - }, - text: '(average(host.network.ingress.bytes) * 8) / (max(metricset.period) / 1000)\n', - }, - }, - references: [ - '02e9d54c-bbe0-42dc-839c-55080a29838dX0', - '02e9d54c-bbe0-42dc-839c-55080a29838dX1', - ], - customLabel: true, - }, - '02e9d54c-bbe0-42dc-839c-55080a29838d': { - label: 'RX (avg.)', - dataType: 'number', - operationType: 'formula', - isBucketed: false, - scale: 'ratio', - params: { - formula: - '(average(host.network.ingress.bytes) * 8) / (max(metricset.period) / 1000)\n', - isFormulaBroken: false, - format: { - id: 'bits', - params: { - decimals: 0, - suffix: '/s', - }, - }, - }, - references: ['02e9d54c-bbe0-42dc-839c-55080a29838dX2'], - filter: { - query: 'host.network.ingress.bytes: *', - language: 'kuery', - }, - customLabel: true, - }, - '7802ef93-622c-44df-94fa-03eec01bb7b6X0': { - label: 'Part of TX', - dataType: 'number', - operationType: 'average', - sourceField: 'host.network.egress.bytes', - isBucketed: false, - scale: 'ratio', - filter: { - query: 'host.network.egress.bytes: *', - language: 'kuery', - }, - params: { - emptyAsNull: false, - }, - customLabel: true, - }, - '7802ef93-622c-44df-94fa-03eec01bb7b6X1': { - label: 'Part of TX', - dataType: 'number', - operationType: 'max', - sourceField: 'metricset.period', - isBucketed: false, - scale: 'ratio', - filter: { - query: 'host.network.egress.bytes: *', - language: 'kuery', - }, - params: { - emptyAsNull: false, - }, - customLabel: true, - }, - '7802ef93-622c-44df-94fa-03eec01bb7b6X2': { - label: 'Part of TX', - dataType: 'number', - operationType: 'math', - isBucketed: false, - scale: 'ratio', - params: { - tinymathAst: { - type: 'function', - name: 'divide', - args: [ - { - type: 'function', - name: 'multiply', - args: ['7802ef93-622c-44df-94fa-03eec01bb7b6X0', 8], - location: { - min: 1, - max: 39, - }, - text: 'average(host.network.egress.bytes) * 8', - }, - { - type: 'function', - name: 'divide', - args: ['7802ef93-622c-44df-94fa-03eec01bb7b6X1', 1000], - location: { - min: 44, - max: 72, - }, - text: 'max(metricset.period) / 1000', - }, - ], - location: { - min: 0, - max: 74, - }, - text: '(average(host.network.egress.bytes) * 8) / (max(metricset.period) / 1000)\n', - }, - }, - references: [ - '7802ef93-622c-44df-94fa-03eec01bb7b6X0', - '7802ef93-622c-44df-94fa-03eec01bb7b6X1', - ], - customLabel: true, - }, - '7802ef93-622c-44df-94fa-03eec01bb7b6': { - label: 'TX (avg.)', - dataType: 'number', - operationType: 'formula', - isBucketed: false, - scale: 'ratio', - params: { - formula: - '(average(host.network.egress.bytes) * 8) / (max(metricset.period) / 1000)\n', - isFormulaBroken: false, - format: { - id: 'bits', - params: { - decimals: 0, - suffix: '/s', - }, - }, - }, - references: ['7802ef93-622c-44df-94fa-03eec01bb7b6X2'], - filter: { - query: 'host.network.egress.bytes: *', - language: 'kuery', - }, - customLabel: true, - }, - }, - columnOrder: [ - '8d17458d-31af-41d1-a23c-5180fd960bee', - '155fc728-d010-498e-8126-0bc46cad2be2', - '467de550-9186-4e18-8cfa-bce07087801a', - '3eca2307-228e-4842-a023-57e15c8c364d', - '02e9d54c-bbe0-42dc-839c-55080a29838d', - '7802ef93-622c-44df-94fa-03eec01bb7b6', - '0a9bd0fa-9966-489b-8c95-70997a7aad4c', - 'fe5a4d7d-6f48-45ab-974c-96bc864ac36f', - '0a9bd0fa-9966-489b-8c95-70997a7aad4cX0', - 'fe5a4d7d-6f48-45ab-974c-96bc864ac36fX0', - '3eca2307-228e-4842-a023-57e15c8c364dX0', - '3eca2307-228e-4842-a023-57e15c8c364dX1', - '02e9d54c-bbe0-42dc-839c-55080a29838dX0', - '02e9d54c-bbe0-42dc-839c-55080a29838dX1', - '02e9d54c-bbe0-42dc-839c-55080a29838dX2', - '7802ef93-622c-44df-94fa-03eec01bb7b6X0', - '7802ef93-622c-44df-94fa-03eec01bb7b6X1', - '7802ef93-622c-44df-94fa-03eec01bb7b6X2', - ], - incompleteColumns: {}, - indexPatternId: '305688db-9e02-4046-acc1-5d0d8dd73ef6', - }, - }, - }, - }, - visualization: { - layerId: 'cbe5d8a0-381d-49bf-b8ac-f8f312ec7129', - layerType: 'data', - columns: [ - { - columnId: '8d17458d-31af-41d1-a23c-5180fd960bee', - width: 296.16666666666663, - isTransposed: false, - }, - { - columnId: '155fc728-d010-498e-8126-0bc46cad2be2', - isTransposed: false, - width: 152.36666666666667, - }, - { - columnId: '467de550-9186-4e18-8cfa-bce07087801a', - isTransposed: false, - width: 121.11666666666667, - }, - { - columnId: '3eca2307-228e-4842-a023-57e15c8c364d', - isTransposed: false, - }, - { - columnId: '0a9bd0fa-9966-489b-8c95-70997a7aad4c', - isTransposed: false, - }, - { - columnId: 'fe5a4d7d-6f48-45ab-974c-96bc864ac36f', - isTransposed: false, - }, - { - isTransposed: false, - columnId: '02e9d54c-bbe0-42dc-839c-55080a29838d', - }, - { - isTransposed: false, - columnId: '7802ef93-622c-44df-94fa-03eec01bb7b6', - }, - ], - paging: { - size: 10, - enabled: true, - }, - headerRowHeight: 'custom', - headerRowHeightLines: 2, - rowHeight: 'single', - rowHeightLines: 1, - }, - filters: [], - query, - }, - } as TypedLensByValueInput['attributes']); +import { SnapshotNode } from '../../../../../common/http_api'; interface Props { dataView: DataView; timeRange: TimeRange; query: Query; - searchSessionId: string; + nodes: SnapshotNode[]; } export const HostsTable: React.FunctionComponent = ({ dataView, timeRange, query, - searchSessionId, + nodes, }) => { - const { - services: { lens }, - } = useKibana(); - const LensComponent = lens?.EmbeddableComponent; - return ( - - ); + return
eui table here from nodes
; }; diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx index 63e95a19f1c7b..08e1fea0c51aa 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx @@ -6,27 +6,23 @@ */ import type { Query, TimeRange } from '@kbn/es-query'; -import { useKibana } from '@kbn/kibana-react-plugin/public'; import { i18n } from '@kbn/i18n'; import React, { useState, useCallback } from 'react'; import { SearchBar } from '@kbn/unified-search-plugin/public'; import { InfraLoadingPanel } from '../../../components/loading'; import { useMetricsDataViewContext } from './hooks/use_data_view'; import { HostsTable } from './components/hosts_table'; -import { InfraClientStartDeps } from '../../../types'; import { useSourceContext } from '../../../containers/metrics_source'; +import { useSnapshot } from '../inventory_view/hooks/use_snaphot'; +import { SnapshotMetricType } from '../../../../common/inventory_models/types'; export const HostsContent: React.FunctionComponent = () => { - const { - services: { data }, - } = useKibana(); - const { source } = useSourceContext(); + const { source, sourceId } = useSourceContext(); const [dateRange, setDateRange] = useState({ from: 'now-15m', to: 'now' }); const [query, setQuery] = useState({ query: '', language: 'kuery' }); const { metricsDataView, hasFailedCreatingDataView, hasFailedFetchingDataView } = useMetricsDataViewContext(); // needed to refresh the lens table when filters havent changed - const [searchSessionId, setSearchSessionId] = useState(data.search.session.start()); const onQuerySubmit = useCallback( (payload: { dateRange: TimeRange; query?: Query }) => { @@ -34,14 +30,31 @@ export const HostsContent: React.FunctionComponent = () => { if (payload.query) { setQuery(payload.query); } - setSearchSessionId(data.search.session.start()); }, - [setDateRange, setQuery, data.search.session] + [setDateRange, setQuery] + ); + const hostMetrics: Array<{ type: SnapshotMetricType }> = [ + { type: 'rx' }, + { type: 'tx' }, + { type: 'memory' }, + // add others + ]; + + const { loading, nodes } = useSnapshot( + '', // use the unified search query + hostMetrics, + [], + 'host', + sourceId, + 1665066458353, // currentTime. need to add support not to require this? + '', + '', + true ); return (
- {metricsDataView ? ( + {metricsDataView && !loading ? ( <> { dataView={metricsDataView} timeRange={dateRange} query={query} - searchSessionId={searchSessionId} + nodes={nodes} /> ) : hasFailedCreatingDataView || hasFailedFetchingDataView ? ( diff --git a/x-pack/plugins/infra/public/types.ts b/x-pack/plugins/infra/public/types.ts index 461ed1261233a..be8c4d877c61c 100644 --- a/x-pack/plugins/infra/public/types.ts +++ b/x-pack/plugins/infra/public/types.ts @@ -28,7 +28,6 @@ import type { } from '@kbn/observability-plugin/public'; // import type { OsqueryPluginStart } from '../../osquery/public'; import type { SpacesPluginStart } from '@kbn/spaces-plugin/public'; -import type { LensPublicStart } from '@kbn/lens-plugin/public'; import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public'; import { UnwrapPromise } from '../common/utility_types'; import type { @@ -75,7 +74,6 @@ export interface InfraClientStartDeps { embeddable?: EmbeddableStart; osquery?: unknown; // OsqueryPluginStart; share: SharePluginStart; - lens: LensPublicStart; storage: IStorageWrapper; } From fc545f62f345067e47fe169fd05993266a77b159 Mon Sep 17 00:00:00 2001 From: neptunian Date: Thu, 6 Oct 2022 11:30:34 -0400 Subject: [PATCH 02/22] add no data --- .../pages/metrics/hosts/hosts_content.tsx | 68 ++++++++++++------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx index 08e1fea0c51aa..16907edf5d35b 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx @@ -9,6 +9,7 @@ import type { Query, TimeRange } from '@kbn/es-query'; import { i18n } from '@kbn/i18n'; import React, { useState, useCallback } from 'react'; import { SearchBar } from '@kbn/unified-search-plugin/public'; +import { NoData } from '../../../components/empty_states'; import { InfraLoadingPanel } from '../../../components/loading'; import { useMetricsDataViewContext } from './hooks/use_data_view'; import { HostsTable } from './components/hosts_table'; @@ -33,6 +34,7 @@ export const HostsContent: React.FunctionComponent = () => { }, [setDateRange, setQuery] ); + const hostMetrics: Array<{ type: SnapshotMetricType }> = [ { type: 'rx' }, { type: 'tx' }, @@ -40,42 +42,62 @@ export const HostsContent: React.FunctionComponent = () => { // add others ]; - const { loading, nodes } = useSnapshot( - '', // use the unified search query + const { loading, nodes, reload } = useSnapshot( + '', // use the unified search query, supported type? hostMetrics, [], 'host', sourceId, - 1665066458353, // currentTime. need to add support not to require this? + 1665066458353, // currentTime. need to add support for TimeRange? '', '', true ); + const noData = !loading && nodes && nodes.length === 0; + return (
{metricsDataView && !loading ? ( - <> - - { + reload(); + }} + testString="noMetricsDataPrompt" /> - + ) : ( + <> + + + + ) ) : hasFailedCreatingDataView || hasFailedFetchingDataView ? (
There was an error trying to load or create the Data View:
From 26710d655f7a94e764cb3667d7cc11214013b8c7 Mon Sep 17 00:00:00 2001 From: Jenny Date: Mon, 10 Oct 2022 10:44:38 +0200 Subject: [PATCH 03/22] Add cpu type --- .../plugins/infra/public/pages/metrics/hosts/hosts_content.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx index 16907edf5d35b..18333a1bd0ecf 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx @@ -39,6 +39,7 @@ export const HostsContent: React.FunctionComponent = () => { { type: 'rx' }, { type: 'tx' }, { type: 'memory' }, + { type: 'cpu' }, // add others ]; From 5a212caae665f80e34e0c5ae68ee65c961a32fbe Mon Sep 17 00:00:00 2001 From: Jenny Date: Tue, 11 Oct 2022 18:08:18 +0200 Subject: [PATCH 04/22] [WIP] Add eui basic table and columns --- .../metrics/hosts/components/hosts_table.tsx | 49 +++++++++++- .../hosts/components/hosts_table_columns.tsx | 78 +++++++++++++++++++ .../pages/metrics/hosts/hosts_content.tsx | 2 + 3 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx index 9797b6e731f42..91850aee16121 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx @@ -8,19 +8,64 @@ import type { Query, TimeRange } from '@kbn/es-query'; import React from 'react'; import type { DataView } from '@kbn/data-views-plugin/public'; +import { EuiBasicTable } from '@elastic/eui'; import { SnapshotNode } from '../../../../../common/http_api'; - +import { HostsTableColumns } from './hosts_table_columns'; interface Props { dataView: DataView; timeRange: TimeRange; query: Query; nodes: SnapshotNode[]; } + export const HostsTable: React.FunctionComponent = ({ dataView, timeRange, query, nodes, }) => { - return
eui table here from nodes
; + // return
eui table here from nodes
; + + const items = [ + { + os: 'MacOs', + cpuCores: 10, + name: 'Jennys-MBP.fritz.box', + rx: { + avg: 1234, + }, + tx: { + avg: 321, + }, + memory: { + avg: 543, + }, + servicesOnHost: 10, + averageMemoryUsagePercent: 5, + }, + { + os: 'Ubuntu', + cpuCores: 4, + name: 'Jennys-Ubuntu.fritz.box', + rx: { + avg: 223, + }, + tx: { + avg: 775, + }, + memory: { + avg: 3323, + }, + servicesOnHost: 4, + averageMemoryUsagePercent: 55, + }, + ]; + + return ( + + ); }; diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx new file mode 100644 index 0000000000000..84197d02f8708 --- /dev/null +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx @@ -0,0 +1,78 @@ +/* + * 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 { EuiBasicTableColumn } from '@elastic/eui'; +import React from 'react'; +import { NumberCell } from '../../../../components/infrastructure_node_metrics_tables/shared/components'; + +export interface HostNodeRow { + name: string; + cpuCores: number | null; + os: string; + rx: { + avg: number | null; + }; + tx: { + avg: number | null; + }; + memory: { + avg: number | null; + }; + servicesOnHost: number | null; + averageMemoryUsagePercent: number | null; +} + +export const HostsTableColumns: Array> = [ + { + name: 'Name', + field: 'name', + truncateText: true, + render: (name: string) =>
{name}
, + }, + { + name: 'Operating System', + field: 'os', + render: (os: string) =>
{os}
, + }, + { + name: '# of CPUs', + field: 'cpuCores', + render: (cpuCores: number) => , + }, + { + name: 'Disk Latency', + field: 'cpuCores', + render: (ds: number) => , + }, + { + name: 'TX (avg.)', + field: 'tx', + render: (tx: { avg: number }) => , + }, + { + name: 'RX (avg.)', + field: 'rx', + render: (rx: { avg: number }) => , + }, + { + name: 'Memory total (avg.)', + field: 'memory', + render: (memory: { avg: number }) => , + }, + { + name: 'Services on Host', + field: 'servicesOnHost', + render: (servicesOnHost: number) => , + }, + { + name: 'Memory usage (avg.)', + field: 'averageMemoryUsagePercent', + render: (averageMemoryUsagePercent: number) => ( + + ), + }, +]; diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx index 18333a1bd0ecf..6828103306047 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx @@ -9,6 +9,7 @@ import type { Query, TimeRange } from '@kbn/es-query'; import { i18n } from '@kbn/i18n'; import React, { useState, useCallback } from 'react'; import { SearchBar } from '@kbn/unified-search-plugin/public'; +import { EuiSpacer } from '@elastic/eui'; import { NoData } from '../../../components/empty_states'; import { InfraLoadingPanel } from '../../../components/loading'; import { useMetricsDataViewContext } from './hooks/use_data_view'; @@ -91,6 +92,7 @@ export const HostsContent: React.FunctionComponent = () => { indexPatterns={[metricsDataView]} onQuerySubmit={onQuerySubmit} /> + Date: Wed, 12 Oct 2022 14:24:13 +0200 Subject: [PATCH 05/22] [WIP] Add cpu cores and os --- .../infra/common/http_api/snapshot_api.ts | 3 +++ .../infra/common/inventory_models/host/index.ts | 1 + .../inventory_models/host/metrics/index.ts | 3 ++- .../host/metrics/snapshot/cpu_cores.ts | 16 ++++++++++++++++ .../infra/common/inventory_models/types.ts | 2 ++ .../public/pages/metrics/hosts/hosts_content.tsx | 4 ++-- .../snapshot/lib/apply_metadata_to_last_path.ts | 4 ++++ .../transform_request_to_metrics_api_request.ts | 5 +++++ 8 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/cpu_cores.ts diff --git a/x-pack/plugins/infra/common/http_api/snapshot_api.ts b/x-pack/plugins/infra/common/http_api/snapshot_api.ts index 9c4fd65ce3fec..eb39f6a440a79 100644 --- a/x-pack/plugins/infra/common/http_api/snapshot_api.ts +++ b/x-pack/plugins/infra/common/http_api/snapshot_api.ts @@ -17,6 +17,9 @@ export const SnapshotNodePathRT = rt.intersection([ rt.partial({ ip: rt.union([rt.string, rt.null]), }), + rt.partial({ + os: rt.union([rt.string, rt.null]), + }), ]); const SnapshotNodeMetricOptionalRT = rt.partial({ diff --git a/x-pack/plugins/infra/common/inventory_models/host/index.ts b/x-pack/plugins/infra/common/inventory_models/host/index.ts index 8e2582c5e1f6f..d95c9644693c7 100644 --- a/x-pack/plugins/infra/common/inventory_models/host/index.ts +++ b/x-pack/plugins/infra/common/inventory_models/host/index.ts @@ -33,6 +33,7 @@ export const host: InventoryModel = { fields: { id: 'host.name', name: 'host.name', + os: 'host.os.platform', // TODO Change to name ip: 'host.ip', }, metrics, diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/index.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/index.ts index 2190140cc0a5e..e4fea2b6c204f 100644 --- a/x-pack/plugins/infra/common/inventory_models/host/metrics/index.ts +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/index.ts @@ -6,6 +6,7 @@ */ import { cpu } from './snapshot/cpu'; +import { cpuCores } from './snapshot/cpu_cores'; import { count } from '../../shared/metrics/snapshot/count'; import { load } from './snapshot/load'; import { logRate } from './snapshot/log_rate'; @@ -33,7 +34,7 @@ import { hostDockerInfo } from './tsvb/host_docker_info'; import { InventoryMetrics } from '../../types'; -const exposedHostSnapshotMetrics = { cpu, load, logRate, memory, rx, tx }; +const exposedHostSnapshotMetrics = { cpu, load, logRate, memory, rx, tx, cpuCores }; // not sure why this is the only model with "count" const hostSnapshotMetrics = { count, ...exposedHostSnapshotMetrics }; diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/cpu_cores.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/cpu_cores.ts new file mode 100644 index 0000000000000..3cc90ebfdca95 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/cpu_cores.ts @@ -0,0 +1,16 @@ +/* + * 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 { MetricsUIAggregation } from '../../../types'; + +export const cpuCores: MetricsUIAggregation = { + cpuCores: { + max: { + field: 'system.cpu.cores', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/types.ts b/x-pack/plugins/infra/common/inventory_models/types.ts index 9459933a489d3..b09deccc50caa 100644 --- a/x-pack/plugins/infra/common/inventory_models/types.ts +++ b/x-pack/plugins/infra/common/inventory_models/types.ts @@ -339,6 +339,7 @@ export type MetricsUIAggregation = rt.TypeOf; export const SnapshotMetricTypeKeys = { count: null, cpu: null, + cpuCores: null, load: null, memory: null, tx: null, @@ -382,6 +383,7 @@ export interface InventoryModel { fields: { id: string; name: string; + os: string; ip?: string; }; crosslinkSupport: { diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx index 6828103306047..d728894a1148a 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx @@ -40,7 +40,7 @@ export const HostsContent: React.FunctionComponent = () => { { type: 'rx' }, { type: 'tx' }, { type: 'memory' }, - { type: 'cpu' }, + { type: 'cpuCores' }, // add others ]; @@ -50,7 +50,7 @@ export const HostsContent: React.FunctionComponent = () => { [], 'host', sourceId, - 1665066458353, // currentTime. need to add support for TimeRange? + 1665482950000, // currentTime. need to add support for TimeRange? '', '', true diff --git a/x-pack/plugins/infra/server/routes/snapshot/lib/apply_metadata_to_last_path.ts b/x-pack/plugins/infra/server/routes/snapshot/lib/apply_metadata_to_last_path.ts index 2931555fc06b0..1c11753014791 100644 --- a/x-pack/plugins/infra/server/routes/snapshot/lib/apply_metadata_to_last_path.ts +++ b/x-pack/plugins/infra/server/routes/snapshot/lib/apply_metadata_to_last_path.ts @@ -56,6 +56,10 @@ export const applyMetadataToLastPath = ( lastPath.ip = ipAddresses; } } + if (inventoryFields.os) { + const inventoryFieldsOs = get(firstMetaDoc, inventoryFields.os) as string; + lastPath.os = inventoryFieldsOs; + } return [...node.path.slice(0, node.path.length - 1), lastPath]; } } diff --git a/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.ts b/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.ts index b7e389cae9126..87fbbdac9a701 100644 --- a/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.ts +++ b/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.ts @@ -93,6 +93,11 @@ export const transformRequestToMetricsAPIRequest = async ({ if (inventoryFields.ip) { metaAggregation.aggregations[META_KEY].top_metrics.metrics.push({ field: inventoryFields.ip }); } + + if (inventoryFields.os) { + metaAggregation.aggregations[META_KEY].top_metrics.metrics.push({ field: inventoryFields.os }); + } + metricsApiRequest.metrics.push(metaAggregation); if (filters.length) { From 20719b5dff820f7b5900b952b653275371ce0d62 Mon Sep 17 00:00:00 2001 From: Jenny Date: Wed, 12 Oct 2022 17:23:19 +0200 Subject: [PATCH 06/22] [WIP] Mapping data to the eui basic table format --- .../common/inventory_models/host/index.ts | 2 +- .../metrics/hosts/components/hosts_table.tsx | 52 ++++++------------- .../hosts/components/hosts_table_columns.tsx | 4 +- 3 files changed, 19 insertions(+), 39 deletions(-) diff --git a/x-pack/plugins/infra/common/inventory_models/host/index.ts b/x-pack/plugins/infra/common/inventory_models/host/index.ts index d95c9644693c7..304981dc0396a 100644 --- a/x-pack/plugins/infra/common/inventory_models/host/index.ts +++ b/x-pack/plugins/infra/common/inventory_models/host/index.ts @@ -33,7 +33,7 @@ export const host: InventoryModel = { fields: { id: 'host.name', name: 'host.name', - os: 'host.os.platform', // TODO Change to name + os: 'host.os.type', // TODO Change to name ip: 'host.ip', }, metrics, diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx index 91850aee16121..78a22152f8e43 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx @@ -9,7 +9,7 @@ import type { Query, TimeRange } from '@kbn/es-query'; import React from 'react'; import type { DataView } from '@kbn/data-views-plugin/public'; import { EuiBasicTable } from '@elastic/eui'; -import { SnapshotNode } from '../../../../../common/http_api'; +import { SnapshotNode, SnapshotNodeMetric } from '../../../../../common/http_api'; import { HostsTableColumns } from './hosts_table_columns'; interface Props { dataView: DataView; @@ -24,42 +24,22 @@ export const HostsTable: React.FunctionComponent = ({ query, nodes, }) => { - // return
eui table here from nodes
; + // WIP Mapping, Add types/optimize + const assignBy = (key) => { + return (data, item) => { + data[item[key]] = item; + return data; + }; + }; - const items = [ - { - os: 'MacOs', - cpuCores: 10, - name: 'Jennys-MBP.fritz.box', - rx: { - avg: 1234, - }, - tx: { - avg: 321, - }, - memory: { - avg: 543, - }, - servicesOnHost: 10, - averageMemoryUsagePercent: 5, - }, - { - os: 'Ubuntu', - cpuCores: 4, - name: 'Jennys-Ubuntu.fritz.box', - rx: { - avg: 223, - }, - tx: { - avg: 775, - }, - memory: { - avg: 3323, - }, - servicesOnHost: 4, - averageMemoryUsagePercent: 55, - }, - ]; + const mapMetrics = (metrics: SnapshotNodeMetric[]): { string: SnapshotNodeMetric } => { + return metrics.reduce(assignBy('name'), {}); + }; + + const items = nodes.map(({ metrics, path }) => ({ + ...path[0], + ...mapMetrics(metrics), + })); return ( > = [ { name: 'Name', - field: 'name', + field: 'label', truncateText: true, render: (name: string) =>
{name}
, }, @@ -41,7 +41,7 @@ export const HostsTableColumns: Array> = [ { name: '# of CPUs', field: 'cpuCores', - render: (cpuCores: number) => , + render: (cpuCores: { value: number }) => , }, { name: 'Disk Latency', From 392e03544722ee69e4c2d94311ff7eac59f8d421 Mon Sep 17 00:00:00 2001 From: Jenny Date: Thu, 13 Oct 2022 11:53:19 +0200 Subject: [PATCH 07/22] Add Memory Total --- .../inventory_models/host/metrics/index.ts | 3 +- .../host/metrics/snapshot/memory_total.ts | 28 +++++++++++++++++++ .../infra/common/inventory_models/types.ts | 1 + .../hosts/components/hosts_table_columns.tsx | 12 ++++---- .../pages/metrics/hosts/hosts_content.tsx | 1 + 5 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/memory_total.ts diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/index.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/index.ts index e4fea2b6c204f..8a60c4a066502 100644 --- a/x-pack/plugins/infra/common/inventory_models/host/metrics/index.ts +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/index.ts @@ -11,6 +11,7 @@ import { count } from '../../shared/metrics/snapshot/count'; import { load } from './snapshot/load'; import { logRate } from './snapshot/log_rate'; import { memory } from './snapshot/memory'; +import { memoryTotal } from './snapshot/memory_total'; import { rx } from './snapshot/rx'; import { tx } from './snapshot/tx'; @@ -34,7 +35,7 @@ import { hostDockerInfo } from './tsvb/host_docker_info'; import { InventoryMetrics } from '../../types'; -const exposedHostSnapshotMetrics = { cpu, load, logRate, memory, rx, tx, cpuCores }; +const exposedHostSnapshotMetrics = { cpu, load, logRate, memory, rx, tx, cpuCores, memoryTotal }; // not sure why this is the only model with "count" const hostSnapshotMetrics = { count, ...exposedHostSnapshotMetrics }; diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/memory_total.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/memory_total.ts new file mode 100644 index 0000000000000..c3d0a8063b93f --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/memory_total.ts @@ -0,0 +1,28 @@ +/* + * 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 { MetricsUIAggregation } from '../../../types'; + +export const memoryTotal: MetricsUIAggregation = { + memory_total: { + avg: { + field: 'system.memory.total', + }, + }, + memoryTotal: { + bucket_script: { + buckets_path: { + memoryTotal: 'memory_total', + }, + script: { + source: 'params.memoryTotal / 1000000', // Convert to MB + lang: 'painless', + }, + gap_policy: 'skip', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/types.ts b/x-pack/plugins/infra/common/inventory_models/types.ts index b09deccc50caa..4a0cd56c0cf8a 100644 --- a/x-pack/plugins/infra/common/inventory_models/types.ts +++ b/x-pack/plugins/infra/common/inventory_models/types.ts @@ -342,6 +342,7 @@ export const SnapshotMetricTypeKeys = { cpuCores: null, load: null, memory: null, + memoryTotal: null, tx: null, rx: null, logRate: null, diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx index 64194ec9fa03c..4ab2d6c1cda11 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx @@ -60,8 +60,10 @@ export const HostsTableColumns: Array> = [ }, { name: 'Memory total (avg.)', - field: 'memory', - render: (memory: { avg: number }) => , + field: 'memoryTotal', + render: (memoryTotal: { avg: number }) => ( + + ), }, { name: 'Services on Host', @@ -70,9 +72,7 @@ export const HostsTableColumns: Array> = [ }, { name: 'Memory usage (avg.)', - field: 'averageMemoryUsagePercent', - render: (averageMemoryUsagePercent: number) => ( - - ), + field: 'memory', + render: (memory: { avg: number }) => , }, ]; diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx index d728894a1148a..727d673ac521c 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx @@ -41,6 +41,7 @@ export const HostsContent: React.FunctionComponent = () => { { type: 'tx' }, { type: 'memory' }, { type: 'cpuCores' }, + { type: 'memoryTotal' }, // add others ]; From d1b432d4752331b3c3daece8f16644d6b3326397 Mon Sep 17 00:00:00 2001 From: Jenny Date: Thu, 13 Oct 2022 17:52:59 +0200 Subject: [PATCH 08/22] Refactor host mapping and add types --- .../metrics/hosts/components/hosts_table.tsx | 21 +++++---------- .../hosts/components/hosts_table_columns.tsx | 27 +++++++++---------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx index 78a22152f8e43..e7b4e76b1abc4 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx @@ -10,7 +10,7 @@ import React from 'react'; import type { DataView } from '@kbn/data-views-plugin/public'; import { EuiBasicTable } from '@elastic/eui'; import { SnapshotNode, SnapshotNodeMetric } from '../../../../../common/http_api'; -import { HostsTableColumns } from './hosts_table_columns'; +import { HostsTableColumns, HostMetics } from './hosts_table_columns'; interface Props { dataView: DataView; timeRange: TimeRange; @@ -18,27 +18,20 @@ interface Props { nodes: SnapshotNode[]; } +type MappedMetrics = Record; + export const HostsTable: React.FunctionComponent = ({ dataView, timeRange, query, nodes, }) => { - // WIP Mapping, Add types/optimize - const assignBy = (key) => { - return (data, item) => { - data[item[key]] = item; - return data; - }; - }; - - const mapMetrics = (metrics: SnapshotNodeMetric[]): { string: SnapshotNodeMetric } => { - return metrics.reduce(assignBy('name'), {}); - }; - const items = nodes.map(({ metrics, path }) => ({ ...path[0], - ...mapMetrics(metrics), + ...metrics.reduce((data, metric) => { + data[metric.name as keyof HostMetics] = metric; + return data; + }, {} as MappedMetrics), })); return ( diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx index 4ab2d6c1cda11..145ef18b4bb3f 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx @@ -7,23 +7,20 @@ import { EuiBasicTableColumn } from '@elastic/eui'; import React from 'react'; +import { SnapshotNodeMetric } from '../../../../../common/http_api/snapshot_api'; import { NumberCell } from '../../../../components/infrastructure_node_metrics_tables/shared/components'; -export interface HostNodeRow { - name: string; - cpuCores: number | null; - os: string; - rx: { - avg: number | null; - }; - tx: { - avg: number | null; - }; - memory: { - avg: number | null; - }; - servicesOnHost: number | null; - averageMemoryUsagePercent: number | null; +interface HostNodeRow extends HostMetics { + os?: string | null | undefined; + servicesOnHost?: number | null | undefined; +} + +export interface HostMetics { + cpuCores: SnapshotNodeMetric; + rx: SnapshotNodeMetric; + tx: SnapshotNodeMetric; + memory: SnapshotNodeMetric; + memoryTotal: SnapshotNodeMetric; } export const HostsTableColumns: Array> = [ From 72f9d8c1cdbe32d3fb822c941a76222d5f6ac223 Mon Sep 17 00:00:00 2001 From: Jenny Date: Fri, 14 Oct 2022 11:07:19 +0200 Subject: [PATCH 09/22] Scale up memory usage percentage --- .../pages/metrics/hosts/components/hosts_table_columns.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx index 145ef18b4bb3f..4d35664864d92 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx @@ -7,6 +7,7 @@ import { EuiBasicTableColumn } from '@elastic/eui'; import React from 'react'; +import { scaleUpPercentage } from '../../../../components/infrastructure_node_metrics_tables/shared/hooks'; import { SnapshotNodeMetric } from '../../../../../common/http_api/snapshot_api'; import { NumberCell } from '../../../../components/infrastructure_node_metrics_tables/shared/components'; @@ -70,6 +71,8 @@ export const HostsTableColumns: Array> = [ { name: 'Memory usage (avg.)', field: 'memory', - render: (memory: { avg: number }) => , + render: (memory: { avg: number }) => ( + + ), }, ]; From a20a278eec78679dc8ed5edd3f1d47782f1c9d02 Mon Sep 17 00:00:00 2001 From: Jenny Date: Fri, 14 Oct 2022 11:50:26 +0200 Subject: [PATCH 10/22] Make os optional in the model --- x-pack/plugins/infra/common/inventory_models/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/common/inventory_models/types.ts b/x-pack/plugins/infra/common/inventory_models/types.ts index 4a0cd56c0cf8a..8c0118d40fa4b 100644 --- a/x-pack/plugins/infra/common/inventory_models/types.ts +++ b/x-pack/plugins/infra/common/inventory_models/types.ts @@ -384,7 +384,7 @@ export interface InventoryModel { fields: { id: string; name: string; - os: string; + os?: string; ip?: string; }; crosslinkSupport: { From 5309f1faed57c3eda3872f187d9d1f53c960a95e Mon Sep 17 00:00:00 2001 From: Jenny Date: Fri, 14 Oct 2022 12:21:28 +0200 Subject: [PATCH 11/22] Text cells formatting --- .../pages/metrics/hosts/components/hosts_table_columns.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx index 4d35664864d92..694f3d4a0c545 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx @@ -7,6 +7,7 @@ import { EuiBasicTableColumn } from '@elastic/eui'; import React from 'react'; +import { EuiText } from '@elastic/eui'; import { scaleUpPercentage } from '../../../../components/infrastructure_node_metrics_tables/shared/hooks'; import { SnapshotNodeMetric } from '../../../../../common/http_api/snapshot_api'; import { NumberCell } from '../../../../components/infrastructure_node_metrics_tables/shared/components'; @@ -29,12 +30,12 @@ export const HostsTableColumns: Array> = [ name: 'Name', field: 'label', truncateText: true, - render: (name: string) =>
{name}
, + render: (name: string) => {name}, }, { name: 'Operating System', field: 'os', - render: (os: string) =>
{os}
, + render: (os: string) => {os ?? '-'}, }, { name: '# of CPUs', From b5e643214cec08a09b3877a4a6fa313a8dec9fac Mon Sep 17 00:00:00 2001 From: Jenny Date: Fri, 14 Oct 2022 14:38:58 +0200 Subject: [PATCH 12/22] Change os.type to os.name --- x-pack/plugins/infra/common/inventory_models/host/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/common/inventory_models/host/index.ts b/x-pack/plugins/infra/common/inventory_models/host/index.ts index 304981dc0396a..7420ca3f15939 100644 --- a/x-pack/plugins/infra/common/inventory_models/host/index.ts +++ b/x-pack/plugins/infra/common/inventory_models/host/index.ts @@ -33,7 +33,7 @@ export const host: InventoryModel = { fields: { id: 'host.name', name: 'host.name', - os: 'host.os.type', // TODO Change to name + os: 'host.os.name', ip: 'host.ip', }, metrics, From b54de0ed0621e819588e09ce82679097f86f7fd9 Mon Sep 17 00:00:00 2001 From: Jenny Date: Fri, 14 Oct 2022 17:57:43 +0200 Subject: [PATCH 13/22] Move snapshot nodes mapping to a hook and test it --- .../metrics/hosts/components/hosts_table.tsx | 15 +-- .../hosts/hooks/use_host_table.test.ts | 126 ++++++++++++++++++ .../metrics/hosts/hooks/use_host_table.ts | 26 ++++ 3 files changed, 156 insertions(+), 11 deletions(-) create mode 100644 x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.test.ts create mode 100644 x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.ts diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx index e7b4e76b1abc4..61e5ff9693cb9 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx @@ -9,8 +9,9 @@ import type { Query, TimeRange } from '@kbn/es-query'; import React from 'react'; import type { DataView } from '@kbn/data-views-plugin/public'; import { EuiBasicTable } from '@elastic/eui'; -import { SnapshotNode, SnapshotNodeMetric } from '../../../../../common/http_api'; -import { HostsTableColumns, HostMetics } from './hosts_table_columns'; +import { SnapshotNode } from '../../../../../common/http_api'; +import { HostsTableColumns } from './hosts_table_columns'; +import { useHostTable } from '../hooks/use_host_table'; interface Props { dataView: DataView; timeRange: TimeRange; @@ -18,21 +19,13 @@ interface Props { nodes: SnapshotNode[]; } -type MappedMetrics = Record; - export const HostsTable: React.FunctionComponent = ({ dataView, timeRange, query, nodes, }) => { - const items = nodes.map(({ metrics, path }) => ({ - ...path[0], - ...metrics.reduce((data, metric) => { - data[metric.name as keyof HostMetics] = metric; - return data; - }, {} as MappedMetrics), - })); + const items = useHostTable(nodes); return ( { + it('it should map the nodes returned from the snapshot api to a format matching eui table items', () => { + const nodes = [ + { + metrics: [ + { + name: 'rx', + avg: 252456.92916666667, + }, + { + name: 'tx', + avg: 252758.425, + }, + { + name: 'memory', + avg: 0.94525, + }, + { + name: 'cpuCores', + value: 10, + }, + { + name: 'memoryTotal', + avg: 34359.738368, + }, + ], + path: [{ value: 'host-0', label: 'host-0', os: null }], + name: 'host-0', + }, + { + metrics: [ + { + name: 'rx', + avg: 95.86339715321859, + }, + { + name: 'tx', + avg: 110.38566859563191, + }, + { + name: 'memory', + avg: 0.5400000214576721, + }, + { + name: 'cpuCores', + value: 8, + }, + { + name: 'memoryTotal', + avg: 9.194304, + }, + ], + path: [{ value: 'host-1', label: 'host-1', ip: '243.86.94.22', os: 'macOS' }], + name: 'host-1', + }, + ]; + + const items = [ + { + rx: { + name: 'rx', + avg: 252456.92916666667, + }, + tx: { + name: 'tx', + avg: 252758.425, + }, + memory: { + name: 'memory', + avg: 0.94525, + }, + cpuCores: { + name: 'cpuCores', + value: 10, + }, + memoryTotal: { + name: 'memoryTotal', + + avg: 34359.738368, + }, + value: 'host-0', + label: 'host-0', + os: null, + }, + { + rx: { + name: 'rx', + avg: 95.86339715321859, + }, + tx: { + name: 'tx', + avg: 110.38566859563191, + }, + memory: { + name: 'memory', + avg: 0.5400000214576721, + }, + cpuCores: { + name: 'cpuCores', + value: 8, + }, + memoryTotal: { + name: 'memoryTotal', + avg: 9.194304, + }, + value: 'host-1', + label: 'host-1', + ip: '243.86.94.22', + os: 'macOS', + }, + ]; + const result = renderHook(() => useHostTable(nodes)); + + expect(result.result.current).toStrictEqual(items); + }); +}); diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.ts b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.ts new file mode 100644 index 0000000000000..0b204071ffd3e --- /dev/null +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.ts @@ -0,0 +1,26 @@ +/* + * 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 { useMemo } from 'react'; +import { SnapshotNode, SnapshotNodeMetric } from '../../../../../common/http_api'; +import { HostMetics } from '../components/hosts_table_columns'; + +type MappedMetrics = Record; + +export const useHostTable = (nodes: SnapshotNode[]) => { + const items: MappedMetrics[] = useMemo(() => { + return nodes.map(({ metrics, path }) => ({ + ...path[0], + ...metrics.reduce((data, metric) => { + data[metric.name as keyof HostMetics] = metric; + return data; + }, {} as MappedMetrics), + })); + }, [nodes]); + + return items; +}; From 4153f3b44a652fe184ac84b897c30aa2eb6e6127 Mon Sep 17 00:00:00 2001 From: Jenny Date: Fri, 14 Oct 2022 18:47:41 +0200 Subject: [PATCH 14/22] Add translation --- .../hosts/components/hosts_table_columns.tsx | 38 ++++++++++++++----- .../translations/translations/fr-FR.json | 9 +++++ .../translations/translations/ja-JP.json | 9 +++++ .../translations/translations/zh-CN.json | 9 +++++ 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx index 694f3d4a0c545..6b2dab60b0d00 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx @@ -7,6 +7,7 @@ import { EuiBasicTableColumn } from '@elastic/eui'; import React from 'react'; +import { i18n } from '@kbn/i18n'; import { EuiText } from '@elastic/eui'; import { scaleUpPercentage } from '../../../../components/infrastructure_node_metrics_tables/shared/hooks'; import { SnapshotNodeMetric } from '../../../../../common/http_api/snapshot_api'; @@ -27,50 +28,69 @@ export interface HostMetics { export const HostsTableColumns: Array> = [ { - name: 'Name', + name: i18n.translate('xpack.infra.hostsTable.nameColumnHeader', { + defaultMessage: 'Name', + }), field: 'label', truncateText: true, + textOnly: true, render: (name: string) => {name}, }, { - name: 'Operating System', + name: i18n.translate('xpack.infra.hostsTable.operatingSystemColumnHeader', { + defaultMessage: 'Operating System', + }), field: 'os', render: (os: string) => {os ?? '-'}, }, { - name: '# of CPUs', + name: i18n.translate('xpack.infra.hostsTable.numberOfCpusColumnHeader', { + defaultMessage: '# of CPUs', + }), field: 'cpuCores', render: (cpuCores: { value: number }) => , }, { - name: 'Disk Latency', + name: i18n.translate('xpack.infra.hostsTable.diskLatencyColumnHeader', { + defaultMessage: 'Disk Latency', + }), field: 'cpuCores', render: (ds: number) => , }, { - name: 'TX (avg.)', + name: i18n.translate('xpack.infra.hostsTable.averageTxColumnHeader', { + defaultMessage: 'TX (avg.)', + }), field: 'tx', render: (tx: { avg: number }) => , }, { - name: 'RX (avg.)', + name: i18n.translate('xpack.infra.hostsTable.averageRxColumnHeader', { + defaultMessage: 'RX (avg.)', + }), field: 'rx', render: (rx: { avg: number }) => , }, { - name: 'Memory total (avg.)', + name: i18n.translate('xpack.infra.hostsTable.averageMemoryTotalColumnHeader', { + defaultMessage: 'Memory total (avg.)', + }), field: 'memoryTotal', render: (memoryTotal: { avg: number }) => ( ), }, { - name: 'Services on Host', + name: i18n.translate('xpack.infra.hostsTable.servicesOnHostColumnHeader', { + defaultMessage: 'Services on Host', + }), field: 'servicesOnHost', render: (servicesOnHost: number) => , }, { - name: 'Memory usage (avg.)', + name: i18n.translate('xpack.infra.hostsTable.averageMemoryUsageColumnHeader', { + defaultMessage: 'Memory usage (avg.)', + }), field: 'memory', render: (memory: { avg: number }) => ( diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index 8a1fda344a013..6723fa8baf160 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -15664,6 +15664,15 @@ "xpack.infra.homePage.noMetricsIndicesInstructionsActionLabel": "Voir les instructions de configuration", "xpack.infra.homePage.settingsTabTitle": "Paramètres", "xpack.infra.homePage.toolbar.kqlSearchFieldPlaceholder": "Rechercher des données d'infrastructure… (par exemple host.name:host-1)", + "xpack.infra.hostsTable.nameColumnHeader": "Nom", + "xpack.infra.hostsTable.operatingSystemColumnHeader": "Système d'exploitation", + "xpack.infra.hostsTable.numberOfCpusColumnHeader": "Nombre de processeurs", + "xpack.infra.hostsTable.diskLatencyColumnHeader": "", + "xpack.infra.hostsTable.averageTxColumnHeader": "", + "xpack.infra.hostsTable.averageRxColumnHeader": "", + "xpack.infra.hostsTable.averageMemoryTotalColumnHeader": "Total de la mémoire (moy.)", + "xpack.infra.hostsTable.servicesOnHostColumnHeader": "", + "xpack.infra.hostsTable.averageMemoryUsageColumnHeader": "Utilisation de la mémoire (moy.)", "xpack.infra.infra.nodeDetails.apmTabLabel": "APM", "xpack.infra.infra.nodeDetails.createAlertLink": "Créer une règle d'inventaire", "xpack.infra.infra.nodeDetails.openAsPage": "Ouvrir en tant que page", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 79f3d61efeae0..0a1a3853896e4 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -15649,6 +15649,15 @@ "xpack.infra.homePage.noMetricsIndicesInstructionsActionLabel": "セットアップの手順を表示", "xpack.infra.homePage.settingsTabTitle": "設定", "xpack.infra.homePage.toolbar.kqlSearchFieldPlaceholder": "インフラストラクチャデータを検索…(例:host.name:host-1)", + "xpack.infra.hostsTable.nameColumnHeader": "名前", + "xpack.infra.hostsTable.operatingSystemColumnHeader": "オペレーティングシステム", + "xpack.infra.hostsTable.numberOfCpusColumnHeader": "CPU数", + "xpack.infra.hostsTable.diskLatencyColumnHeader": "", + "xpack.infra.hostsTable.averageTxColumnHeader": "", + "xpack.infra.hostsTable.averageRxColumnHeader": "", + "xpack.infra.hostsTable.averageMemoryTotalColumnHeader": "メモリ合計 (平均) ", + "xpack.infra.hostsTable.servicesOnHostColumnHeader": "", + "xpack.infra.hostsTable.averageMemoryUsageColumnHeader": "メモリー使用状況(平均)", "xpack.infra.infra.nodeDetails.apmTabLabel": "APM", "xpack.infra.infra.nodeDetails.createAlertLink": "インベントリルールの作成", "xpack.infra.infra.nodeDetails.openAsPage": "ページとして開く", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index d0852f4c84387..ead91f528c2d7 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -15670,6 +15670,15 @@ "xpack.infra.homePage.noMetricsIndicesInstructionsActionLabel": "查看设置说明", "xpack.infra.homePage.settingsTabTitle": "设置", "xpack.infra.homePage.toolbar.kqlSearchFieldPlaceholder": "搜索基础设施数据……(例如 host.name:host-1)", + "xpack.infra.hostsTable.nameColumnHeader": "名称", + "xpack.infra.hostsTable.operatingSystemColumnHeader": "操作系统", + "xpack.infra.hostsTable.numberOfCpusColumnHeader": "# 个 CPU", + "xpack.infra.hostsTable.diskLatencyColumnHeader": "", + "xpack.infra.hostsTable.averageTxColumnHeader": "", + "xpack.infra.hostsTable.averageRxColumnHeader": "", + "xpack.infra.hostsTable.averageMemoryTotalColumnHeader": "内存合计 (平均值)", + "xpack.infra.hostsTable.servicesOnHostColumnHeader": "", + "xpack.infra.hostsTable.averageMemoryUsageColumnHeader": "内存使用率(平均值)", "xpack.infra.infra.nodeDetails.apmTabLabel": "APM", "xpack.infra.infra.nodeDetails.createAlertLink": "创建库存规则", "xpack.infra.infra.nodeDetails.openAsPage": "以页面形式打开", From 5ae30bea5a1158f018ad255cdfc3ecdef27e3d29 Mon Sep 17 00:00:00 2001 From: Jenny Date: Fri, 14 Oct 2022 18:55:32 +0200 Subject: [PATCH 15/22] Add fixed range and cleanup --- .../metrics/hosts/components/hosts_table.tsx | 12 +----------- .../pages/metrics/hosts/hosts_content.tsx | 18 +++++++++--------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx index 61e5ff9693cb9..55815f172d414 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx @@ -5,26 +5,16 @@ * 2.0. */ -import type { Query, TimeRange } from '@kbn/es-query'; import React from 'react'; -import type { DataView } from '@kbn/data-views-plugin/public'; import { EuiBasicTable } from '@elastic/eui'; import { SnapshotNode } from '../../../../../common/http_api'; import { HostsTableColumns } from './hosts_table_columns'; import { useHostTable } from '../hooks/use_host_table'; interface Props { - dataView: DataView; - timeRange: TimeRange; - query: Query; nodes: SnapshotNode[]; } -export const HostsTable: React.FunctionComponent = ({ - dataView, - timeRange, - query, - nodes, -}) => { +export const HostsTable: React.FunctionComponent = ({ nodes }) => { const items = useHostTable(nodes); return ( diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx index 727d673ac521c..aa41e3a824fb6 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx @@ -42,7 +42,6 @@ export const HostsContent: React.FunctionComponent = () => { { type: 'memory' }, { type: 'cpuCores' }, { type: 'memoryTotal' }, - // add others ]; const { loading, nodes, reload } = useSnapshot( @@ -51,10 +50,16 @@ export const HostsContent: React.FunctionComponent = () => { [], 'host', sourceId, - 1665482950000, // currentTime. need to add support for TimeRange? + 1665748800000, // currentTime. need to add support for TimeRange? '', '', - true + true, + { + from: 1665748800000, // dynamic time range needs to be supported + interval: '1m', + lookbackSize: 5, + to: 1665752400000, + } ); const noData = !loading && nodes && nodes.length === 0; @@ -94,12 +99,7 @@ export const HostsContent: React.FunctionComponent = () => { onQuerySubmit={onQuerySubmit} /> - + ) ) : hasFailedCreatingDataView || hasFailedFetchingDataView ? ( From 9ab9f8ab2df9ff6de7d6dc613b9148dedf9ee3d3 Mon Sep 17 00:00:00 2001 From: Jenny Date: Tue, 18 Oct 2022 12:19:32 +0200 Subject: [PATCH 16/22] Fix diskLatency field name --- .../pages/metrics/hosts/components/hosts_table_columns.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx index 6b2dab60b0d00..4101ad3938318 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx @@ -54,7 +54,7 @@ export const HostsTableColumns: Array> = [ name: i18n.translate('xpack.infra.hostsTable.diskLatencyColumnHeader', { defaultMessage: 'Disk Latency', }), - field: 'cpuCores', + field: 'diskLatency', render: (ds: number) => , }, { From 263ee4db837d82e515982877a02e4cc4a26e83fe Mon Sep 17 00:00:00 2001 From: Jenny Date: Tue, 18 Oct 2022 14:06:05 +0200 Subject: [PATCH 17/22] Remove not existing showQueryBar prop from SearchBar and set time range values --- .../infra/public/pages/metrics/hosts/hosts_content.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx index aa41e3a824fb6..1797b61b82e41 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx @@ -50,15 +50,15 @@ export const HostsContent: React.FunctionComponent = () => { [], 'host', sourceId, - 1665748800000, // currentTime. need to add support for TimeRange? + 1666081614879, // currentTime. need to add support for TimeRange? '', '', true, { - from: 1665748800000, // dynamic time range needs to be supported + from: 1666081614879, // dynamic time range needs to be supported interval: '1m', lookbackSize: 5, - to: 1665752400000, + to: 1666082814879, } ); @@ -86,7 +86,6 @@ export const HostsContent: React.FunctionComponent = () => { ) : ( <> Date: Thu, 20 Oct 2022 13:18:40 +0200 Subject: [PATCH 18/22] Use last path --- .../infra/public/pages/metrics/hosts/hooks/use_host_table.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.ts b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.ts index 0b204071ffd3e..4c604b2a27217 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.ts +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.ts @@ -5,8 +5,9 @@ * 2.0. */ +import { last } from 'lodash'; import { useMemo } from 'react'; -import { SnapshotNode, SnapshotNodeMetric } from '../../../../../common/http_api'; +import type { SnapshotNode, SnapshotNodeMetric } from '../../../../../common/http_api'; import { HostMetics } from '../components/hosts_table_columns'; type MappedMetrics = Record; @@ -14,7 +15,7 @@ type MappedMetrics = Record; export const useHostTable = (nodes: SnapshotNode[]) => { const items: MappedMetrics[] = useMemo(() => { return nodes.map(({ metrics, path }) => ({ - ...path[0], + ...last(path), ...metrics.reduce((data, metric) => { data[metric.name as keyof HostMetics] = metric; return data; From 0d07ca1bc5df008915141d291aac0f783470c3aa Mon Sep 17 00:00:00 2001 From: Jenny Date: Thu, 20 Oct 2022 13:42:45 +0200 Subject: [PATCH 19/22] Test last path change --- .../public/pages/metrics/hosts/hooks/use_host_table.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.test.ts b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.test.ts index 4c63c7275bc65..e0d26413f0453 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.test.ts +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hooks/use_host_table.test.ts @@ -60,7 +60,10 @@ describe('useHostTable hook', () => { avg: 9.194304, }, ], - path: [{ value: 'host-1', label: 'host-1', ip: '243.86.94.22', os: 'macOS' }], + path: [ + { value: 'host-1', label: 'host-1' }, + { value: 'host-1', label: 'host-1', ip: '243.86.94.22', os: 'macOS' }, + ], name: 'host-1', }, ]; From e1f58f10adb927541b4f93175fb2497318fbf568 Mon Sep 17 00:00:00 2001 From: Jenny Date: Thu, 20 Oct 2022 13:44:08 +0200 Subject: [PATCH 20/22] Type imports --- .../pages/metrics/hosts/components/hosts_table_columns.tsx | 2 +- .../plugins/infra/public/pages/metrics/hosts/hosts_content.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx index 4101ad3938318..7bd8184b0e464 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table_columns.tsx @@ -10,7 +10,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { EuiText } from '@elastic/eui'; import { scaleUpPercentage } from '../../../../components/infrastructure_node_metrics_tables/shared/hooks'; -import { SnapshotNodeMetric } from '../../../../../common/http_api/snapshot_api'; +import type { SnapshotNodeMetric } from '../../../../../common/http_api/snapshot_api'; import { NumberCell } from '../../../../components/infrastructure_node_metrics_tables/shared/components'; interface HostNodeRow extends HostMetics { diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx index 1797b61b82e41..25aa168ca8dc0 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx @@ -16,7 +16,7 @@ import { useMetricsDataViewContext } from './hooks/use_data_view'; import { HostsTable } from './components/hosts_table'; import { useSourceContext } from '../../../containers/metrics_source'; import { useSnapshot } from '../inventory_view/hooks/use_snaphot'; -import { SnapshotMetricType } from '../../../../common/inventory_models/types'; +import type { SnapshotMetricType } from '../../../../common/inventory_models/types'; export const HostsContent: React.FunctionComponent = () => { const { source, sourceId } = useSourceContext(); From 662c7ae3b7fa41489776a636aca0f82b561d2206 Mon Sep 17 00:00:00 2001 From: Jenny Date: Thu, 20 Oct 2022 13:45:10 +0200 Subject: [PATCH 21/22] Change the way lastPath.os is set --- .../routes/snapshot/lib/apply_metadata_to_last_path.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/infra/server/routes/snapshot/lib/apply_metadata_to_last_path.ts b/x-pack/plugins/infra/server/routes/snapshot/lib/apply_metadata_to_last_path.ts index 1c11753014791..07fa1ac9cd1cf 100644 --- a/x-pack/plugins/infra/server/routes/snapshot/lib/apply_metadata_to_last_path.ts +++ b/x-pack/plugins/infra/server/routes/snapshot/lib/apply_metadata_to_last_path.ts @@ -46,7 +46,7 @@ export const applyMetadataToLastPath = ( // Set the label as the name and fallback to the id OR path.value lastPath.label = (firstMetaDoc[inventoryFields.name] ?? lastPath.value) as string; // If the inventory fields contain an ip address, we need to try and set that - // on the path object. IP addersses are typically stored as multiple fields. We will + // on the path object. IP addresses are typically stored as multiple fields. We will // use the first IPV4 address we find. if (inventoryFields.ip) { const ipAddresses = get(firstMetaDoc, inventoryFields.ip) as string[]; @@ -57,8 +57,7 @@ export const applyMetadataToLastPath = ( } } if (inventoryFields.os) { - const inventoryFieldsOs = get(firstMetaDoc, inventoryFields.os) as string; - lastPath.os = inventoryFieldsOs; + lastPath.os = get(firstMetaDoc, inventoryFields.os) as string; } return [...node.path.slice(0, node.path.length - 1), lastPath]; } From a4bd9a53c2e496796610d9944e4add0ad26ceda9 Mon Sep 17 00:00:00 2001 From: Jenny Date: Thu, 20 Oct 2022 13:47:53 +0200 Subject: [PATCH 22/22] Type import --- .../infra/public/pages/metrics/hosts/components/hosts_table.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx index 03230bffd1c39..f81f80faca73e 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/hosts_table.tsx @@ -7,7 +7,7 @@ import React from 'react'; import { EuiBasicTable } from '@elastic/eui'; -import { SnapshotNode } from '../../../../../common/http_api'; +import type { SnapshotNode } from '../../../../../common/http_api'; import { HostsTableColumns } from './hosts_table_columns'; import { useHostTable } from '../hooks/use_host_table';