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.

936 B
Raw Blame
import api from 'api';
// eslint-disable-next-line no-restricted-imports
import { Dispatch } from 'redux';
import { toUTCEpoch } from 'utils/timeUtils';

import { ActionTypes } from './types';

export interface UsageDataItem {
	timestamp: number;
	count: number;
}

export interface GetUsageDataAction {
	type: ActionTypes.getUsageData;
	payload: UsageDataItem[];
}

export const getUsageData =
	(minTime: number, maxTime: number, step: number, service: string) =>
	async (dispatch: Dispatch): Promise<void> => {
		const requesString = `/usage?start=${toUTCEpoch(minTime)}&end=${toUTCEpoch(
			maxTime,
		)}&step=${step}&service=${service || ''}`;
		// Step can only be multiple of 3600
		const response = await api.get<UsageDataItem[]>(requesString);

		dispatch<GetUsageDataAction>({
			type: ActionTypes.getUsageData,
			payload: response.data,
			// PNOTE - response.data in the axios response has the actual API response
		});
	};