Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as React from 'react';
import Moment from 'react-moment';
import {Pod, ResourceName} from '../../../shared/models';
import {isYoungerThanXMinutes} from '../utils';
import {formatMetric} from './pod-view';
import {isYoungerThanXMinutes, formatResourceInfo} from '../utils';

export const PodTooltip = (props: {pod: Pod}) => {
const pod = props.pod;
Expand All @@ -23,10 +22,20 @@ export const PodTooltip = (props: {pod: Pod}) => {
})
.map(i => {
const isPodRequests = i.name === ResourceName.ResourceCPU || i.name === ResourceName.ResourceMemory;
const formattedValue = isPodRequests ? formatMetric(i.name as ResourceName, parseInt(i.value, 10)) : i.value;
let formattedValue = i.value;
let label = `${i.name}:`;

//this is just to show cpu and mem info with "Requests" as prefix
const label = i.name === ResourceName.ResourceCPU ? 'Requests CPU:' : i.name === ResourceName.ResourceMemory ? 'Requests MEM:' : `${i.name}:`;
if (isPodRequests) {
if (i.name === ResourceName.ResourceCPU) {
const {displayValue} = formatResourceInfo('cpu', i.value);
formattedValue = displayValue;
label = 'Requests CPU:';
} else if (i.name === ResourceName.ResourceMemory) {
const {displayValue} = formatResourceInfo('memory', i.value);
formattedValue = displayValue;
label = 'Requests MEM:';
}
}

return (
<div className='row' key={i.name}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
position: absolute;
color: #A3A3A3;
font-size: 10px;
top: -10px;
top: -9px;
transform: rotate(180deg);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
NodeId,
nodeKey,
PodHealthIcon,
getUsrMsgKeyToDisplay
getUsrMsgKeyToDisplay,
formatResourceInfo
} from '../utils';
import {NodeUpdateAnimation} from './node-update-animation';
import {PodGroup} from '../application-pod-view/pod-view';
Expand Down Expand Up @@ -530,11 +531,19 @@ function renderPodGroup(props: ApplicationResourceTreeProps, id: string, node: R
<Tooltip
content={
<>
{(node.info || []).map(i => (
<div key={i.name}>
{i.name}: {i.value}
</div>
))}
{(node.info || []).map(i => {
// Use common formatting function for CPU and Memory
if (i.name === 'cpu' || i.name === 'memory') {
const {tooltipValue} = formatResourceInfo(i.name, `${i.value}`);
return <div key={i.name}>{tooltipValue}</div>;
} else {
return (
<div key={i.name}>
{i.name}: {i.value}
</div>
);
}
})}
</>
}
key={node.uid}>
Expand Down Expand Up @@ -662,9 +671,9 @@ function expandCollapse(node: ResourceTreeNode, props: ApplicationResourceTreePr

function NodeInfoDetails({tag: tag, kind: kind}: {tag: models.InfoItem; kind: string}) {
if (kind === 'Pod') {
const val = `${tag.name}`;
const val = tag.name;
if (val === 'Status Reason') {
if (`${tag.value}` !== 'ImagePullBackOff')
if (String(tag.value) !== 'ImagePullBackOff')
return (
<span className='application-resource-tree__node-label' title={`Status: ${tag.value}`}>
{tag.value}
Expand All @@ -680,10 +689,10 @@ function NodeInfoDetails({tag: tag, kind: kind}: {tag: models.InfoItem; kind: st
);
}
} else if (val === 'Containers') {
const arr = `${tag.value}`.split('/');
const arr = String(tag.value).split('/');
const title = `Number of containers in total: ${arr[1]} \nNumber of ready containers: ${arr[0]}`;
return (
<span className='application-resource-tree__node-label' title={`${title}`}>
<span className='application-resource-tree__node-label' title={title}>
{tag.value}
</span>
);
Expand All @@ -699,6 +708,14 @@ function NodeInfoDetails({tag: tag, kind: kind}: {tag: models.InfoItem; kind: st
{tag.value}
</span>
);
} else if (val === 'cpu' || val === 'memory') {
// Use common formatting function for CPU and Memory
const {displayValue, tooltipValue} = formatResourceInfo(val, String(tag.value));
return (
<span className='application-resource-tree__node-label' title={tooltipValue}>
{displayValue}
</span>
);
} else {
return (
<span className='application-resource-tree__node-label' title={`${tag.name}: ${tag.value}`}>
Expand Down Expand Up @@ -801,19 +818,27 @@ function renderResourceNode(props: ApplicationResourceTreeProps, id: string, nod
) : null}
{(node.info || [])
.filter(tag => !tag.name.includes('Node'))
.slice(0, 4)
.slice(0, 2)
.map((tag, i) => {
return <NodeInfoDetails tag={tag} kind={node.kind} key={i} />;
})}
{(node.info || []).length > 4 && (
{(node.info || []).length > 3 && (
<Tooltip
content={
<>
{(node.info || []).map(i => (
<div key={i.name}>
{i.name}: {i.value}
</div>
))}
{(node.info || []).map(i => {
// Use common formatting function for CPU and Memory
if (i.name === 'cpu' || i.name === 'memory') {
const {tooltipValue} = formatResourceInfo(i.name, `${i.value}`);
return <div key={i.name}>{tooltipValue}</div>;
} else {
return (
<div key={i.name}>
{i.name}: {i.value}
</div>
);
}
})}
</>
}
key={node.uid}>
Expand Down
40 changes: 40 additions & 0 deletions ui/src/app/applications/components/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1815,3 +1815,43 @@ export const podRequests = {
CPU: 'Requests (CPU)',
MEMORY: 'Requests (MEM)'
} as const;

export function formatResourceInfo(name: string, value: string): {displayValue: string; tooltipValue: string} {
const numValue = parseInt(value, 10);

const formatCPUValue = (milliCpu: number): string => {
return milliCpu >= 1000 ? `${(milliCpu / 1000).toFixed(1)}` : `${milliCpu}m`;
};

const formatMemoryValue = (milliBytes: number): string => {
const mib = Math.round(milliBytes / (1024 * 1024 * 1000));
return `${mib}Mi`;
};

const formatCPUTooltip = (milliCpu: number): string => {
const displayValue = milliCpu >= 1000 ? `${(milliCpu / 1000).toFixed(1)} cores` : `${milliCpu}m`;
return `CPU Request: ${displayValue}`;
};

const formatMemoryTooltip = (milliBytes: number): string => {
const mib = Math.round(milliBytes / (1024 * 1024 * 1000));
return `Memory Request: ${mib}Mi`;
};

if (name === 'cpu') {
return {
displayValue: formatCPUValue(numValue),
tooltipValue: formatCPUTooltip(numValue)
};
} else if (name === 'memory') {
return {
displayValue: formatMemoryValue(numValue),
tooltipValue: formatMemoryTooltip(numValue)
};
}

return {
displayValue: value,
tooltipValue: `${name}: ${value}`
};
}
Loading