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.

2.6 KB
Raw Blame
import { AppLink } from 'lib/router/AppLink';
import { Info, Search } from '@signozhq/icons';
import { Popconfirm, PopconfirmProps } from 'antd';
import type { ColumnType } from 'antd/es/table';
import ROUTES from 'constants/routes';
import { routeConfig } from 'container/SideNav/config';
import { getQueryString } from 'container/SideNav/helper';
import { navigate } from 'lib/router/navigation';
import { ServicesList } from 'types/api/metrics/getService';

import { filterDropdown } from '../Filter/FilterDropdown';

import '../ServiceApplication.styles.scss';

const MAX_TOP_LEVEL_OPERATIONS = 2500;

const highTopLevelOperationsPopoverDesc = (metrics: string): JSX.Element => (
	<div className="popover-description">
		The service `{metrics}` has too many top level operations. It makes the
		dashboard slow to load.
	</div>
);

export const getColumnSearchProps = (
	dataIndex: keyof ServicesList,
	search: string,
): ColumnType<ServicesList> => ({
	filterDropdown,
	filterIcon: <Search size="md" />,
	onFilter: (
		value: string | number | boolean,
		record: ServicesList,
	): boolean => {
		if (record[dataIndex]) {
			return (
				record[dataIndex]
					?.toString()
					.toLowerCase()
					.includes(value.toString().toLowerCase()) || false
			);
		}

		return false;
	},
	render: (metrics: string, record: ServicesList): JSX.Element => {
		const urlParams = new URLSearchParams(search);
		const avialableParams = routeConfig[ROUTES.SERVICE_METRICS];
		const queryString = getQueryString(avialableParams, urlParams);
		const topLevelOperations = record?.dataWarning?.topLevelOps || [];

		const handleShowTopLevelOperations: PopconfirmProps['onConfirm'] = () => {
			navigate(
				`${ROUTES.APPLICATION}/${encodeURIComponent(metrics)}/top-level-operations`,
			);
		};

		const hasHighTopLevelOperations =
			topLevelOperations &&
			Array.isArray(topLevelOperations) &&
			topLevelOperations.length > MAX_TOP_LEVEL_OPERATIONS;

		return (
			<div className={`serviceName ${hasHighTopLevelOperations ? 'error' : ''} `}>
				{hasHighTopLevelOperations && (
					<Popconfirm
						title="Too Many Top Level Operations"
						description={highTopLevelOperationsPopoverDesc(metrics)}
						placement="right"
						overlayClassName="service-high-top-level-operations"
						onConfirm={handleShowTopLevelOperations}
						trigger={['hover']}
						showCancel={false}
						okText="Show Top Level Operations"
					>
						<Info size={14} />
					</Popconfirm>
				)}

				<AppLink
					data-testid={`service-link-${metrics}`}
					to={`${ROUTES.APPLICATION}/${encodeURIComponent(
						metrics,
					)}?${queryString.join('')}`}
				>
					{metrics}
				</AppLink>
			</div>
		);
	},
});