mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 17:13:33 +01:00
fix: explain interrupted requests and account for overlapping latency
This commit is contained in:
1 parent
1e617d2df0
commit
d2e3954d21
18 files changed
+394
-33
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { createHash } from "crypto";
|
||||
import { logRecord } from "../core/log-record";
|
||||
import { logRecord, LOG_NUMBERS, LOG_STAGES } from "../core/log-record";
|
||||
import { logContext, validTraceId } from "../core/log-context";
|
||||
import { LOG_EVENTS } from "../core/log-schema";
|
||||
|
||||
@@ -50,13 +50,16 @@ function safeRow(input: Record<string, unknown>): Row | null {
|
||||
const time = typeof input._time === "string" ? input._time : input.timestamp;
|
||||
if (typeof time !== "string" || !Number.isFinite(Date.parse(time))) return null;
|
||||
// Reuse the application's reviewed projection. Never return raw backend data.
|
||||
const numeric = ["status", "httpStatus", "ms", "firstByteMs", "responseMs", "attempt", "rss", "memoryRatio", "droppedLogs", "oldestWaitingMs", "waiting"];
|
||||
const numeric = [...LOG_NUMBERS, ...LOG_STAGES.flatMap(stage => [`stage_${stage}_ms`, `stage_${stage}_count`, `stage_${stage}_open`])];
|
||||
const data: Record<string, unknown> = { ...input, code: input.errorCode };
|
||||
for (const key of numeric) if (typeof input[key] === "string" && /^-?\d+(?:\.\d+)?$/.test(input[key] as string)) data[key] = Number(input[key]);
|
||||
for (const [field, suffix] of [["stages", "ms"], ["stageCounts", "count"], ["stageOpen", "open"]]) {
|
||||
data[field] = Object.fromEntries(LOG_STAGES.map(stage => [stage, data[`stage_${stage}_${suffix}`]]));
|
||||
}
|
||||
// Revalidate finite route and diagnostic allowlists; never pass raw strings.
|
||||
const projected = logContext.run({}, () => logRecord(["error", "warn", "info", "debug"].includes(String(input.severity)) ? String(input.severity) : "info", String(input.module || "application"), ["", data]));
|
||||
const result: Row = { timestamp: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?Z$/.test(time) ? time : new Date(time).toISOString(), severity: String(projected.severity), service: services.includes(String(input.service)) ? String(input.service) : "unknown", event: events.has(String(input.event)) ? String(input.event) : "application_log", module: String(projected.module), release: /^(?:[a-f0-9]{7,40}|unknown)$/.test(String(input.release)) ? String(input.release) : "unknown" };
|
||||
for (const key of [...numeric, "errorCode", "requestId", "jobId", "queue", "route", "method", "errorType", "errorStack", "causeType", "causeStack", "repoId", "requestPath"]) if (typeof projected[key] === "string" || typeof projected[key] === "number") result[key] = projected[key] as string | number;
|
||||
for (const key of [...numeric, "outcome", "endpointKind", "cancellationOrigin", "cancellationEvidence", "hopId", "parentHopId", "errorCode", "requestId", "jobId", "queue", "route", "method", "errorType", "errorStack", "causeType", "causeStack", "repoId", "requestPath"]) if (typeof projected[key] === "string" || typeof projected[key] === "number") result[key] = projected[key] as string | number;
|
||||
if (validTraceId(input.instance)) result.instance = input.instance;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { installDatabaseTiming } from "../core/database-timing";
|
||||
import InstallationModel from "../core/model/github-installation";
|
||||
import { credentialCipher } from "../core/credentials";
|
||||
import CredentialModel from "../core/model/credentials/credentials.model";
|
||||
@@ -24,6 +25,7 @@ export const database = mongoose.connection;
|
||||
export let isConnected = false;
|
||||
|
||||
export async function connect(overrides: Pick<ConnectOptions, "appName" | "maxPoolSize" | "minPoolSize"> = {}) {
|
||||
installDatabaseTiming();
|
||||
credentialCipher(); // Refuse to serve persisted credentials without a valid keyring.
|
||||
mongoose.set("strictQuery", false);
|
||||
const options: ConnectOptions = {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { recordUpstreamFailure } from "../../core/request-evidence";
|
||||
import { jobTrace } from "../../core/log-context";
|
||||
import { hasVisibleSubmodules } from "../../core/file-submodules";
|
||||
import { FILE_LISTING_LIMIT } from "../../core/file-tree";
|
||||
@@ -89,6 +90,7 @@ router.get(
|
||||
},
|
||||
})
|
||||
.on("error", (err: Error & { response?: { statusCode?: number; body?: unknown } }) => {
|
||||
if (!res.destroyed) recordUpstreamFailure(res, err, "streamer");
|
||||
headersDone(true);
|
||||
const upstreamStatus = err?.response?.statusCode;
|
||||
let upstreamBody: string | undefined;
|
||||
|
||||
Reference in new issue
Block a user