feat(api, web): enhance health check and domain management features
Build, Test, and Push CFDM Docker Image / test (push) Successful in 3m3s
Build, Test, and Push CFDM Docker Image / build-and-push (push) Successful in 1m48s
Build, Test, and Push CFDM Docker Image / update-wiki (push) Successful in 6s
Build, Test, and Push CFDM Docker Image / create-release (push) Has been skipped
Build, Test, and Push CFDM Docker Image / test (push) Successful in 3m3s
Build, Test, and Push CFDM Docker Image / build-and-push (push) Successful in 1m48s
Build, Test, and Push CFDM Docker Image / update-wiki (push) Successful in 6s
Build, Test, and Push CFDM Docker Image / create-release (push) Has been skipped
- Integrated domain monitoring routes and bulk update functionality for domains in the API. - Improved health check service to include domain monitoring and logging of health status changes. - Updated web components to reflect health status with new HealthCheckBadge and enhanced domain filtering options. - Refactored domain service to support bulk updates and improved domain management capabilities. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
dd167a4fec
commit
64585ccd47
38 files changed
+4199
-677
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import { createDomainMonitorSchema } from "@cfdm/shared";
|
||||
import { repos } from "@cfdm/db";
|
||||
import * as healthCheckService from "../services/health-check-service.js";
|
||||
|
||||
export async function domainMonitorRoutes(app: FastifyInstance) {
|
||||
app.get("/domains/:id/monitors", async (request) => {
|
||||
const { id } = request.params as { id: string };
|
||||
return repos.listDomainMonitors(request.server.db, Number(id));
|
||||
});
|
||||
|
||||
app.post("/domains/:id/monitors", async (request) => {
|
||||
const { id } = request.params as { id: string };
|
||||
const body = createDomainMonitorSchema.parse(request.body);
|
||||
return repos.createDomainMonitor(request.server.db, Number(id), body);
|
||||
});
|
||||
|
||||
app.delete("/domains/:domainId/monitors/:monitorId", async (request) => {
|
||||
const { monitorId } = request.params as {
|
||||
domainId: string;
|
||||
monitorId: string;
|
||||
};
|
||||
repos.deleteDomainMonitor(request.server.db, Number(monitorId));
|
||||
return { deleted: true };
|
||||
});
|
||||
|
||||
app.get("/domains/:id/monitor-results", async (request) => {
|
||||
const { id } = request.params as { id: string };
|
||||
const query = request.query as { limit?: string };
|
||||
const limit = query.limit ? Number(query.limit) : 50;
|
||||
return repos.listDomainMonitorResultsForDomain(
|
||||
request.server.db,
|
||||
Number(id),
|
||||
limit,
|
||||
);
|
||||
});
|
||||
|
||||
app.post("/domains/:id/monitors/run", async (request) => {
|
||||
const config = request.server.config;
|
||||
const checked = await healthCheckService.runDomainMonitors(request.server.db, {
|
||||
degradedFailures: config.healthDegradedFailures,
|
||||
downFailures: config.healthDownFailures,
|
||||
latencyWarnMs: config.healthLatencyWarnMs,
|
||||
});
|
||||
return { checked };
|
||||
});
|
||||
}
|
||||
|
||||
export async function notificationRoutes(app: FastifyInstance) {
|
||||
app.get("/notifications/log", async (request) => {
|
||||
const query = request.query as { limit?: string };
|
||||
const limit = query.limit ? Number(query.limit) : 50;
|
||||
return repos.listNotificationLog(request.server.db, limit);
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import { updateDomainSchema } from "@cfdm/shared";
|
||||
import { bulkUpdateDomainsSchema, updateDomainSchema } from "@cfdm/shared";
|
||||
import { z } from "zod";
|
||||
import * as domainService from "../services/domain-service.js";
|
||||
|
||||
@@ -25,6 +25,20 @@ export async function domainRoutes(app: FastifyInstance) {
|
||||
);
|
||||
});
|
||||
|
||||
app.post("/domains/bulk", async (request) => {
|
||||
const body = bulkUpdateDomainsSchema.parse(request.body);
|
||||
const updated = domainService.bulkUpdateDomains(
|
||||
request.server.db,
|
||||
body.ids,
|
||||
{
|
||||
group_id: body.group_id,
|
||||
environment: body.environment,
|
||||
tags_add: body.tags_add,
|
||||
},
|
||||
);
|
||||
return { updated };
|
||||
});
|
||||
|
||||
app.get("/domains/:id", async (request) => {
|
||||
const { id } = request.params as { id: string };
|
||||
return domainService.getDomain(request.server.db, Number(id));
|
||||
@@ -33,14 +47,7 @@ export async function domainRoutes(app: FastifyInstance) {
|
||||
app.patch("/domains/:id", async (request) => {
|
||||
const { id } = request.params as { id: string };
|
||||
const body = updateDomainSchema.parse(request.body);
|
||||
const existing = domainService.getDomain(request.server.db, Number(id));
|
||||
return domainService.updateDomain(
|
||||
request.server.db,
|
||||
Number(id),
|
||||
body.group_id !== undefined ? body.group_id : existing.group_id,
|
||||
body.status ?? existing.status,
|
||||
body.cert_monitoring,
|
||||
);
|
||||
return domainService.updateDomain(request.server.db, Number(id), body);
|
||||
});
|
||||
|
||||
app.delete("/domains/:id", async (request) => {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import { healthStatusQuerySchema } from "@cfdm/shared";
|
||||
import { repos } from "@cfdm/db";
|
||||
import * as healthCheckService from "../services/health-check-service.js";
|
||||
import * as serviceConfigService from "../services/service-config-service.js";
|
||||
|
||||
@@ -15,14 +16,31 @@ export async function healthCheckRoutes(app: FastifyInstance) {
|
||||
|
||||
app.post("/health-check/run", async (request) => {
|
||||
const config = request.server.config;
|
||||
const thresholds = {
|
||||
degradedFailures: config.healthDegradedFailures,
|
||||
downFailures: config.healthDownFailures,
|
||||
latencyWarnMs: config.healthLatencyWarnMs,
|
||||
};
|
||||
const checked = await healthCheckService.runAllChecks(request.server.db, {
|
||||
thresholds: {
|
||||
degradedFailures: config.healthDegradedFailures,
|
||||
downFailures: config.healthDownFailures,
|
||||
latencyWarnMs: config.healthLatencyWarnMs,
|
||||
},
|
||||
onStatusChange: async (target, _prev, _next) => {
|
||||
thresholds,
|
||||
onStatusChange: async (target, prev, next) => {
|
||||
try {
|
||||
const label =
|
||||
next === "up"
|
||||
? "OK"
|
||||
: next === "degraded"
|
||||
? "Slow"
|
||||
: next === "down"
|
||||
? "Down"
|
||||
: "—";
|
||||
repos.insertNotificationLog(
|
||||
request.server.db,
|
||||
"ip_health",
|
||||
target.scope,
|
||||
target.ref_id,
|
||||
`${target.hostname || target.ip}: ${label}`,
|
||||
`IP ${target.ip}: ${prev ?? "—"} → ${label}`,
|
||||
);
|
||||
await serviceConfigService.reconcileDnsForTarget(
|
||||
request.server.db,
|
||||
request.server.cf,
|
||||
@@ -30,10 +48,14 @@ export async function healthCheckRoutes(app: FastifyInstance) {
|
||||
target.ref_id,
|
||||
);
|
||||
} catch {
|
||||
// best-effort reconcile; ошибки логируются cron-задачей
|
||||
// best-effort
|
||||
}
|
||||
},
|
||||
});
|
||||
return { checked };
|
||||
const monitors = await healthCheckService.runDomainMonitors(
|
||||
request.server.db,
|
||||
thresholds,
|
||||
);
|
||||
return { checked, monitors };
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user