Skip to content

Commit

Permalink
Merge pull request #27 from jasonrhodes/k8s-node-logs-table-tweaks
Browse files Browse the repository at this point in the history
Fixing design for k8s node representation
  • Loading branch information
jasonrhodes authored Feb 9, 2023
2 parents 299710f + 5d9030c commit 8fcabce
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 136 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 { EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiText } from '@elastic/eui';
import React, { Fragment } from 'react';

export interface DLItem {
title: string;
description: string | React.ReactNode;
}

export function CustomDescriptionList({ items }: { items: DLItem[] }) {
const pairs = items.reduce<Array<[DLItem, DLItem?]>>((p, item) => {
const latest = p[p.length - 1];
if (!latest || latest.length === 2) {
p.push([item]);
} else if (latest.length === 1) {
latest.push(item);
}
return p;
}, []);

return (
<>
{pairs.map((pair, i) => (
<Fragment key={`dl-row-${i}`}>
<EuiFlexGroup>
<CustomDLItem item={pair[0]} />
<CustomDLItem item={pair[1]} />
</EuiFlexGroup>
{i === pairs.length - 1 ? null : <EuiSpacer />}
</Fragment>
))}
</>
);
}

function CustomDLItem({ item }: { item?: DLItem }) {
if (!item) {
return null;
}

return (
<EuiFlexItem>
<EuiText>
<b>{item.title}</b>
</EuiText>
<div>{item.description}</div>
</EuiFlexItem>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
* 2.0.
*/

import { EuiDescriptionList, EuiHealth, EuiIcon, EuiPageTemplate, EuiSpacer } from '@elastic/eui';
import { EuiHealth, EuiIcon, EuiPageTemplate } from '@elastic/eui';
import { capitalize } from 'lodash';
import React from 'react';
import { K8sCluster } from '../../common/types_api';
import { cloudIconMap, statusMap } from '../constants';
import { CustomDescriptionList, DLItem } from './custom_description_list';
import { K8sNodesTable } from './k8s_nodes_table';
import { SectionRule } from './section_rule';

export function K8sClusterInfo({ cluster }: { cluster: K8sCluster }) {
const list: Array<{ title: string; description: React.ReactChild }> = [
const list: DLItem[] = [
{
title: 'Cluster name',
description: cluster.name || '',
description: cluster.name,
},
{
title: 'Status',
Expand All @@ -28,20 +30,12 @@ export function K8sClusterInfo({ cluster }: { cluster: K8sCluster }) {
},
{
title: 'Version',
description: cluster.version || '',
description: cluster.version,
},
{
title: '',
description: '',
},
// {
// title: 'Nodes',
// description: (
// <ul>
// {nodes.map((node) => (
// <li key={node.id}>
// <Link to={`/k8s/nodes/${node.name}`}>{node.name}</Link>
// </li>
// ))}
// </ul>
// ),
// },
];

if (cluster.cloud?.provider) {
Expand All @@ -61,8 +55,8 @@ export function K8sClusterInfo({ cluster }: { cluster: K8sCluster }) {
return (
<>
<EuiPageTemplate.Section>
<EuiDescriptionList listItems={list} />
<EuiSpacer />
<CustomDescriptionList items={list} />
<SectionRule />
<K8sNodesTable nodes={cluster.nodes} />
</EuiPageTemplate.Section>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* 2.0.
*/

import { EuiInMemoryTable, EuiText } from '@elastic/eui';
import { EuiInMemoryTable, EuiSpacer, EuiText } from '@elastic/eui';
import React from 'react';
import { K8sNodeLog } from '../../common/types_api';
import { relativeTimeString } from '../lib/relative_time';

export function K8sLogsTable({ logs }: { logs: K8sNodeLog[] }) {
const columns = [
Expand All @@ -17,7 +16,7 @@ export function K8sLogsTable({ logs }: { logs: K8sNodeLog[] }) {
name: 'Timestamp',
sortable: true,
width: '400px',
render: (ts: string) => relativeTimeString(new Date(ts)),
render: (ts: string) => getUTCTime(new Date(ts)),
},
{
field: 'message',
Expand All @@ -29,8 +28,9 @@ export function K8sLogsTable({ logs }: { logs: K8sNodeLog[] }) {
return (
<>
<EuiText>
<b>Node Logs (Last 12 Hours)</b>
<b>Node Logs (Last 24 Hours, 500 logs max)</b>
</EuiText>
<EuiSpacer />
<EuiInMemoryTable<K8sNodeLog>
loading={false}
columns={columns}
Expand All @@ -47,3 +47,18 @@ export function K8sLogsTable({ logs }: { logs: K8sNodeLog[] }) {
</>
);
}

function getUTCTime(date: Date) {
const hour = padLeft(date.getUTCHours());
const minute = padLeft(date.getUTCMinutes());
const second = padLeft(date.getUTCSeconds());
return `${hour}:${minute}:${second}`;
}

function padLeft(n: number) {
if (n < 10) {
return `0${n}`;
}

return `${n}`;
}
Loading

0 comments on commit 8fcabce

Please sign in to comment.