From 1fd31357141e9f2129b64ba5710322c2ffa1202e Mon Sep 17 00:00:00 2001 From: Chris Cowan Date: Mon, 19 Aug 2019 14:32:08 -0700 Subject: [PATCH] [Infra UI] Display non-metric details on Node Detail page - Closes #42689 - Adds NodeDetails component --- .../components/metrics/node_details.tsx | 143 ++++++++++++++++++ .../containers/metadata/use_metadata.ts | 1 + .../infra/public/pages/metrics/index.tsx | 5 +- 3 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 x-pack/legacy/plugins/infra/public/components/metrics/node_details.tsx diff --git a/x-pack/legacy/plugins/infra/public/components/metrics/node_details.tsx b/x-pack/legacy/plugins/infra/public/components/metrics/node_details.tsx new file mode 100644 index 0000000000000..9d8d642681a5a --- /dev/null +++ b/x-pack/legacy/plugins/infra/public/components/metrics/node_details.tsx @@ -0,0 +1,143 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React, { useState, useCallback } from 'react'; +import { EuiButtonIcon, EuiFlexGrid, EuiFlexItem, EuiTitle, EuiText } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { get } from 'lodash'; +import { InfraMetadata } from '../../../common/http_api'; +import euiStyled from '../../../../../common/eui_styled_components'; + +interface Props { + metadata?: InfraMetadata | null; +} + +const FIELDS = [ + { + field: 'cloud.instance.id', + label: i18n.translate('xpack.infra.nodeDetails.labels.instanceId', { + defaultMessage: 'Instance ID', + }), + }, + { + field: 'cloud.provider', + label: i18n.translate('xpack.infra.nodeDetails.labels.cloudProvider', { + defaultMessage: 'Cloud Provider', + }), + }, + { + field: 'host.os.name', + label: i18n.translate('xpack.infra.nodeDetails.labels.operatinSystem', { + defaultMessage: 'Operating System', + }), + }, + { + field: 'host.os.kernel', + label: i18n.translate('xpack.infra.nodeDetails.labels.kernelVersion', { + defaultMessage: 'Kernel Version', + }), + }, + { + field: 'host.hostname', + label: i18n.translate('xpack.infra.nodeDetails.labels.hostname', { + defaultMessage: 'Hostname', + }), + }, + { + field: 'host.containerized', + label: i18n.translate('xpack.infra.nodeDetails.labels.containerized', { + defaultMessage: 'Containerized', + }), + }, + { + field: 'cloud.project.id', + label: i18n.translate('xpack.infra.nodeDetails.labels.projectId', { + defaultMessage: 'Project ID', + }), + }, + { + field: 'cloud.availability_zone', + label: i18n.translate('xpack.infra.nodeDetails.labels.availabilityZone', { + defaultMessage: 'Availability Zone', + }), + }, + { + field: 'cloud.machine.type', + label: i18n.translate('xpack.infra.nodeDetails.labels.machineType', { + defaultMessage: 'Machine Type', + }), + }, + { + field: 'cloud.instance.name', + label: i18n.translate('xpack.infra.nodeDetails.labels.instanceName', { + defaultMessage: 'Instance Name', + }), + }, +]; + +const getLabelForField = (field: string) => { + const fieldDef = FIELDS.find(f => f.field === field); + if (!fieldDef) return field; + return fieldDef.label; +}; + +const getValueForField = (metadata: InfraMetadata, field: string) => { + const value = get(metadata.info, field, '--'); + if (field !== 'host.containerized') { + return value; + } + return value !== '--' + ? i18n.translate('xpack.infra.nodeDetails.yes', { defaultMessage: 'Yes' }) + : i18n.translate('xpack.infra.nodeDetails.no', { defaultMessage: 'No' }); +}; + +export const NodeDetails = ({ metadata }: Props) => { + const [isOpen, setControlState] = useState(false); + if (!metadata) { + return null; + } + + const handleClick = useCallback(() => (isOpen ? setControlState(false) : setControlState(true)), [ + isOpen, + ]); + + return ( + + + + + + {FIELDS.slice(0, isOpen ? FIELDS.length : 4).map(({ field }) => ( + + +

{getLabelForField(field)}

+
+ {getValueForField(metadata, field)} +
+ ))} +
+
+ ); +}; + +const NodeDetailsContainer = euiStyled.div` +border-top: 1px solid ${props => props.theme.eui.euiBorderColor}; +border-bottom: 1px solid ${props => props.theme.eui.euiBorderColor}; +padding: ${props => props.theme.eui.paddingSizes.m} 0; +margin-bottom: ${props => props.theme.eui.paddingSizes.m}; +display: flex; +`; + +const Controls = euiStyled.div` +flex-grow: 0; +margin-right: ${props => props.theme.eui.paddingSizes.m}; +`; diff --git a/x-pack/legacy/plugins/infra/public/containers/metadata/use_metadata.ts b/x-pack/legacy/plugins/infra/public/containers/metadata/use_metadata.ts index c3b81ad37cfa9..8e14120616803 100644 --- a/x-pack/legacy/plugins/infra/public/containers/metadata/use_metadata.ts +++ b/x-pack/legacy/plugins/infra/public/containers/metadata/use_metadata.ts @@ -44,6 +44,7 @@ export function useMetadata( filteredLayouts: (response && getFilteredLayouts(layouts, response.features)) || [], error: (error && error.message) || null, loading, + metadata: response, cloudId: (response && response.info && diff --git a/x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx b/x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx index e43e5ef95bbf2..1ad22be94c481 100644 --- a/x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx +++ b/x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx @@ -41,6 +41,7 @@ import { withMetricPageProviders } from './page_providers'; import { useMetadata } from '../../containers/metadata/use_metadata'; import { Source } from '../../containers/source'; import { InfraLoadingPanel } from '../../components/loading'; +import { NodeDetails } from '../../components/metrics/node_details'; const DetailPageContent = euiStyled(PageContent)` overflow: auto; @@ -87,7 +88,7 @@ export const MetricDetail = withMetricPageProviders( } const { sourceId } = useContext(Source.Context); const layouts = layoutCreator(theme); - const { name, filteredLayouts, loading: metadataLoading, cloudId } = useMetadata( + const { name, filteredLayouts, loading: metadataLoading, cloudId, metadata } = useMetadata( nodeId, nodeType, layouts, @@ -227,7 +228,7 @@ export const MetricDetail = withMetricPageProviders( - +