mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-03 01:23:31 +01:00
feat: add operational incident evidence and recovering alerts
This commit is contained in:
1 parent
a4f441f097
commit
0f9d8c657a
18 files changed
+558
-123
No files matched your search
@@ -1079,6 +1079,7 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
|
||||
"getRedis",
|
||||
"hourKey",
|
||||
"persistError",
|
||||
"reportOutputDrops",
|
||||
"resolveThreshold",
|
||||
"serializeError",
|
||||
"trimErrorLike",
|
||||
@@ -1096,6 +1097,7 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
|
||||
"getRedis",
|
||||
"hourKey",
|
||||
"persistError",
|
||||
"reportOutputDrops",
|
||||
"resolveThreshold",
|
||||
"serializeError",
|
||||
"trimErrorLike",
|
||||
@@ -2205,7 +2207,7 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
|
||||
"collector",
|
||||
"endpoint",
|
||||
"grafana",
|
||||
"group",
|
||||
"incidentGroups",
|
||||
"investigateLogs",
|
||||
"logOptions",
|
||||
"range",
|
||||
@@ -2213,6 +2215,7 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
|
||||
"rows",
|
||||
"safeRedisLog",
|
||||
"safeRow",
|
||||
"signature",
|
||||
"timestampKey"
|
||||
],
|
||||
"build/server/admin-log-investigation.js": [
|
||||
@@ -2220,7 +2223,7 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
|
||||
"collector",
|
||||
"endpoint",
|
||||
"grafana",
|
||||
"group",
|
||||
"incidentGroups",
|
||||
"investigateLogs",
|
||||
"logOptions",
|
||||
"range",
|
||||
@@ -2228,6 +2231,7 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
|
||||
"rows",
|
||||
"safeRedisLog",
|
||||
"safeRow",
|
||||
"signature",
|
||||
"timestampKey"
|
||||
],
|
||||
"src/server/dailyStatsSnapshot.ts": [
|
||||
|
||||
@@ -10,7 +10,7 @@ import { logContext, validTraceId } from "./log-context";
|
||||
const instance = randomUUID();
|
||||
const allowed = (values: readonly string[], value: unknown): value is string => typeof value === "string" && values.includes(value);
|
||||
const events: Record<string, string> = {
|
||||
...LOG_EVENTS,
|
||||
...LOG_EVENTS, deployment: "deployment",
|
||||
request: "request_completed", "slow request": "request_slow", "request interrupted": "request_cancelled",
|
||||
"process fatal error": "process_fatal_error", "process started": "process_started",
|
||||
"process heartbeat": "process_heartbeat", "job started": "job_started", "job completed": "job_completed",
|
||||
@@ -18,19 +18,19 @@ const events: Record<string, string> = {
|
||||
};
|
||||
const errorCodes = new Set([
|
||||
...ERROR_CODES,
|
||||
"token_refresh_failed", "quota_exceeded", "github_rate_limit_exceeded", "github_app_reconnect_required", "github_token_invalid",
|
||||
"repo_renamed", "preparation_interrupted", "commit_not_found", "zip_not_available", "token_refresh_failed", "quota_exceeded", "github_rate_limit_exceeded", "github_app_reconnect_required", "github_token_invalid",
|
||||
"repository_expired", "repository_not_ready", "repository_not_found", "repository_job_cancelled",
|
||||
"ECONNRESET", "ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND", "EPIPE", "ABORT_ERR",
|
||||
"upstream_error", "upstream_timeout", "invalid_signature", "webhook_processing_failed",
|
||||
]);
|
||||
export const LOG_NUMBERS = ["expectedBytes", "measuredMs", "unattributedMs", "overlapMs","status", "httpStatus", "ms", "firstByteMs", "responseMs", "bytes", "bytesPerSecond",
|
||||
export const LOG_NUMBERS = ["restartMs", "exitCode","droppedLogsInterval","expectedBytes", "measuredMs", "unattributedMs", "overlapMs","status", "httpStatus", "ms", "firstByteMs", "responseMs", "bytes", "bytesPerSecond",
|
||||
"attempt", "rss", "memoryLimitBytes", "memoryRatio", "uptime", "activeRequests", "waiting", "active", "delayed", "failed",
|
||||
"oldestWaitingMs", "droppedLogs", "loopP95Ms", "upstreamStatus"];
|
||||
export const LOG_STAGES = ["transfer", "database","repository", "credential_resolution", "upstream", "cache_lookup", "cache_fill", "worker_wait", "anonymize", "streamer_headers"];
|
||||
export function logRecord(level: string, module: string, args: unknown[]) {
|
||||
const context = logContext.getStore() || {};
|
||||
const details: Record<string, unknown> = {};
|
||||
const keys = [...LOG_NUMBERS, "requestId", "jobId", "hopId", "parentHopId", "cancellationOrigin", "cancellationEvidence", "endpointKind", "stageCounts", "stageOpen", "code", "message", "outcome", "method", "route", "queue",
|
||||
const keys = [...LOG_NUMBERS, "requestId", "jobId", "hopId", "parentHopId", "deploymentId", "deploymentOperation", "deploymentPhase", "deploymentOutcome", "cancellationOrigin", "cancellationEvidence", "endpointKind", "stageCounts", "stageOpen", "code", "message", "outcome", "method", "route", "queue",
|
||||
"errorType", "errorStack", "causeType", "causeStack", "requestPath", "stages", "reason", "phase", "event", "deliveryId", "hostname", "service"];
|
||||
// Do not traverse arbitrary objects or invoke error getters while logging.
|
||||
for (const arg of args.slice(0, 8)) if (arg && typeof arg === "object") {
|
||||
@@ -50,8 +50,8 @@ export function logRecord(level: string, module: string, args: unknown[]) {
|
||||
service: context.service || (allowed(["api", "streamer", "worker"], details.service) ? details.service : undefined) || (process.env.SERVICE_NAME?.toLowerCase() === "streamer" ? "streamer" : "api"),
|
||||
instance, release: /^[a-f0-9]{7,40}$/.test(process.env.APP_RELEASE || "") ? process.env.APP_RELEASE : "unknown",
|
||||
event, message: event, module: LOG_MODULES.includes(module) ? module : "application" };
|
||||
for (const key of ["requestId", "jobId", "hopId", "parentHopId"] as const) {
|
||||
const value = details[key] || context[key];
|
||||
for (const key of ["requestId", "jobId", "hopId", "parentHopId", "deploymentId"] as const) {
|
||||
const value = details[key] || (key === "deploymentId" ? undefined : context[key]);
|
||||
if (validTraceId(value)) record[key] = value;
|
||||
}
|
||||
if (Number.isSafeInteger(context.attempt)) record.attempt = context.attempt;
|
||||
@@ -64,7 +64,7 @@ export function logRecord(level: string, module: string, args: unknown[]) {
|
||||
if (validTraceId(details.deliveryId)) record.deliveryId = details.deliveryId;
|
||||
if (allowed(["github.com", "api.github.com", "codeload.github.com", "raw.githubusercontent.com", "media.githubusercontent.com"], details.hostname)) record.upstreamHost = details.hostname;
|
||||
else if (details.hostname) record.upstreamHost = "other";
|
||||
for (const [key, values] of Object.entries({ cancellationOrigin: ["unknown", "api", "streamer", "timeout", "upstream"],
|
||||
for (const [key, values] of Object.entries({ deploymentOperation: ["deploy", "rollback"], deploymentPhase: ["start", "restart", "finish"], deploymentOutcome: ["started", "completed", "failed", "unchanged"], cancellationOrigin: ["unknown", "api", "streamer", "timeout", "upstream"],
|
||||
cancellationEvidence: ["response_close", "request_aborted", "upstream_error", "timeout", "local_abort"], endpointKind: ["public", "internal"] })) {
|
||||
if (allowed(values, details[key])) record[key] = details[key];
|
||||
}
|
||||
|
||||
@@ -93,6 +93,13 @@ let errorOutputBroken = false;
|
||||
process.stdout.on("error", () => { outputBroken = true; droppedOutput++; });
|
||||
process.stderr.on("error", () => { errorOutputBroken = true; droppedOutput++; });
|
||||
export function getDroppedOutput() { return droppedOutput; }
|
||||
let reportedDrops = 0;
|
||||
/** Advance the interval only when emitting the report did not itself drop a record. */
|
||||
export function reportOutputDrops(report: (fields: { droppedLogs: number; droppedLogsInterval: number }) => void) {
|
||||
const before = droppedOutput;
|
||||
report({ droppedLogs: before, droppedLogsInterval: Math.max(0, before - reportedDrops) });
|
||||
if (droppedOutput === before) reportedDrops = before;
|
||||
}
|
||||
export function getInProcessDropped(): number {
|
||||
return droppedInProcess;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { logMemory } from "./log-memory";
|
||||
import { createLogger, serializeError, getDroppedOutput } from "./logger";
|
||||
import { createLogger, serializeError, reportOutputDrops } from "./logger";
|
||||
|
||||
/** Observe fatal errors without overriding Node's default exit behavior. */
|
||||
export function installFatalErrorLogging(service: "api" | "streamer") {
|
||||
@@ -9,8 +9,8 @@ export function installFatalErrorLogging(service: "api" | "streamer") {
|
||||
});
|
||||
logger.info("process started", { service });
|
||||
const heartbeat = setInterval(() => {
|
||||
void logMemory().then(memory => logger.info("process heartbeat", {
|
||||
service, uptime: process.uptime(), ...memory, droppedLogs: getDroppedOutput() }));
|
||||
void logMemory().then(memory => reportOutputDrops(drops => logger.info("process heartbeat", {
|
||||
service, uptime: process.uptime(), ...memory, ...drops })));
|
||||
}, 30000);
|
||||
heartbeat.unref();
|
||||
process.on("uncaughtExceptionMonitor", report);
|
||||
|
||||
Reference in new issue
Block a user