Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

7.6 KB
Raw Blame
import { Color } from '@signozhq/design-tokens';
import {
	InframonitoringtypesNodeConditionDTO,
	InframonitoringtypesNodeRecordDTO,
} from 'api/generated/services/sigNoz.schemas';
import TanStackTable, { TableColumnDef } from 'components/TanStackTableView';
import { ExpandButtonWrapper } from 'container/InfraMonitoringK8sV2/components';

import ColumnHeader from '../Base/ColumnHeader';
import EntityGroupHeader from '../Base/EntityGroupHeader';
import K8sGroupCell from '../Base/K8sGroupCell';
import ClickableStatusBadge from '../Base/components/StatusFilterCells/ClickableStatusBadge';
import ClickableStatusCounts from '../Base/components/StatusFilterCells/ClickableStatusCounts';
import { formatBytes, getPodStatusItems } from '../commonUtils';
import {
	INFRA_MONITORING_ATTR_KEYS,
	InfraMonitoringEntity,
} from '../constants';
import { TextNoData, ValidateColumnValueWrapper } from '../components';
import { NODE_CONDITION_COLORS, NODE_CONDITION_LABELS } from './utils';
import { Workflow } from '@signozhq/icons';

export function getK8sNodeRowKey(
	node: InframonitoringtypesNodeRecordDTO,
): string {
	return (
		node.nodeName || node.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_NODE_UID] || ''
	);
}

export function getK8sNodeItemKey(
	node: InframonitoringtypesNodeRecordDTO,
): string {
	return node.nodeName;
}

export type NodeTableColumnConfig =
	TableColumnDef<InframonitoringtypesNodeRecordDTO>;
