feat: add webhook /metrics endpoint with Prometheus output (5.2)
This commit is contained in:
1 parent
98d2557c32
commit
5bc1486be6
5 files changed
+126
-8
No files matched your search
@@ -1,6 +1,9 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { parseFinalConfirmation, describeConflictResolutionFailure } from "../src/review/conflictResolver.js";
|
||||
import {
|
||||
parseFinalConfirmation,
|
||||
describeConflictResolutionFailure
|
||||
} from "../src/review/conflictResolver.js";
|
||||
|
||||
test("final confirmation parses a clean JSON body", () => {
|
||||
const parsed = parseFinalConfirmation(
|
||||
@@ -31,13 +34,13 @@ test("final confirmation rejects structurally invalid output", () => {
|
||||
});
|
||||
|
||||
test("failure descriptions are actionable and never expose raw command output", () => {
|
||||
const timeout = describeConflictResolutionFailure(new Error("initial goose conflict-editing pass timed out."));
|
||||
const timeout = describeConflictResolutionFailure(
|
||||
new Error("initial goose conflict-editing pass timed out.")
|
||||
);
|
||||
assert.match(timeout, /No commit was pushed/);
|
||||
const identity = describeConflictResolutionFailure(new Error("committer identity unknown"));
|
||||
assert.match(identity, /committer identity/);
|
||||
const push = describeConflictResolutionFailure(
|
||||
new Error("! [rejected] ... (stale info)")
|
||||
);
|
||||
const push = describeConflictResolutionFailure(new Error("! [rejected] ... (stale info)"));
|
||||
assert.match(push, /force lease rejected|Run \/conflict again/);
|
||||
const generic = describeConflictResolutionFailure(new Error("something odd"));
|
||||
assert.match(generic, /could not safely complete/);
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { buildGooseAgentEnvironment, extractGooseFinalText, redactProcessArgs } from "../src/ai/gooseCli.js";
|
||||
import {
|
||||
buildGooseAgentEnvironment,
|
||||
extractGooseFinalText,
|
||||
redactProcessArgs
|
||||
} from "../src/ai/gooseCli.js";
|
||||
import { config } from "../src/config.js";
|
||||
|
||||
const originalEffort = config.gooseThinkingEffort;
|
||||
@@ -38,7 +42,7 @@ test("extractGooseFinalText strips a surrounding markdown fence", () => {
|
||||
messages: [
|
||||
{
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "```json\n{\"ok\":true}\n```" }]
|
||||
content: [{ type: "text", text: '```json\n{"ok":true}\n```' }]
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { MetricsRegistry } from "../src/webhook/metrics.js";
|
||||
|
||||
test("counters accumulate and serialize with sorted stable output", () => {
|
||||
const registry = new MetricsRegistry();
|
||||
registry.inc("reviews_total", { outcome: "pass" });
|
||||
registry.inc("reviews_total", { outcome: "pass" });
|
||||
registry.inc("reviews_total", { outcome: "block" });
|
||||
const output = registry.snapshotPrometheus();
|
||||
assert.match(output, /ghbot_reviews_total\{outcome="pass"\} 2/);
|
||||
assert.match(output, /ghbot_reviews_total\{outcome="block"\} 1/);
|
||||
assert.match(output, /ghbot_uptime_seconds \d+/);
|
||||
});
|
||||
|
||||
test("label values are escaped for the Prometheus text format", () => {
|
||||
const registry = new MetricsRegistry();
|
||||
registry.inc("events_total", { repo: 'acme "x"\n' });
|
||||
const output = registry.snapshotPrometheus();
|
||||
assert.ok(output.includes('ghbot_events_total{repo="acme \\"x\\"\\n"} 1'));
|
||||
});
|
||||
|
||||
test("durations produce count, sum, and quantiles", () => {
|
||||
const registry = new MetricsRegistry();
|
||||
registry.observeDuration("review_duration_ms", 100);
|
||||
registry.observeDuration("review_duration_ms", 300);
|
||||
const output = registry.snapshotPrometheus();
|
||||
assert.match(output, /ghbot_review_duration_ms_count 2/);
|
||||
assert.match(output, /ghbot_review_duration_ms_sum_ms 400/);
|
||||
assert.match(output, /ghbot_duration_ms\{quantile="0.5"\} \d+/);
|
||||
assert.match(output, /ghbot_duration_ms\{quantile="0.95"\} \d+/);
|
||||
});
|
||||
|
||||
test("an empty registry still emits uptime", () => {
|
||||
const output = new MetricsRegistry().snapshotPrometheus();
|
||||
assert.match(output, /ghbot_uptime_seconds/);
|
||||
});
|
||||
Reference in new issue
Block a user