@obzerver/server 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai.d.ts +1 -0
- package/dist/ai.js +7 -2
- package/dist/ai.js.map +1 -1
- package/dist/alerts.d.ts +2 -0
- package/dist/alerts.js.map +1 -1
- package/dist/cli.js +89 -18
- package/dist/cli.js.map +1 -1
- package/dist/db.d.ts +10 -1
- package/dist/db.js +46 -6
- package/dist/db.js.map +1 -1
- package/dist/keys.d.ts +53 -0
- package/dist/keys.js +54 -0
- package/dist/keys.js.map +1 -0
- package/dist/mcp.js +7 -0
- package/dist/mcp.js.map +1 -1
- package/dist/projects.d.ts +13 -2
- package/dist/projects.js +24 -13
- package/dist/projects.js.map +1 -1
- package/dist/ratelimit.d.ts +17 -0
- package/dist/ratelimit.js +44 -0
- package/dist/ratelimit.js.map +1 -0
- package/dist/server.d.ts +23 -0
- package/dist/server.js +176 -43
- package/dist/server.js.map +1 -1
- package/dist/simple.d.ts +142 -0
- package/dist/simple.js +482 -0
- package/dist/simple.js.map +1 -0
- package/package.json +5 -4
- package/public/assets/index-D1q02VSn.css +2 -0
- package/public/assets/index-HhyoqQPd.js +114 -0
- package/public/index.html +2 -2
- package/public/assets/index-CUhGP7XJ.css +0 -1
- package/public/assets/index-gvQyqryL.js +0 -573
package/dist/simple.d.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { Db } from './db.js';
|
|
2
|
+
import * as Q from './queries.js';
|
|
3
|
+
import { type RuleParams, type RuleType } from './alerts.js';
|
|
4
|
+
export type Tone = 'good' | 'warn' | 'bad' | 'neutral';
|
|
5
|
+
export type Health = 'healthy' | 'attention' | 'broken' | 'idle' | 'no_data';
|
|
6
|
+
export interface Vital {
|
|
7
|
+
id: 'working' | 'speed' | 'traffic' | 'server';
|
|
8
|
+
label: string;
|
|
9
|
+
value: string;
|
|
10
|
+
note: string;
|
|
11
|
+
tone: Tone;
|
|
12
|
+
usual?: string | null;
|
|
13
|
+
}
|
|
14
|
+
export interface Finding {
|
|
15
|
+
id: string;
|
|
16
|
+
kind: 'secret' | 'alert' | 'silent' | 'endpoint' | 'error' | 'jobs' | 'release' | 'new_errors' | 'traffic' | 'speed' | 'failures';
|
|
17
|
+
tone: Tone;
|
|
18
|
+
title: string;
|
|
19
|
+
detail: string;
|
|
20
|
+
ts?: number | null;
|
|
21
|
+
link?: string;
|
|
22
|
+
ask?: string;
|
|
23
|
+
count?: number;
|
|
24
|
+
users?: number;
|
|
25
|
+
isNew?: boolean;
|
|
26
|
+
executionId?: number | null;
|
|
27
|
+
}
|
|
28
|
+
export interface Todo {
|
|
29
|
+
id: string;
|
|
30
|
+
urgency: 'now' | 'soon' | 'later';
|
|
31
|
+
title: string;
|
|
32
|
+
why: string;
|
|
33
|
+
steps: string[];
|
|
34
|
+
link?: string;
|
|
35
|
+
linkLabel?: string;
|
|
36
|
+
ask?: string;
|
|
37
|
+
executionId?: number | null;
|
|
38
|
+
}
|
|
39
|
+
export interface SimpleHome {
|
|
40
|
+
health: Health;
|
|
41
|
+
headline: string;
|
|
42
|
+
summary: string;
|
|
43
|
+
vitals: Vital[];
|
|
44
|
+
timeline: Array<{
|
|
45
|
+
t: number;
|
|
46
|
+
count: number;
|
|
47
|
+
failed: number;
|
|
48
|
+
}>;
|
|
49
|
+
bucketMs: number;
|
|
50
|
+
broke: Finding[];
|
|
51
|
+
changed: Finding[];
|
|
52
|
+
/** What "usual" means here, when there is enough history to say. */
|
|
53
|
+
usualBasis: string | null;
|
|
54
|
+
todo: Todo[];
|
|
55
|
+
suggestions: string[];
|
|
56
|
+
apps: Array<{
|
|
57
|
+
id: string;
|
|
58
|
+
lastSeen: number;
|
|
59
|
+
reporting: boolean;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
export declare function simpleHome(db: Db, w: Q.Window, now?: number): SimpleHome;
|
|
63
|
+
export interface Preset {
|
|
64
|
+
id: string;
|
|
65
|
+
type: RuleType;
|
|
66
|
+
label: string;
|
|
67
|
+
description: string;
|
|
68
|
+
params: RuleParams;
|
|
69
|
+
}
|
|
70
|
+
/** What a newcomer wants to hear about. Each maps to one alert type; Advanced mode shows the rules themselves. */
|
|
71
|
+
export declare const PRESETS: Preset[];
|
|
72
|
+
export interface SimpleChannels {
|
|
73
|
+
email: string;
|
|
74
|
+
slack: string;
|
|
75
|
+
}
|
|
76
|
+
export declare function simpleAlerts(db: Db, { emailReady }: {
|
|
77
|
+
emailReady: boolean;
|
|
78
|
+
}): {
|
|
79
|
+
presets: {
|
|
80
|
+
id: string;
|
|
81
|
+
label: string;
|
|
82
|
+
description: string;
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
firing: boolean;
|
|
85
|
+
lastFired: number | null;
|
|
86
|
+
}[];
|
|
87
|
+
channels: SimpleChannels;
|
|
88
|
+
emailReady: boolean;
|
|
89
|
+
firing: {
|
|
90
|
+
id: number;
|
|
91
|
+
name: string;
|
|
92
|
+
since: number | null;
|
|
93
|
+
}[];
|
|
94
|
+
events: {
|
|
95
|
+
id: number;
|
|
96
|
+
ts: number;
|
|
97
|
+
state: string;
|
|
98
|
+
rule: string;
|
|
99
|
+
type: string;
|
|
100
|
+
message: string;
|
|
101
|
+
kindLabel: string;
|
|
102
|
+
}[];
|
|
103
|
+
};
|
|
104
|
+
export declare function saveSimpleAlerts(db: Db, body: {
|
|
105
|
+
presets?: Record<string, boolean>;
|
|
106
|
+
channels?: Partial<SimpleChannels>;
|
|
107
|
+
}): void;
|
|
108
|
+
/** One enabled preset rule to send a test through. */
|
|
109
|
+
export declare function simpleTestRule(db: Db): import("./alerts.js").Rule | null;
|
|
110
|
+
export interface SimpleCompare {
|
|
111
|
+
label: string;
|
|
112
|
+
before: string;
|
|
113
|
+
after: string;
|
|
114
|
+
tone: Tone;
|
|
115
|
+
hint?: string;
|
|
116
|
+
}
|
|
117
|
+
export interface SimpleRelease {
|
|
118
|
+
service: string;
|
|
119
|
+
version: string;
|
|
120
|
+
previous: string | null;
|
|
121
|
+
first: number;
|
|
122
|
+
last: number;
|
|
123
|
+
requests: number;
|
|
124
|
+
latest: boolean;
|
|
125
|
+
verdict: Q.Verdict;
|
|
126
|
+
tone: Tone;
|
|
127
|
+
label: string;
|
|
128
|
+
summary: string;
|
|
129
|
+
compare: SimpleCompare[];
|
|
130
|
+
newErrors: Array<{
|
|
131
|
+
fingerprint: string;
|
|
132
|
+
class: string;
|
|
133
|
+
message: string;
|
|
134
|
+
count: number;
|
|
135
|
+
}>;
|
|
136
|
+
codeChanges: string[];
|
|
137
|
+
/** What to do about it, when there is something to do. */
|
|
138
|
+
advice: string[] | null;
|
|
139
|
+
ask: string;
|
|
140
|
+
}
|
|
141
|
+
/** Every deploy of every app, newest first, with a verdict and a before/after anyone can read. */
|
|
142
|
+
export declare function simpleReleases(db: Db, w: Q.Window): SimpleRelease[];
|
package/dist/simple.js
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
import * as Q from './queries.js';
|
|
2
|
+
import { secretGroups } from './secrets.js';
|
|
3
|
+
import { RULE_TYPES, toRule } from './alerts.js';
|
|
4
|
+
// ---------------------------------------------------------------- formatting (plain, no units jargon)
|
|
5
|
+
const n0 = (v) => Math.round(v).toLocaleString('en-US');
|
|
6
|
+
const fmtMs = (v) => (v == null ? '—' : v >= 10000 ? `${(v / 1000).toFixed(0)} s` : v >= 1000 ? `${(v / 1000).toFixed(1)} s` : `${Math.round(v)} ms`);
|
|
7
|
+
const fmtPct = (v) => (v >= 99.95 && v < 100 ? '99.9%' : v === 100 || v === 0 ? `${v}%` : v >= 10 ? `${v.toFixed(1)}%` : `${v.toFixed(v < 1 ? 2 : 1)}%`);
|
|
8
|
+
const times = (n) => (n === 1 ? 'once' : n === 2 ? 'twice' : `${n0(n)} times`);
|
|
9
|
+
const plural = (n, one, many = `${one}s`) => `${n0(n)} ${n === 1 ? one : many}`;
|
|
10
|
+
const clip = (s, n = 140) => { const t = String(s ?? '').replace(/\s+/g, ' ').trim(); return t.length > n ? `${t.slice(0, n - 1)}…` : t; };
|
|
11
|
+
const enc = encodeURIComponent;
|
|
12
|
+
const opLink = (kind, service, name) => `/operations/${kind}/${enc(service)}/${enc(name)}`;
|
|
13
|
+
const TONE_RANK = { bad: 0, warn: 1, neutral: 2, good: 3 };
|
|
14
|
+
const KIND_RANK = { secret: 0, silent: 1, error: 2, endpoint: 3, jobs: 4, alert: 5 };
|
|
15
|
+
const byTone = (a, b) => TONE_RANK[a.tone] - TONE_RANK[b.tone] || (KIND_RANK[a.kind] ?? 9) - (KIND_RANK[b.kind] ?? 9) || (b.count ?? 0) - (a.count ?? 0);
|
|
16
|
+
/** "a password", "an AWS access key": secret labels read naturally inside a sentence (brand names keep their capitals). */
|
|
17
|
+
function article(label) {
|
|
18
|
+
const common = /^(Password|Private|Bearer|Secret|Card)\b/.test(label);
|
|
19
|
+
const l = common ? label.charAt(0).toLowerCase() + label.slice(1) : label;
|
|
20
|
+
return `${/^[aeiou]/i.test(l) ? 'an' : 'a'} ${l}`;
|
|
21
|
+
}
|
|
22
|
+
// ---------------------------------------------------------------- the home page
|
|
23
|
+
export function simpleHome(db, w, now = Date.now()) {
|
|
24
|
+
const meta = Q.meta(db);
|
|
25
|
+
const services = w.service ? meta.services.filter((s) => s.id === w.service) : meta.services;
|
|
26
|
+
const apps = services.map((s) => ({ id: s.id, lastSeen: s.lastSeen, reporting: now - s.lastSeen < 15 * 60000 }));
|
|
27
|
+
if (!meta.counts.traces) {
|
|
28
|
+
return {
|
|
29
|
+
health: 'no_data', headline: 'Waiting for your app', summary: 'Connect your app and send it a few requests. Health shows up here within seconds.',
|
|
30
|
+
vitals: [], timeline: [], bucketMs: 0, broke: [], changed: [], usualBasis: null, todo: [], suggestions: [], apps,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const ov = Q.overview(db, w);
|
|
34
|
+
const k = ov.kpis;
|
|
35
|
+
const usual = k.usual && k.usual.requests >= 50 ? k.usual : null;
|
|
36
|
+
const live = now - w.to < 5 * 60000;
|
|
37
|
+
// ---- vitals
|
|
38
|
+
const vitals = [];
|
|
39
|
+
const req = k.requests || 0;
|
|
40
|
+
const ok = req ? 100 - k.failureRate : 100;
|
|
41
|
+
vitals.push({
|
|
42
|
+
id: 'working', label: 'Requests working', value: req ? fmtPct(ok) : '—',
|
|
43
|
+
note: !req ? 'No requests in this period' : k.failed ? `${n0(k.failed)} of ${n0(req)} failed with a server error` : `All ${n0(req)} requests worked`,
|
|
44
|
+
tone: !req ? 'neutral' : req >= 20 && k.failureRate >= 5 ? 'bad' : k.failureRate >= 1 && k.failed >= 3 ? 'warn' : 'good',
|
|
45
|
+
usual: usual ? `usually ${fmtPct(100 - usual.failureRate)}` : null,
|
|
46
|
+
});
|
|
47
|
+
const slowX = usual?.p95 && k.p95 ? k.p95 / usual.p95 : null;
|
|
48
|
+
vitals.push({
|
|
49
|
+
id: 'speed', label: 'Speed', value: fmtMs(k.p95),
|
|
50
|
+
note: k.p95 == null ? 'No requests to time' : `95% of requests finish within ${fmtMs(k.p95)}`,
|
|
51
|
+
tone: k.p95 == null ? 'neutral'
|
|
52
|
+
: (slowX != null && slowX >= 2 && k.p95 - usual.p95 > 200) || k.p95 >= 5000 ? 'bad'
|
|
53
|
+
: (slowX != null && slowX >= 1.4 && k.p95 - usual.p95 > 80) || k.p95 >= 1500 ? 'warn' : 'good',
|
|
54
|
+
usual: usual?.p95 ? `usually ${fmtMs(usual.p95)}` : null,
|
|
55
|
+
});
|
|
56
|
+
const trafficX = usual && usual.requests ? req / usual.requests : null;
|
|
57
|
+
vitals.push({
|
|
58
|
+
id: 'traffic', label: 'Traffic', value: n0(req),
|
|
59
|
+
note: k.rpm ? `about ${n0(k.rpm)} requests a minute` : req ? `${plural(req, 'request')}` : 'Nobody called your app',
|
|
60
|
+
tone: trafficX != null && trafficX <= 0.3 && live ? 'warn' : 'neutral',
|
|
61
|
+
usual: trafficX == null ? null : trafficX >= 1.5 ? `${trafficX.toFixed(1)}× more than usual` : trafficX <= 0.67 ? `${Math.round((1 - trafficX) * 100)}% less than usual` : 'about usual',
|
|
62
|
+
});
|
|
63
|
+
const server = serverLoad(db, w, services.map((s) => s.id));
|
|
64
|
+
vitals.push({
|
|
65
|
+
id: 'server', label: 'Server', value: server ? (server.worst >= 90 ? 'Overloaded' : server.worst >= 75 ? 'Busy' : 'OK') : '—',
|
|
66
|
+
note: server ? [server.cpu != null ? `CPU ${Math.round(server.cpu)}%` : null, server.mem != null ? `memory ${Math.round(server.mem)}%` : null, plural(server.instances, 'instance')].filter(Boolean).join(' · ') : 'No server stats yet',
|
|
67
|
+
tone: !server ? 'neutral' : server.worst >= 90 ? 'bad' : server.worst >= 75 ? 'warn' : 'good',
|
|
68
|
+
});
|
|
69
|
+
// ---- what broke
|
|
70
|
+
const broke = [];
|
|
71
|
+
const todo = [];
|
|
72
|
+
const suggestions = [];
|
|
73
|
+
const leaks = secretGroups(db, { from: 0, to: now, service: w.service, status: 'open' });
|
|
74
|
+
for (const g of leaks.slice(0, 3)) {
|
|
75
|
+
const where = g.operation ? ` in ${g.operation}` : g.logger ? ` (logger ${g.logger})` : '';
|
|
76
|
+
broke.push({
|
|
77
|
+
id: `secret:${g.fingerprint}`, kind: 'secret', tone: 'bad', ts: g.lastSeen, count: g.count,
|
|
78
|
+
title: `${cap(article(g.label))} is being written to your ${g.source === 'error' ? 'error messages' : 'logs'}`,
|
|
79
|
+
detail: `${g.service}${where} · ${times(g.count)} so far. Obzerver hid it before saving, but your code still prints it.`,
|
|
80
|
+
link: `/secrets?fp=${g.fingerprint}`, ask: `Where is ${article(g.label)} leaking into the logs of ${g.service}, and how do I stop it?`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (leaks.length > 3)
|
|
84
|
+
broke.push({ id: 'secret:more', kind: 'secret', tone: 'bad', title: `${leaks.length - 3} more places leak secrets`, detail: 'Each one needs the same fix.', link: '/secrets' });
|
|
85
|
+
for (const s of meta.services) {
|
|
86
|
+
if (w.service && s.id !== w.service)
|
|
87
|
+
continue;
|
|
88
|
+
if (now - s.lastSeen >= 15 * 60000 && now - s.lastSeen < 2 * 86400e3) {
|
|
89
|
+
broke.push({
|
|
90
|
+
id: `silent:${s.id}`, kind: 'silent', tone: 'bad', ts: s.lastSeen, title: `${s.id} stopped reporting`,
|
|
91
|
+
detail: 'We have not heard from it for a while. It may have crashed, been stopped, or lost its connection to Obzerver.',
|
|
92
|
+
link: `/logs?service=${enc(s.id)}`, ask: `Why did ${s.id} stop reporting? What happened right before?`,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const alertsFiring = db.all("SELECT id, name, type, params, last_change FROM alert_rules WHERE state = 'firing' AND enabled = 1 AND type NOT IN ('secret_leak', 'new_error_group', 'silence')");
|
|
97
|
+
const slosSeen = new Set();
|
|
98
|
+
for (const a of alertsFiring) {
|
|
99
|
+
if (a.type === 'slo_burn') {
|
|
100
|
+
// One line per SLO, whichever burn speeds fire.
|
|
101
|
+
const p = toRule(a).params;
|
|
102
|
+
const slo = p.sloId ? db.get('SELECT id, name, target FROM slos WHERE id = ?', p.sloId) : null;
|
|
103
|
+
if (!slo || slosSeen.has(slo.id))
|
|
104
|
+
continue;
|
|
105
|
+
slosSeen.add(slo.id);
|
|
106
|
+
const fast = alertsFiring.some((x) => x.type === 'slo_burn' && toRule(x).params.sloId === slo.id && toRule(x).params.speed === 'fast');
|
|
107
|
+
broke.push({ id: `slo:${slo.id}`, kind: 'alert', tone: 'bad', ts: a.last_change, title: `${slo.name} is below its ${slo.target}% goal`, detail: `Too many requests are failing: at this pace the room for errors you allowed runs out ${fast ? 'within hours' : 'within days'}.`, link: '/slos', ask: `Why is ${slo.name} below its goal?` });
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const msg = db.get("SELECT message FROM alert_events WHERE rule_id = ? AND state = 'firing' ORDER BY ts DESC LIMIT 1", a.id)?.message;
|
|
111
|
+
broke.push({ id: `alert:${a.id}`, kind: 'alert', tone: a.type === 'error_rate' ? 'bad' : 'warn', ts: a.last_change, title: `Alert: ${a.name}`, detail: clip(msg || 'Firing now', 160), link: `/alerts?rule=${a.id}` });
|
|
112
|
+
}
|
|
113
|
+
const errs = ov.errorGroups.slice(0, 4);
|
|
114
|
+
for (const g of errs) {
|
|
115
|
+
const ex = db.get('SELECT id FROM traces WHERE fingerprint = ? AND ts >= ? ORDER BY ts DESC LIMIT 1', g.fingerprint, w.from - 86400e3)?.id ?? null;
|
|
116
|
+
broke.push({
|
|
117
|
+
id: `error:${g.fingerprint}`, kind: 'error', tone: g.count >= 10 || g.isNew ? 'bad' : 'warn', ts: g.lastSeen, count: g.count, users: g.users, isNew: g.isNew, executionId: ex,
|
|
118
|
+
title: `${g.class}${g.operation ? ` in ${g.operation}` : ''}`,
|
|
119
|
+
detail: `${clip(g.message, 120)} · ${times(g.count)}${g.users ? `, ${plural(g.users, 'user')} affected` : ''}`,
|
|
120
|
+
link: `/errors/${g.fingerprint}`, ask: `Why does "${clip(g.class + ': ' + g.message, 90)}" happen${g.operation ? ` in ${g.operation}` : ''}, and how do I fix it?`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const errorOps = new Set(errs.map((g) => g.operation).filter(Boolean));
|
|
124
|
+
const failing = ov.mostFailing.filter((o) => o.failed >= 3 && o.failureRate >= 5 && !errorOps.has(o.name)).slice(0, 3);
|
|
125
|
+
for (const o of failing) {
|
|
126
|
+
broke.push({
|
|
127
|
+
id: `endpoint:${o.service}:${o.name}`, kind: 'endpoint', tone: o.failureRate >= 20 ? 'bad' : 'warn', ts: o.lastSeen, count: o.failed,
|
|
128
|
+
title: `${o.name} is failing`, detail: `${fmtPct(o.failureRate)} of its requests fail (${n0(o.failed)} of ${n0(o.calls)}) · ${o.service}`,
|
|
129
|
+
link: opLink('http', o.service, o.name), ask: `Why is ${o.name} failing?`,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (k.jobs >= 5 && k.jobsFailed >= 3 && k.jobsFailed / k.jobs >= 0.1) {
|
|
133
|
+
const top = Q.operations(db, w, 'job').filter((j) => j.failed > 0).sort((a, b) => b.failed - a.failed)[0];
|
|
134
|
+
broke.push({
|
|
135
|
+
id: 'jobs', kind: 'jobs', tone: k.jobsFailed / k.jobs >= 0.25 ? 'bad' : 'warn', count: k.jobsFailed,
|
|
136
|
+
title: 'Background jobs are failing', detail: `${n0(k.jobsFailed)} of ${n0(k.jobs)} runs failed${top ? `, mostly ${top.name}` : ''}`,
|
|
137
|
+
link: top ? opLink('job', top.service, top.name) : '/jobs', ask: `Why are ${top ? top.name : 'background'} jobs failing?`,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
broke.sort(byTone);
|
|
141
|
+
// ---- what changed
|
|
142
|
+
const changed = [];
|
|
143
|
+
const since = Math.min(w.from, now - 7 * 86400e3);
|
|
144
|
+
const recent = Q.releases(db, w).filter((r) => r.first >= since)
|
|
145
|
+
// "First version we have seen" is only news when it is the newest version of that app.
|
|
146
|
+
.filter((r, i, all) => r.verdict !== 'baseline' || !all.slice(0, i).some((x) => x.service === r.service)).slice(0, 4);
|
|
147
|
+
const latestPerService = new Set();
|
|
148
|
+
for (const r of recent) {
|
|
149
|
+
const v = Q.releaseVerdict(db, r.service, r.version);
|
|
150
|
+
if (!v)
|
|
151
|
+
continue;
|
|
152
|
+
const tone = v.verdict === 'regression' ? 'bad' : v.verdict === 'changed' ? 'warn' : v.verdict === 'clean' ? 'good' : 'neutral';
|
|
153
|
+
const detail = releaseInPlainWords(v);
|
|
154
|
+
changed.push({ id: `release:${r.service}:${r.version}`, kind: 'release', tone, ts: r.first, title: `${r.service} ${r.version} was deployed`, detail, link: `/releases?release=${enc(`${r.service}@${r.version}`)}`, ask: `What changed in ${r.service} ${r.version}${v.previous ? ` compared to ${v.previous}` : ''}?` });
|
|
155
|
+
if (!latestPerService.has(r.service)) {
|
|
156
|
+
latestPerService.add(r.service);
|
|
157
|
+
if (v.verdict === 'regression' && v.previous) {
|
|
158
|
+
todo.push({
|
|
159
|
+
id: `rollback:${r.service}`, urgency: 'now', title: `Roll back ${r.service} to ${v.previous}`, why: detail.replace(/^Made things worse/, `${r.version} made things worse`),
|
|
160
|
+
steps: [`Redeploy ${v.previous} (or revert the last change) to stop the damage`, 'Look at the new errors it brought', 'Ship a fix; Obzerver compares the next release automatically'],
|
|
161
|
+
link: `/releases?release=${enc(`${r.service}@${r.version}`)}`, linkLabel: 'Compare with before', ask: `What broke in ${r.service} ${r.version} compared to ${v.previous}?`,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const newErrs = ov.errorGroups.filter((g) => g.isNew);
|
|
167
|
+
if (newErrs.length) {
|
|
168
|
+
changed.push({ id: 'new_errors', kind: 'new_errors', tone: 'warn', title: `${plural(newErrs.length, 'new kind', 'new kinds')} of error started`, detail: newErrs.slice(0, 3).map((g) => g.class + (g.operation ? ` in ${g.operation}` : '')).join(' · '), link: '/errors', count: newErrs.length });
|
|
169
|
+
}
|
|
170
|
+
if (usual) {
|
|
171
|
+
if (k.failureRate > Math.max(1, usual.failureRate * 3) && k.failed >= 5) {
|
|
172
|
+
changed.push({ id: 'failures', kind: 'failures', tone: 'bad', title: 'More requests are failing than usual', detail: `${fmtPct(k.failureRate)} fail right now; usually it's ${fmtPct(usual.failureRate)}.`, link: '/requests?sort=failureRate' });
|
|
173
|
+
}
|
|
174
|
+
if (slowX != null && slowX >= 1.4 && k.p95 - usual.p95 > 80) {
|
|
175
|
+
changed.push({ id: 'speed', kind: 'speed', tone: 'warn', title: 'Your app is slower than usual', detail: `${fmtMs(k.p95)} for the slowest requests instead of the usual ${fmtMs(usual.p95)}.`, link: '/requests?sort=p95' });
|
|
176
|
+
}
|
|
177
|
+
else if (slowX != null && slowX <= 0.6 && usual.p95 - k.p95 > 50) {
|
|
178
|
+
changed.push({ id: 'speed', kind: 'speed', tone: 'good', title: 'Faster than usual', detail: `${fmtMs(k.p95)} for the slowest requests instead of the usual ${fmtMs(usual.p95)}.` });
|
|
179
|
+
}
|
|
180
|
+
if (trafficX != null && (trafficX >= 1.8 || trafficX <= 0.5)) {
|
|
181
|
+
changed.push({
|
|
182
|
+
id: 'traffic', kind: 'traffic', tone: trafficX <= 0.3 && live ? 'warn' : 'neutral',
|
|
183
|
+
title: trafficX >= 1.8 ? `${trafficX.toFixed(1)}× more traffic than usual` : `${Math.round((1 - trafficX) * 100)}% less traffic than usual`,
|
|
184
|
+
detail: `${n0(req)} requests; usually about ${n0(usual.requests)} at this time.`, link: '/requests',
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
changed.sort((a, b) => (b.ts ?? now) - (a.ts ?? now));
|
|
189
|
+
// ---- what to do (most urgent first, at most five)
|
|
190
|
+
for (const g of leaks.slice(0, 2)) {
|
|
191
|
+
const what = article(g.label);
|
|
192
|
+
todo.unshift({
|
|
193
|
+
id: `secret:${g.fingerprint}`, urgency: 'now', title: `Stop logging ${what}`,
|
|
194
|
+
why: `It shows up in ${g.source === 'error' ? 'error messages' : 'the logs'} of ${g.service}${g.operation ? ` at ${g.operation}` : ''}. Anyone who can read logs could see it.`,
|
|
195
|
+
steps: [`Find the line that logs it${g.operation ? ` (the code behind ${g.operation})` : ''}`, 'Log an id or a masked value instead of the secret', `Change (rotate) the ${g.label.toLowerCase()} — assume it was exposed`, 'Mark it fixed here; we will tell you if it comes back'],
|
|
196
|
+
link: `/secrets?fp=${g.fingerprint}`, linkLabel: 'See where', ask: `Where is ${what} leaking into the logs of ${g.service}, and how do I stop it?`,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
for (const f of broke.filter((b) => b.kind === 'silent')) {
|
|
200
|
+
const id = f.id.slice('silent:'.length);
|
|
201
|
+
todo.push({
|
|
202
|
+
id: f.id, urgency: 'now', title: `Check that ${id} is running`, why: 'It stopped sending data, so either it is down or it lost its connection.',
|
|
203
|
+
steps: ['Open your hosting dashboard (Render, Railway, Fly, Vercel, your server…) and check the app is up', 'Read its last logs before it went quiet', 'Restart or redeploy it'],
|
|
204
|
+
link: f.link, linkLabel: 'Last logs', ask: f.ask,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
for (const f of broke.filter((b) => b.kind === 'error').slice(0, 2)) {
|
|
208
|
+
todo.push({
|
|
209
|
+
id: f.id, urgency: f.tone === 'bad' ? 'now' : 'soon', title: `Fix ${f.title}`,
|
|
210
|
+
why: `${f.isNew ? 'A new error that ' : 'It '}happened ${times(f.count ?? 0)}${f.users ? ` to ${plural(f.users, 'user')}` : ''} in this period.`,
|
|
211
|
+
steps: [f.executionId ? 'Copy the fix prompt below and paste it into your AI editor (Cursor, Claude Code, Copilot…)' : 'Open the error to see the exact line of code', 'Check the change and deploy it', 'Come back here: the error should stop showing up'],
|
|
212
|
+
link: f.link, linkLabel: 'Open the error', ask: f.ask, executionId: f.executionId,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
for (const f of broke.filter((b) => b.kind === 'endpoint' || b.kind === 'jobs').slice(0, 1)) {
|
|
216
|
+
todo.push({ id: f.id, urgency: 'soon', title: `Find out why ${f.kind === 'jobs' ? 'jobs fail' : f.title.replace(/ is failing$/, ' fails')}`, why: f.detail, steps: ['Open it and look at a failed request', 'Read the logs written during that request', 'Ask Obzeri if the cause is not obvious'], link: f.link, linkLabel: 'Open it', ask: f.ask });
|
|
217
|
+
}
|
|
218
|
+
const speed = vitals.find((v) => v.id === 'speed');
|
|
219
|
+
if (speed.tone !== 'good' && ov.slowest[0]) {
|
|
220
|
+
const o = ov.slowest[0];
|
|
221
|
+
todo.push({
|
|
222
|
+
id: 'slow', urgency: speed.tone === 'bad' ? 'now' : 'soon', title: `Speed up ${o.name}`, why: `It's your slowest endpoint: the slowest requests take ${fmtMs(o.p95)}.`,
|
|
223
|
+
steps: ['Open it and see where the time goes (database, outside APIs, your code)', 'Fix the biggest part first, often a slow or repeated database query', 'Deploy and compare'],
|
|
224
|
+
link: opLink('http', o.service, o.name), linkLabel: 'See where time goes', ask: `Why is ${o.name} slow?`,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
if (server && server.worst >= 75) {
|
|
228
|
+
todo.push({
|
|
229
|
+
id: 'server', urgency: server.worst >= 90 ? 'now' : 'soon', title: server.mem != null && server.mem >= (server.cpu ?? 0) ? 'Your server is running low on memory' : 'Your server is running hot',
|
|
230
|
+
why: `${server.cpu != null ? `CPU at ${Math.round(server.cpu)}%` : ''}${server.cpu != null && server.mem != null ? ', ' : ''}${server.mem != null ? `memory at ${Math.round(server.mem)}%` : ''}. Close to the limit, the app slows down or restarts.`,
|
|
231
|
+
steps: ['Check whether it keeps climbing (a leak) or just follows traffic', 'Give the app more memory/CPU or add an instance', 'If it keeps climbing, look at the latest release'],
|
|
232
|
+
link: '/profiler', linkLabel: 'Open the profiler', ask: 'Is my server running out of memory or CPU, and why?',
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
const notified = db.all('SELECT channels FROM alert_rules WHERE enabled = 1').some((r) => /"type":"(email|slack|webhook)"/.test(r.channels || ''));
|
|
236
|
+
if (!notified) {
|
|
237
|
+
todo.push({ id: 'notify', urgency: 'later', title: 'Get told when something breaks', why: 'Alerts only show up in this dashboard right now. Add your email or Slack so you hear about problems first.', steps: ['Pick what you want to hear about', 'Add your email or a Slack webhook', 'Send a test'], link: '/alerts', linkLabel: 'Set up alerts' });
|
|
238
|
+
}
|
|
239
|
+
if (!meta.versions.length) {
|
|
240
|
+
todo.push({ id: 'versions', urgency: 'later', title: 'Tag your deploys', why: 'With a version on each deploy, Obzerver tells you whether a release made things better or worse.', steps: ['Most CI and hosting providers are detected automatically', 'Otherwise set OBZERVER_VERSION (your version or git commit) when you deploy'], link: '/settings', linkLabel: 'How to connect' });
|
|
241
|
+
}
|
|
242
|
+
const URG = { now: 0, soon: 1, later: 2 };
|
|
243
|
+
const seen = new Set();
|
|
244
|
+
const todos = todo.filter((t) => (seen.has(t.id) ? false : (seen.add(t.id), true))).sort((a, b) => URG[a.urgency] - URG[b.urgency]).slice(0, 5);
|
|
245
|
+
// ---- verdict
|
|
246
|
+
const bad = broke.filter((b) => b.tone === 'bad').length + changed.filter((c) => c.tone === 'bad').length + vitals.filter((v) => v.tone === 'bad').length;
|
|
247
|
+
const warn = broke.filter((b) => b.tone === 'warn').length + changed.filter((c) => c.tone === 'warn').length + vitals.filter((v) => v.tone === 'warn').length;
|
|
248
|
+
const health = bad ? 'broken' : warn ? 'attention' : req === 0 ? 'idle' : 'healthy';
|
|
249
|
+
const top = broke[0] ?? changed.find((c) => c.tone === 'bad' || c.tone === 'warn');
|
|
250
|
+
const headline = health === 'broken' ? (broke.length && broke.every((b) => b.kind === 'secret') ? 'Your app works, but it leaks secrets' : 'Something is broken')
|
|
251
|
+
: health === 'attention' ? 'Mostly fine, a few things to look at'
|
|
252
|
+
: health === 'idle' ? 'All quiet' : 'Your app is healthy';
|
|
253
|
+
const issues = broke.filter((b) => b.tone !== 'good').length + changed.filter((c) => c.tone === 'bad' && c.kind !== 'new_errors').length + vitals.filter((v) => v.tone === 'bad' || v.tone === 'warn').length;
|
|
254
|
+
const lower = (t) => (/^(A|An|Your|More|Background|Faster)\b/.test(t) ? t.charAt(0).toLowerCase() + t.slice(1) : t);
|
|
255
|
+
const summary = health === 'healthy'
|
|
256
|
+
? `${n0(req)} requests, ${fmtPct(ok)} worked and most answered within ${fmtMs(k.p95)}.${usual ? ' That is normal for this time.' : ''}`
|
|
257
|
+
: health === 'idle' ? 'No requests in this period, and nothing is wrong.'
|
|
258
|
+
: top ? `${issues > 1 ? `${plural(issues, 'thing')} need a look. ` : ''}Most urgent: ${lower(top.title)}.` : `${plural(issues, 'thing')} to look at below.`;
|
|
259
|
+
// ---- questions worth asking
|
|
260
|
+
if (broke[0]?.ask)
|
|
261
|
+
suggestions.push(broke[0].ask);
|
|
262
|
+
const rel = changed.find((c) => c.kind === 'release');
|
|
263
|
+
if (rel?.ask)
|
|
264
|
+
suggestions.push(rel.ask);
|
|
265
|
+
suggestions.push('Is my app healthy right now?', 'What changed since yesterday?', 'What should I fix first?', 'Which page is the slowest for my users?');
|
|
266
|
+
return {
|
|
267
|
+
health, headline, summary, vitals,
|
|
268
|
+
timeline: ov.series.points.map((p) => ({ t: p.t, count: p.count, failed: p.s5xx ?? p.failed ?? 0 })), bucketMs: ov.series.bucketMs,
|
|
269
|
+
broke, changed, usualBasis: usual?.description ?? null, todo: todos, suggestions: [...new Set(suggestions)].slice(0, 6), apps,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
273
|
+
function releaseInPlainWords(v) {
|
|
274
|
+
const a = v.previousStats, b = v.stats;
|
|
275
|
+
if (v.verdict === 'baseline')
|
|
276
|
+
return 'The first version we have seen of this app. The next deploy is compared with it.';
|
|
277
|
+
if (v.verdict === 'not_enough_data')
|
|
278
|
+
return 'Too early to tell: not enough traffic on it yet.';
|
|
279
|
+
if (v.verdict === 'clean')
|
|
280
|
+
return `Looks good: errors ${a?.errorRate ?? 0}% → ${b.errorRate ?? 0}%, speed ${fmtMs(a?.p95)} → ${fmtMs(b.p95)}.`;
|
|
281
|
+
const parts = [];
|
|
282
|
+
if (a && (b.errorRate ?? 0) - (a.errorRate ?? 0) > 0.3)
|
|
283
|
+
parts.push(`more requests fail (${a.errorRate}% → ${b.errorRate}%)`);
|
|
284
|
+
for (const e of v.evidence) {
|
|
285
|
+
if (e.type === 'memory_leak')
|
|
286
|
+
parts.push('memory keeps growing (a memory leak)');
|
|
287
|
+
else if (e.type === 'new_errors')
|
|
288
|
+
parts.push(`${plural(v.newErrors.length, 'new kind', 'new kinds')} of error`);
|
|
289
|
+
else if (e.type === 'latency' && a)
|
|
290
|
+
parts.push(`slower (${fmtMs(a.p95)} → ${fmtMs(b.p95)})`);
|
|
291
|
+
else if (e.type === 'memory')
|
|
292
|
+
parts.push('uses more memory');
|
|
293
|
+
else if (e.type === 'cpu')
|
|
294
|
+
parts.push('uses more CPU');
|
|
295
|
+
else if (e.type === 'event_loop')
|
|
296
|
+
parts.push('the server is busier');
|
|
297
|
+
else if (e.type === 'outbound')
|
|
298
|
+
parts.push('calls new outside services');
|
|
299
|
+
else if (e.type === 'quiet_routes')
|
|
300
|
+
parts.push('some endpoints stopped getting traffic');
|
|
301
|
+
}
|
|
302
|
+
if (!parts.length)
|
|
303
|
+
parts.push('the code now runs different database queries or calls');
|
|
304
|
+
const s = [...new Set(parts)].join(', ');
|
|
305
|
+
return v.verdict === 'regression' ? `Made things worse: ${s}.` : `Works, but behaves differently: ${s}.`;
|
|
306
|
+
}
|
|
307
|
+
/** Latest CPU and memory utilization across the apps' instances (the worst one counts). */
|
|
308
|
+
function serverLoad(db, w, services) {
|
|
309
|
+
if (!services.length)
|
|
310
|
+
return null;
|
|
311
|
+
const rows = db.all(`SELECT r.* FROM runtime r JOIN (SELECT service, instance, MAX(ts) mts FROM runtime WHERE ts >= ? AND ts <= ? AND service IN (${services.map(() => '?').join(',')}) GROUP BY service, instance) m
|
|
312
|
+
ON r.service = m.service AND r.instance = m.instance AND r.ts = m.mts`, Math.max(w.from, w.to - 30 * 60000), w.to, ...services);
|
|
313
|
+
if (!rows.length)
|
|
314
|
+
return null;
|
|
315
|
+
let cpu = null, mem = null;
|
|
316
|
+
for (const r of rows) {
|
|
317
|
+
const c = r.cpu == null ? null : r.cores ? r.cpu / Math.min(r.cores, r.cpu_limit || r.cores) : r.cpu;
|
|
318
|
+
const heap = r.heap_used != null && r.heap_limit ? (r.heap_used / r.heap_limit) * 100 : null;
|
|
319
|
+
const box = r.rss != null && r.mem_limit ? (r.rss / r.mem_limit) * 100 : null;
|
|
320
|
+
const m = Math.max(heap ?? -1, box ?? -1);
|
|
321
|
+
if (c != null)
|
|
322
|
+
cpu = Math.max(cpu ?? 0, c);
|
|
323
|
+
if (m >= 0)
|
|
324
|
+
mem = Math.max(mem ?? 0, m);
|
|
325
|
+
}
|
|
326
|
+
return { cpu, mem, worst: Math.max(cpu ?? 0, mem ?? 0), instances: rows.length };
|
|
327
|
+
}
|
|
328
|
+
/** What a newcomer wants to hear about. Each maps to one alert type; Advanced mode shows the rules themselves. */
|
|
329
|
+
export const PRESETS = [
|
|
330
|
+
{ id: 'down', type: 'silence', label: 'My app goes down', description: 'No requests or data for 15 minutes', params: { windowMin: 15 } },
|
|
331
|
+
{ id: 'errors', type: 'error_rate', label: 'Errors suddenly jump', description: 'Far more failed requests than normal for this time', params: { mode: 'anomaly', windowMin: 15, minRequests: 20, threshold: 2 } },
|
|
332
|
+
{ id: 'slow', type: 'p95_latency', label: 'My app gets slow', description: 'The slowest requests take more than 1.5 seconds', params: { mode: 'threshold', windowMin: 10, threshold: 1500, op: '>', minRequests: 20 } },
|
|
333
|
+
{ id: 'new_error', type: 'new_error_group', label: 'A new kind of error shows up', description: 'The first time an error we have never seen happens', params: {} },
|
|
334
|
+
{ id: 'secret', type: 'secret_leak', label: 'A password or key leaks into logs', description: 'Passwords, tokens, API keys or card numbers in a log line', params: {} },
|
|
335
|
+
{ id: 'jobs', type: 'job_failure_rate', label: 'Background jobs start failing', description: 'More than 10% of job runs fail', params: { mode: 'threshold', windowMin: 15, threshold: 10, op: '>', minRequests: 5 } },
|
|
336
|
+
];
|
|
337
|
+
/** Rules that cover a preset: its type, for the whole app (not scoped to one route or service). */
|
|
338
|
+
const presetRules = (db, p) => db.all('SELECT * FROM alert_rules WHERE type = ? ORDER BY builtin DESC, id', p.type)
|
|
339
|
+
.map(toRule).filter((r) => !r.params.service && !r.params.route && !r.params.sloId);
|
|
340
|
+
export function simpleAlerts(db, { emailReady }) {
|
|
341
|
+
const presets = PRESETS.map((p) => {
|
|
342
|
+
const rules = presetRules(db, p);
|
|
343
|
+
const on = rules.filter((r) => r.enabled);
|
|
344
|
+
const last = on.length ? db.get(`SELECT MAX(ts) ts FROM alert_events WHERE state = 'firing' AND rule_id IN (${on.map(() => '?').join(',')})`, ...on.map((r) => r.id))?.ts ?? null : null;
|
|
345
|
+
return { id: p.id, label: p.label, description: p.description, enabled: on.length > 0, firing: on.some((r) => r.state === 'firing'), lastFired: last };
|
|
346
|
+
});
|
|
347
|
+
// The channels of the enabled preset rules (they are kept in step when saved from here).
|
|
348
|
+
const chans = PRESETS.flatMap((p) => presetRules(db, p).filter((r) => r.enabled)).flatMap((r) => r.channels);
|
|
349
|
+
const channels = {
|
|
350
|
+
email: chans.find((c) => c.type === 'email')?.to || '',
|
|
351
|
+
slack: chans.find((c) => c.type === 'slack')?.url || '',
|
|
352
|
+
};
|
|
353
|
+
const events = db.all(`SELECT e.id, e.ts, e.state, e.message, r.name rule, r.type FROM alert_events e LEFT JOIN alert_rules r ON r.id = e.rule_id ORDER BY e.ts DESC LIMIT 30`)
|
|
354
|
+
.map((e) => ({ id: e.id, ts: e.ts, state: e.state, rule: e.rule || 'Deleted rule', type: e.type, message: clip(e.message, 220), kindLabel: RULE_TYPES[e.type]?.label ?? '' }));
|
|
355
|
+
const sloSeen = new Set();
|
|
356
|
+
const firing = db.all("SELECT id, name, type, params, last_change FROM alert_rules WHERE state = 'firing' AND enabled = 1 AND type <> 'secret_leak'").flatMap((r) => {
|
|
357
|
+
if (r.type !== 'slo_burn')
|
|
358
|
+
return [{ id: r.id, name: r.name, since: r.last_change }];
|
|
359
|
+
// Fast and slow burn of one SLO read as one plain line.
|
|
360
|
+
const id = toRule(r).params.sloId;
|
|
361
|
+
const slo = id ? db.get('SELECT name, target FROM slos WHERE id = ?', id) : null;
|
|
362
|
+
if (!id || !slo || sloSeen.has(id))
|
|
363
|
+
return [];
|
|
364
|
+
sloSeen.add(id);
|
|
365
|
+
return [{ id: r.id, name: `${slo.name} is below its ${slo.target}% goal`, since: r.last_change }];
|
|
366
|
+
});
|
|
367
|
+
return { presets, channels, emailReady, firing, events };
|
|
368
|
+
}
|
|
369
|
+
export function saveSimpleAlerts(db, body) {
|
|
370
|
+
const want = body.channels;
|
|
371
|
+
const channels = (existing) => {
|
|
372
|
+
if (!want)
|
|
373
|
+
return existing;
|
|
374
|
+
const keep = existing.filter((c) => c.type !== 'email' && c.type !== 'slack');
|
|
375
|
+
if (!keep.some((c) => c.type === 'inapp'))
|
|
376
|
+
keep.unshift({ type: 'inapp' });
|
|
377
|
+
if (want.email?.trim())
|
|
378
|
+
keep.push({ type: 'email', to: want.email.trim() });
|
|
379
|
+
if (want.slack?.trim())
|
|
380
|
+
keep.push({ type: 'slack', url: want.slack.trim() });
|
|
381
|
+
return keep;
|
|
382
|
+
};
|
|
383
|
+
if (want?.slack && !/^https:\/\/\S+$/.test(want.slack.trim()))
|
|
384
|
+
throw Object.assign(new Error('The Slack webhook should be an https:// URL'), { statusCode: 400 });
|
|
385
|
+
if (want?.email && !want.email.split(',').every((e) => /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(e.trim())))
|
|
386
|
+
throw Object.assign(new Error('That does not look like an email address'), { statusCode: 400 });
|
|
387
|
+
db.tx(() => {
|
|
388
|
+
for (const p of PRESETS) {
|
|
389
|
+
const rules = presetRules(db, p);
|
|
390
|
+
const on = body.presets?.[p.id];
|
|
391
|
+
if (on === true && !rules.length) {
|
|
392
|
+
const shared = want ? channels([{ type: 'inapp' }]) : currentChannels(db);
|
|
393
|
+
db.run('INSERT INTO alert_rules(name, type, params, channels, enabled, created) VALUES(?, ?, ?, ?, 1, ?)', p.label, p.type, JSON.stringify({ ...p.params, preset: p.id }), JSON.stringify(shared), Date.now());
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
for (const r of rules) {
|
|
397
|
+
const enabled = on === undefined ? r.enabled : on ? (r === rules[0] ? true : r.enabled) : false;
|
|
398
|
+
db.run('UPDATE alert_rules SET enabled = ?, channels = ? WHERE id = ?', enabled ? 1 : 0, JSON.stringify(channels(r.channels)), r.id);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
function currentChannels(db) {
|
|
404
|
+
const a = simpleAlerts(db, { emailReady: true }).channels;
|
|
405
|
+
const out = [{ type: 'inapp' }];
|
|
406
|
+
if (a.email)
|
|
407
|
+
out.push({ type: 'email', to: a.email });
|
|
408
|
+
if (a.slack)
|
|
409
|
+
out.push({ type: 'slack', url: a.slack });
|
|
410
|
+
return out;
|
|
411
|
+
}
|
|
412
|
+
/** One enabled preset rule to send a test through. */
|
|
413
|
+
export function simpleTestRule(db) {
|
|
414
|
+
for (const p of PRESETS) {
|
|
415
|
+
const r = presetRules(db, p).find((x) => x.enabled && x.channels.some((c) => c.type !== 'inapp'));
|
|
416
|
+
if (r)
|
|
417
|
+
return r;
|
|
418
|
+
}
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
const VERDICT_LABEL = {
|
|
422
|
+
regression: ['Made things worse', 'bad'], changed: ['Works, but behaves differently', 'warn'], clean: ['Looks good', 'good'],
|
|
423
|
+
not_enough_data: ['Too early to tell', 'neutral'], baseline: ['First version we have seen', 'neutral'],
|
|
424
|
+
};
|
|
425
|
+
/** Every deploy of every app, newest first, with a verdict and a before/after anyone can read. */
|
|
426
|
+
export function simpleReleases(db, w) {
|
|
427
|
+
const seen = new Set();
|
|
428
|
+
return Q.releases(db, w).flatMap((r) => {
|
|
429
|
+
const v = Q.releaseVerdict(db, r.service, r.version);
|
|
430
|
+
if (!v)
|
|
431
|
+
return [];
|
|
432
|
+
const latest = !seen.has(r.service);
|
|
433
|
+
seen.add(r.service);
|
|
434
|
+
const [label, tone] = VERDICT_LABEL[v.verdict];
|
|
435
|
+
const a = v.previousStats, b = v.stats;
|
|
436
|
+
const compare = [];
|
|
437
|
+
const worse = (x, y, ratio, abs) => x == null || y == null ? 'neutral' : y > x * ratio && y - x > abs ? 'bad' : x > y * ratio && x - y > abs ? 'good' : 'neutral';
|
|
438
|
+
if (a) {
|
|
439
|
+
compare.push({ label: 'Requests failing', before: `${a.errorRate ?? 0}%`, after: `${b.errorRate ?? 0}%`, tone: worse(a.errorRate, b.errorRate, 1.5, 0.3), hint: 'Share of requests that failed with a server error' });
|
|
440
|
+
compare.push({ label: 'Slowest requests', before: fmtMs(a.p95), after: fmtMs(b.p95), tone: worse(a.p95, b.p95, 1.3, 20), hint: '95% of requests finish within this' });
|
|
441
|
+
compare.push({ label: 'Average speed', before: fmtMs(a.avg), after: fmtMs(b.avg), tone: worse(a.avg, b.avg, 1.3, 10) });
|
|
442
|
+
const ra = v.previousRuntime, rb = v.runtime;
|
|
443
|
+
if (ra && rb) {
|
|
444
|
+
if (ra.heapUsed != null && rb.heapUsed != null)
|
|
445
|
+
compare.push({ label: 'Memory used', before: `${Math.round(ra.heapUsed)} MB`, after: `${Math.round(rb.heapUsed)} MB`, tone: worse(ra.heapUsed, rb.heapUsed, 1.3, 20) });
|
|
446
|
+
if (rb.heapGrowth != null) {
|
|
447
|
+
const leak = v.evidence.some((e) => e.type === 'memory_leak');
|
|
448
|
+
compare.push({ label: 'Memory growth', before: ra.heapGrowth != null ? `${ra.heapGrowth.toFixed(1)} MB/h` : '—', after: `${rb.heapGrowth.toFixed(1)} MB/h`, tone: leak ? 'bad' : 'neutral', hint: leak ? 'Keeps climbing: a memory leak, the app will run out of memory and restart' : 'How fast memory grows per instance' });
|
|
449
|
+
}
|
|
450
|
+
const ca = ra.cpuUtil ?? ra.cpu, cb = rb.cpuUtil ?? rb.cpu;
|
|
451
|
+
if (ca != null && cb != null)
|
|
452
|
+
compare.push({ label: 'CPU', before: `${Math.round(ca)}%`, after: `${Math.round(cb)}%`, tone: worse(ca, cb, 1.3, 5) });
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const codeChanges = [];
|
|
456
|
+
const count = (type, change) => v.changes.filter((c) => c.type === type && c.change === change).length;
|
|
457
|
+
const say = (n, text) => { if (n)
|
|
458
|
+
codeChanges.push(`${n} ${text}`); };
|
|
459
|
+
say(count('query', 'new'), count('query', 'new') === 1 ? 'new database query' : 'new database queries');
|
|
460
|
+
say(count('query', 'more_frequent'), count('query', 'more_frequent') === 1 ? 'database query now runs more often per request' : 'database queries now run more often per request');
|
|
461
|
+
say(v.changes.filter((c) => c.change === 'slower').length, v.changes.filter((c) => c.change === 'slower').length === 1 ? 'call got slower' : 'calls got slower');
|
|
462
|
+
say(count('outbound', 'new'), count('outbound', 'new') === 1 ? 'new outside service called' : 'new outside services called');
|
|
463
|
+
say(count('query', 'gone') + count('outbound', 'gone') + count('method', 'gone'), 'calls no longer made');
|
|
464
|
+
const quiet = v.evidence.find((e) => e.type === 'quiet_routes');
|
|
465
|
+
if (quiet)
|
|
466
|
+
codeChanges.push(quiet.text.replace('Routes that stopped after the boundary', 'Endpoints that stopped getting traffic'));
|
|
467
|
+
const advice = v.verdict === 'regression' && v.previous ? [
|
|
468
|
+
latest ? `Roll back to ${v.previous}: redeploy it or revert the last change` : `A later version replaced it; check that version fixed this`,
|
|
469
|
+
v.newErrors.length ? 'Fix the new errors it brought (open them below)' : 'Compare a slow or failed request before and after',
|
|
470
|
+
'Ship the fix: this page compares the next deploy automatically',
|
|
471
|
+
] : v.verdict === 'changed' && latest ? ['Nothing is failing more, but check the changes below are what you meant to ship'] : null;
|
|
472
|
+
return [{
|
|
473
|
+
service: r.service, version: r.version, previous: v.previous, first: r.first, last: r.last, requests: r.requests, latest,
|
|
474
|
+
verdict: v.verdict, tone, label,
|
|
475
|
+
summary: v.verdict === 'baseline' ? 'Every later deploy of this app is compared with it.' : releaseInPlainWords(v).replace(/^(Made things worse|Works, but behaves differently|Looks good): /, '').replace(/^./, (c) => c.toUpperCase()),
|
|
476
|
+
compare, newErrors: v.verdict === 'baseline' ? [] : v.newErrors.slice(0, 5).map((e) => ({ fingerprint: e.fingerprint, class: e.class, message: clip(e.message, 140), count: e.count })),
|
|
477
|
+
codeChanges, advice,
|
|
478
|
+
ask: v.verdict === 'regression' ? `What broke in ${r.service} ${r.version} compared to ${v.previous}, and how do I fix it?` : `What changed in ${r.service} ${r.version}${v.previous ? ` compared to ${v.previous}` : ''}?`,
|
|
479
|
+
}];
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
//# sourceMappingURL=simple.js.map
|