Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Infra UI] Display non-metric details on Node Detail page #43551

Merged
merged 14 commits into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/infrastructure/images/infra-view-metrics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/infrastructure/view-metrics.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
== Viewing infrastructure metrics

When you select *View Metrics* for a component in your infrastructure from the <<infra-ui, Infrastructure app in Kibana>>, you can view detailed metrics for that component, and for any related components.
You can also view additional component metadata.

[role="screenshot"]
image::infrastructure/images/infra-view-metrics.png[Infrastructure View Metrics in Kibana]
Expand Down
156 changes: 156 additions & 0 deletions x-pack/legacy/plugins/infra/public/components/metrics/node_details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* 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, useMemo } 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;
}

interface FieldDef {
field: string;
label: string;
isBoolean?: boolean;
}

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',
}),
isBoolean: true,
},
{
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',
}),
},
] as FieldDef[];

const getLabelForField = ({ field }: FieldDef) => {
const fieldDef = FIELDS.find(f => f.field === field);
if (!fieldDef) return field;
return fieldDef.label;
};

const getValueForField = (metadata: InfraMetadata, { field, isBoolean }: FieldDef) => {
if (isBoolean) {
return get(metadata.info, field, false)
? i18n.translate('xpack.infra.nodeDetails.yes', { defaultMessage: 'Yes' })
: i18n.translate('xpack.infra.nodeDetails.no', { defaultMessage: 'No' });
}
const value = get(metadata.info, field, '--');
return value;
};

export const NodeDetails = ({ metadata }: Props) => {
const [isOpen, setControlState] = useState<boolean>(false);

const toggleIsOpen = useCallback(
() => (isOpen ? setControlState(false) : setControlState(true)),
[isOpen]
);

const fields = useMemo(() => (isOpen ? FIELDS : FIELDS.slice(0, 4)), [isOpen]);

if (!metadata) {
return null;
}

return (
<NodeDetailsContainer>
<Controls>
<EuiButtonIcon
iconType={isOpen ? 'arrowUp' : 'arrowDown'}
onClick={toggleIsOpen}
aria-label={i18n.translate('xpack.infra.nodeDetails.labels.showMoreDetails', {
defaultMessage: 'Show more details',
})}
/>
</Controls>
<EuiFlexGrid columns={4} style={{ flexGrow: 1 }}>
{fields.map(field => (
<EuiFlexItem key={field.field} style={{ minWidth: 0 }}>
simianhacker marked this conversation as resolved.
Show resolved Hide resolved
<EuiTitle size="xs">
<h4>{getLabelForField(field)}</h4>
</EuiTitle>
<EuiText>{getValueForField(metadata, field)}</EuiText>
</EuiFlexItem>
))}
</EuiFlexGrid>
</NodeDetailsContainer>
);
};

const NodeDetailsContainer = euiStyled.div`
border-top: ${props => props.theme.eui.euiBorderWidthThin} solid ${props =>
props.theme.eui.euiBorderColor};
border-bottom: ${props => props.theme.eui.euiBorderWidthThin} 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};
`;
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function useMetadata(
filteredLayouts: (response && getFilteredLayouts(layouts, response.features)) || [],
error: (error && error.message) || null,
loading,
metadata: response,
cloudId:
(response &&
response.info &&
Expand Down
5 changes: 3 additions & 2 deletions x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -230,7 +231,7 @@ export const MetricDetail = withMetricPageProviders(
</MetricsTitleTimeRangeContainer>
</EuiPageHeaderSection>
</EuiPageHeader>

<NodeDetails metadata={metadata} />
<EuiPageContentWithRelative>
<Metrics
label={name}
Expand Down