All files / frontend/src/services/api system.ts

13.46% Statements 7/52
100% Branches 0/0
0% Functions 0/3
13.46% Lines 7/52

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78                1x                                                                                                                           1x 1x 1x 1x 1x   1x  
/**
 * System API Service
 * 
 * Handles system-level operations:
 * - Service health checks
 * - System metrics
 */
 
import api from '@/lib/api';
import type { ServiceHealth } from './types';
 
/**
 * Check health of a specific service
 */
export async function checkServiceHealth(serviceName: string): Promise<ServiceHealth> {
    const response = await api.get<ServiceHealth>(`/api/v1/${serviceName}/health`);
    return response.data;
}
 
/**
 * Check health of all services
 */
export async function checkAllServicesHealth(): Promise<Record<string, ServiceHealth>> {
    const services = ['api-gateway', 'rf-acquisition', 'training', 'inference', 'data-ingestion-web'];
    const healthChecks = await Promise.allSettled(
        services.map(async (service) => {
            try {
                const health = await checkServiceHealth(service);
                return { service, health };
            } catch (error) {
                return {
                    service,
                    health: {
                        status: 'unhealthy' as const,
                        service,
                        version: 'unknown',
                        timestamp: new Date().toISOString(),
                        details: { error: String(error) },
                    },
                };
            }
        })
    );
 
    const result: Record<string, ServiceHealth> = {};
    healthChecks.forEach((check, index) => {
        if (check.status === 'fulfilled') {
            result[check.value.service] = check.value.health;
        } else {
            result[services[index]] = {
                status: 'unhealthy',
                service: services[index],
                version: 'unknown',
                timestamp: new Date().toISOString(),
                details: { error: check.reason },
            };
        }
    });
 
    return result;
}
 
/**
 * Get API Gateway root status
 */
export async function getAPIGatewayStatus(): Promise<Record<string, unknown>> {
    const response = await api.get('/');
    return response.data;
}
 
const systemService = {
    checkServiceHealth,
    checkAllServicesHealth,
    getAPIGatewayStatus,
};
 
export default systemService;