export const k8sNodesColumnsConfig: NodeTableColumnConfig[] = [
	{
		id: 'nodeGroup',
		header: (): React.ReactNode => <EntityGroupHeader title="Node Group" />,
		accessorFn: (row): string => row.nodeName || '',
		width: { min: 290 },
		enableSort: false,
		enableRemove: false,
		enableMove: false,
		pin: 'left',
		visibilityBehavior: 'hidden-on-collapse',
		cell: ({ isExpanded, toggleExpanded, row }): JSX.Element | null => {
			return (
				<ExpandButtonWrapper
					isExpanded={isExpanded}
					toggleExpanded={toggleExpanded}
				>
					<K8sGroupCell row={row} />
				</ExpandButtonWrapper>
			);
		},
	},
	{
		id: INFRA_MONITORING_ATTR_KEYS.K8S_NODE_NAME,
		header: (): React.ReactNode => (
			<EntityGroupHeader
				title="Node Name"
				icon={<Workflow data-hide-expanded="true" size={14} />}
				docPath="/infrastructure-monitoring/kubernetes/nodes#node-name"
			/>
		),
		accessorFn: (row): string => row.nodeName || '',
		width: { min: 290 },
		enableSort: true,
		enableRemove: false,
		enableMove: false,
		pin: 'left',
		visibilityBehavior: 'hidden-on-expand',
		cell: ({ value }): React.ReactNode => (
			<TanStackTable.Text>{value}</TanStackTable.Text>
		),
	},
	{
		id: 'condition',
		header: (): React.ReactNode => (
			<ColumnHeader docPath="/infrastructure-monitoring/kubernetes/nodes#node-condition">
				Status
			</ColumnHeader>
		),
		accessorFn: (row): string => row.condition,
		width: { min: 120 },
		enableSort: false,
		cell: ({ row, groupMeta, rowId }): React.ReactNode => {
			if (!groupMeta) {
				const color =
					NODE_CONDITION_COLORS[row.condition] || NODE_CONDITION_COLORS.no_data;

				if (color === NODE_CONDITION_COLORS.no_data) {
					return <TextNoData type="tanstack" />;
				}

				return (
					<ClickableStatusBadge
						color={color}
						label={NODE_CONDITION_LABELS[row.condition] || 'Unknown'}
						status={row.condition}
						kind="node"
						rowId={rowId}
					/>
				);
			}

			return (
				<ClickableStatusCounts
					kind="node"
					items={[
						{
							value: row.nodeCountsByReadiness?.ready ?? 0,
							label: 'Ready',
							color: Color.BG_FOREST_500,
							statuses: [InframonitoringtypesNodeConditionDTO.ready],
						},
						{
							value: row.nodeCountsByReadiness?.notReady ?? 0,
							label: 'Not Ready',
							color: Color.BG_AMBER_500,
							statuses: [InframonitoringtypesNodeConditionDTO.not_ready],
						},
					]}
					rowId={rowId}
				/>
			);
		},
	},
	{
		id: 'podCountsByStatus',
		header: (): React.ReactNode => (
			<ColumnHeader docPath="/infrastructure-monitoring/kubernetes/nodes#pod-counts-by-status">
				Pod Status
			</ColumnHeader>
		),
		accessorFn: (row): InframonitoringtypesNodeRecordDTO['podCountsByStatus'] =>
			row.podCountsByStatus,
		width: { min: 250 },
		enableSort: false,
		cell: ({ row, rowId }): React.ReactNode => {
			const podCountsByStatus = row.podCountsByStatus;
			if (!podCountsByStatus) {
				return <TextNoData type="tanstack" />;
			}
			return (
				<ClickableStatusCounts
					kind="pod"
					items={getPodStatusItems(row.podCountsByStatus)}
					rowId={rowId}
				/>
			);
		},
	},
	{
		id: 'clusterName',
		header: (): React.ReactNode => (
			<ColumnHeader docPath="/infrastructure-monitoring/kubernetes/nodes#cluster-name">
				Cluster Name
			</ColumnHeader>
		),
		accessorFn: (row): string =>
			row.meta?.[INFRA_MONITORING_ATTR_KEYS.K8S_CLUSTER_NAME] || '',
		width: { min: 150, default: 150 },
		enableSort: false,
		defaultVisibility: false,
		cell: ({ value }): React.ReactNode => (
			<TanStackTable.Text>{value as string}</TanStackTable.Text>
		),
	},
	{
		id: 'cpu',
		header: (): React.ReactNode => (
			<ColumnHeader docPath="/infrastructure-monitoring/kubernetes/nodes#cpu-usage-cores">
				CPU Usage (cores)
			</ColumnHeader>
		),
		accessorFn: (row): number => row.nodeCPU,
		width: { min: 160, default: 160 },
		enableSort: true,
		cell: ({ value, rowId }): React.ReactNode => {
			const cpu = Number(value);
			return (
				<ValidateColumnValueWrapper
					rowId={rowId}
					value={cpu}
					entity={InfraMonitoringEntity.NODES}
					attribute="CPU metric"
				>
					<TanStackTable.Text>{cpu.toFixed(2)}</TanStackTable.Text>
				</ValidateColumnValueWrapper>
			);
		},
	},
	{
		id: 'cpu_allocatable',
		header: (): React.ReactNode => (
			<ColumnHeader docPath="/infrastructure-monitoring/kubernetes/nodes#cpu-alloc-cores">
				CPU Allocatable (cores)
			</ColumnHeader>
		),
		accessorFn: (row): number => row.nodeCPUAllocatable,
		width: { min: 160, default: 190 },
		enableSort: true,
		cell: ({ value, rowId }): React.ReactNode => {
			const cpuAllocatable = Number(value);
			return (
				<ValidateColumnValueWrapper
					rowId={rowId}
					value={cpuAllocatable}
					entity={InfraMonitoringEntity.NODES}
					attribute="CPU allocatable metric"
				>
					<TanStackTable.Text>{cpuAllocatable.toFixed(2)}</TanStackTable.Text>
				</ValidateColumnValueWrapper>
			);
		},
	},
	{
		id: 'memory',
		header: (): React.ReactNode => (
			<ColumnHeader docPath="/infrastructure-monitoring/kubernetes/nodes#memory-usage-wss">
				Memory Usage (WSS)
			</ColumnHeader>
		),
		accessorFn: (row): number => row.nodeMemory,
		width: { min: 220, default: 220 },
		enableSort: true,
		cell: ({ value, rowId }): React.ReactNode => {
			const memory = value as number;
			return (
				<ValidateColumnValueWrapper
					rowId={rowId}
					value={memory}
					entity={InfraMonitoringEntity.NODES}
					attribute="memory metric"
				>
					<TanStackTable.Text>{formatBytes(memory)}</TanStackTable.Text>
				</ValidateColumnValueWrapper>
			);
		},
	},
	{
		id: 'memory_allocatable',
		header: (): React.ReactNode => (
			<ColumnHeader docPath="/infrastructure-monitoring/kubernetes/nodes#memory-allocatable">
				Memory Allocatable
			</ColumnHeader>
		),
		accessorFn: (row): number => row.nodeMemoryAllocatable,
		width: { min: 200, default: 200 },
		enableSort: true,
		cell: ({ value, rowId }): React.ReactNode => {
			const memoryAllocatable = value as number;
			return (
				<ValidateColumnValueWrapper
					rowId={rowId}
					value={memoryAllocatable}
					entity={InfraMonitoringEntity.NODES}
					attribute="memory allocatable metric"
				>
					<TanStackTable.Text>{formatBytes(memoryAllocatable)}</TanStackTable.Text>
				</ValidateColumnValueWrapper>
			);
		},
	},
];