Spaces:
Running
Running
Download apps/api/src/integrations/integration-health.controller.ts from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 3.31 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/src/integrations/integration-health.controller.ts
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/api/src/integrations/integration-health.controller.ts
-
curl -L -o integration-health.controller.ts https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/src/integrations/integration-health.controller.ts
3.31 kB
| import { Controller, Get, Param, Logger } from "@nestjs/common"; | |
| import { IntegrationHealthService } from "./integration-health.service"; | |
| import { SelfHostedClientsService } from "./clients/self-hosted-clients.service"; | |
| ("integrations/health") | |
| export class IntegrationHealthController { | |
| private readonly logger = new Logger(IntegrationHealthController.name); | |
| constructor( | |
| private readonly healthService: IntegrationHealthService, | |
| private readonly selfHosted: SelfHostedClientsService, | |
| ) {} | |
| () | |
| async getHealth() { | |
| const results = await this.healthService.checkAll(); | |
| const healthyCount = results.filter((r) => r.status === "healthy").length; | |
| const degradedCount = results.filter((r) => r.status === "degraded").length; | |
| const unhealthyCount = results.filter((r) => r.status === "unhealthy").length; | |
| return { | |
| timestamp: new Date().toISOString(), | |
| summary: { | |
| total: results.length, | |
| healthy: healthyCount, | |
| degraded: degradedCount, | |
| unhealthy: unhealthyCount, | |
| }, | |
| integrations: results, | |
| }; | |
| } | |
| ("status") | |
| async getCachedHealth() { | |
| const results = this.healthService.getHealthResults(); | |
| const healthyCount = results.filter((r) => r.status === "healthy").length; | |
| return { | |
| timestamp: new Date().toISOString(), | |
| summary: { | |
| total: results.length, | |
| healthy: healthyCount, | |
| degraded: results.filter((r) => r.status === "degraded").length, | |
| unhealthy: results.filter((r) => r.status === "unhealthy").length, | |
| }, | |
| integrations: results, | |
| }; | |
| } | |
| (":provider") | |
| async getProviderHealth(("provider") provider: string) { | |
| return ( | |
| (await this.healthService.getIntegrationHealth(provider)) || { | |
| provider, | |
| status: "unknown", | |
| lastChecked: new Date().toISOString(), | |
| latencyMs: 0, | |
| error: "Provider not found in health cache", | |
| } | |
| ); | |
| } | |
| ("webhooks/recent") | |
| async getWebhookDeliveries() { | |
| return { | |
| deliveries: this.healthService.getWebhookDeliveries(100), | |
| totalRecorded: this.healthService.getWebhookDeliveries(10000).length, | |
| }; | |
| } | |
| ("metrics/client") | |
| async getClientMetrics() { | |
| return { | |
| provider: "self-hosted-clients", | |
| timestamp: new Date().toISOString(), | |
| metrics: this.selfHosted.getMetrics(), | |
| }; | |
| } | |
| ("metrics/webhook") | |
| async getWebhookMetrics() { | |
| const deliveries = this.healthService.getWebhookDeliveries(500); | |
| const providers = [...new Set(deliveries.map((d) => d.provider))]; | |
| const metrics = providers.map((provider) => { | |
| const providerDeliveries = deliveries.filter((d) => d.provider === provider); | |
| const total = providerDeliveries.length; | |
| const failed = providerDeliveries.filter((d) => d.status === "failed").length; | |
| const avgLatency = total > 0 | |
| ? providerDeliveries.reduce((s, d) => s + d.latencyMs, 0) / total | |
| : 0; | |
| return { | |
| provider, | |
| totalDeliveries: total, | |
| failedDeliveries: failed, | |
| successRate: total > 0 ? ((total - failed) / total) * 100 : 100, | |
| avgLatencyMs: Math.round(avgLatency), | |
| }; | |
| }); | |
| return { | |
| timestamp: new Date().toISOString(), | |
| metrics, | |
| }; | |
| } | |
| } |