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.

1.8 KB
Raw Blame
import { getTopOperationList } from './__mocks__/getTopOperation';
import { TopOperationList } from './TopOperationsTable';
import {
	convertedTracesToDownloadData,
	getErrorRate,
	getNearestHighestBucketValue,
} from './utils';

describe('Error Rate', () => {
	it('should return correct error rate', () => {
		const list: TopOperationList = getTopOperationList({
			errorCount: 10,
			numCalls: 100,
		});

		expect(getErrorRate(list)).toBe(10);
	});

	it('should handle no errors gracefully', () => {
		const list = getTopOperationList({ errorCount: 0, numCalls: 100 });
		expect(getErrorRate(list)).toBe(0);
	});

	it('should handle zero calls', () => {
		const list = getTopOperationList({ errorCount: 0, numCalls: 0 });
		expect(getErrorRate(list)).toBe(0);
	});
});

describe('getNearestHighestBucketValue', () => {
	it('should return nearest higher bucket value', () => {
		expect(getNearestHighestBucketValue(50, [10, 20, 30, 40, 60, 70])).toBe('60');
	});

	it('should return +Inf for value higher than any bucket', () => {
		expect(getNearestHighestBucketValue(80, [10, 20, 30, 40, 60, 70])).toBe(
			'+Inf',
		);
	});

	it('should return the first bucket for value lower than all buckets', () => {
		expect(getNearestHighestBucketValue(5, [10, 20, 30, 40, 60, 70])).toBe('10');
	});
});

describe('convertedTracesToDownloadData', () => {
	it('should convert trace data correctly', () => {
		const data = [
			{
				name: 'op1',
				p50: 50000000,
				p95: 95000000,
				p99: 99000000,
				numCalls: 100,
				errorCount: 10,
			},
		];

		expect(convertedTracesToDownloadData(data)).toStrictEqual([
			{
				Name: 'op1',
				'P50 (in ms)': '50.00',
				'P95 (in ms)': '95.00',
				'P99 (in ms)': '99.00',
				'Number of calls': '100',
				'Error Rate (%)': '10.00',
			},
		]);
	});
});