homebridge-pagerduty 2.1.0 → 2.2.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/CHANGELOG.md +14 -0
- package/README.md +14 -0
- package/SECURITY.md +2 -2
- package/config.schema.json +7 -4
- package/dist/controller.d.ts +32 -2
- package/dist/controller.js +108 -12
- package/dist/delivery/events.d.ts +7 -4
- package/dist/delivery/events.js +16 -4
- package/dist/delivery/health.d.ts +0 -6
- package/dist/delivery/health.js +0 -4
- package/dist/delivery/sender.d.ts +12 -1
- package/dist/delivery/sender.js +32 -9
- package/dist/devices/base-accessory.js +1 -1
- package/dist/diagnostics/collector.d.ts +5 -3
- package/dist/diagnostics/collector.js +25 -18
- package/dist/diagnostics/format.js +3 -0
- package/dist/dynamic-schema.d.ts +14 -1
- package/dist/dynamic-schema.js +88 -25
- package/dist/platform.d.ts +40 -5
- package/dist/platform.js +140 -17
- package/dist/settings.d.ts +55 -1
- package/dist/settings.js +57 -3
- package/dist/signals/config.d.ts +14 -1
- package/dist/signals/config.js +27 -0
- package/dist/signals/reader.d.ts +8 -0
- package/dist/signals/reader.js +19 -4
- package/dist/signals/schema.d.ts +8 -1
- package/dist/signals/schema.js +12 -5
- package/dist/state/desired.js +34 -5
- package/dist/state/instance-lock.d.ts +94 -0
- package/dist/state/instance-lock.js +214 -0
- package/dist/state/model.d.ts +2 -0
- package/dist/state/model.js +4 -2
- package/dist/state/mutations.d.ts +9 -1
- package/dist/state/mutations.js +29 -7
- package/dist/state/reconcile.d.ts +13 -1
- package/dist/state/reconcile.js +29 -5
- package/dist/state/store.d.ts +10 -2
- package/dist/state/store.js +20 -3
- package/dist/types/index.d.ts +31 -0
- package/dist/utils/startup-report.js +17 -2
- package/dist/utils/timing.d.ts +5 -27
- package/dist/utils/timing.js +5 -43
- package/dist/utils/validators.d.ts +21 -1
- package/dist/utils/validators.js +162 -30
- package/docs/EVENTS-API.md +8 -1
- package/docs/FEATURES.md +8 -4
- package/docs/README-DETAILED.md +53 -18
- package/docs/REVIEW.md +9 -7
- package/docs/SIGNALS-AGENT.md +1 -1
- package/docs/SIGNALS.md +10 -5
- package/package.json +10 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.2.0](https://github.com/tbaur/homebridge-pagerduty/compare/v2.1.1...v2.2.0) (2026-11-28)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* damp flapping alerts and harden signal store and delivery ([#35](https://github.com/tbaur/homebridge-pagerduty/issues/35)) ([0de1561](https://github.com/tbaur/homebridge-pagerduty/commit/0de156109b8026817325940c38fcde5f93de6d80))
|
|
9
|
+
|
|
10
|
+
## [2.1.1](https://github.com/tbaur/homebridge-pagerduty/compare/v2.1.0...v2.1.1) (2026-10-26)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* show the severity a plugin signal already has ([#25](https://github.com/tbaur/homebridge-pagerduty/issues/25)) ([36f139e](https://github.com/tbaur/homebridge-pagerduty/commit/36f139e6b5d630a64e20deb4d34f4b7b2bf09505))
|
|
16
|
+
|
|
3
17
|
## [2.1.0](https://github.com/tbaur/homebridge-pagerduty/compare/v2.0.2...v2.1.0) (2026-10-25)
|
|
4
18
|
|
|
5
19
|
|
package/README.md
CHANGED
|
@@ -22,6 +22,20 @@
|
|
|
22
22
|
|
|
23
23
|
The [detailed documentation](docs/README-DETAILED.md) describes every accessory, setting and log line.
|
|
24
24
|
|
|
25
|
+
## Integrated Plugins with Signal
|
|
26
|
+
|
|
27
|
+
These plugins write to the [signal store](docs/SIGNALS.md). Each one pages only after you allow it. No HomeKit automation rules are required.
|
|
28
|
+
|
|
29
|
+
- [homebridge-myleviton](https://github.com/tbaur/homebridge-myleviton)
|
|
30
|
+
- [homebridge-navilink](https://github.com/tbaur/homebridge-navilink)
|
|
31
|
+
- [homebridge-myalarmcom](https://github.com/tbaur/homebridge-myalarmcom)
|
|
32
|
+
- [homebridge-mynest](https://github.com/tbaur/homebridge-mynest)
|
|
33
|
+
- [homebridge-myresideo](https://github.com/tbaur/homebridge-myresideo)
|
|
34
|
+
- [homebridge-concert](https://github.com/tbaur/homebridge-concert)
|
|
35
|
+
- [homebridge-myairthings](https://github.com/tbaur/homebridge-myairthings)
|
|
36
|
+
|
|
37
|
+
If you have integrated another plugin, [let me know](https://github.com/tbaur/homebridge-pagerduty/issues) and I will add it to this list.
|
|
38
|
+
|
|
25
39
|
## Quick Start
|
|
26
40
|
|
|
27
41
|
### 1. Install
|
package/SECURITY.md
CHANGED
|
@@ -31,7 +31,7 @@ If a key leaks, delete the integration in PagerDuty, create a new one, and put t
|
|
|
31
31
|
- **Escaped log values.** Alert names, summaries and anything written by another plugin pass through `forLog`, which escapes control characters and caps length. A value cannot inject a fake log line or terminal escape codes.
|
|
32
32
|
- **Input validation.** Config is checked at startup. A missing key starts nothing. An unusable config disables the platform without unregistering accessories. A bad alert entry is held until it is fixed.
|
|
33
33
|
- **Bounded I/O.** Separate connect and total timeouts on every request, a 64 KiB response cap, and no redirects followed.
|
|
34
|
-
- **Owner-only files.** The plugin writes to one `homebridge-pagerduty` directory inside the Homebridge storage directory. That directory and the signal store's interface directory inside it are created with mode `0700`. The plugin also writes the settings screen file `.homebridge-pagerduty-v1.schema.json` next to it, where the Homebridge UI looks for it. The state file, the settings screen file and the signal store, including its `-wal` and `-shm` files, are created with mode `0600`. Store files found with a looser mode are tightened, and the plugin logs that.
|
|
34
|
+
- **Owner-only files.** The plugin writes to one `homebridge-pagerduty` directory inside the Homebridge storage directory. That directory and the signal store's interface directory inside it are created with mode `0700`. The plugin also writes the settings screen file `.homebridge-pagerduty-v1.schema.json` next to it, where the Homebridge UI looks for it. The state file, the instance lock, the settings screen file and the signal store, including its `-wal` and `-shm` files, are created with mode `0600`. Store files found with a looser mode are tightened, and the plugin logs that.
|
|
35
35
|
- **No runtime dependencies.** HTTPS and SQLite come from Node.
|
|
36
36
|
- **Dependencies audited.** CI runs `npm audit` on the runtime tree and OSV-Scanner on the full tree.
|
|
37
37
|
- **A CI step rejects key-shaped strings** in the docs, source, tests, scripts, schema and workflows, so a key cannot be committed by accident. Tests build their fake keys at runtime, and the suite refuses to run if `PAGERDUTY_ROUTING_KEY` is set.
|
|
@@ -46,7 +46,7 @@ Other plugins can raise alerts by writing rows to `homebridge-pagerduty/signals-
|
|
|
46
46
|
What the plugin does to keep the store safe to read:
|
|
47
47
|
|
|
48
48
|
- The list of allowed plugins is part of the SQL query, so rows from other plugins cannot push allowed rows out of the read.
|
|
49
|
-
- Names and text that other plugins write are validated and length-capped. On the settings screen,
|
|
49
|
+
- Names and text that other plugins write are validated and length-capped. On the settings screen, a plugin's free text is only ever a field's starting value, never a title or description, which the Homebridge UI renders as markup. Package and signal names do appear as section titles, and they are limited to lowercase letters, digits and `@/._-`, so they cannot carry markup.
|
|
50
50
|
- The schema's `CHECK` constraints limit `plugin` to package-name characters and cap every text column. Rows are validated again when read, in case another plugin created the table differently.
|
|
51
51
|
- A read error never clears an alert, so a damaged or locked store cannot silently resolve a page.
|
|
52
52
|
|
package/config.schema.json
CHANGED
|
@@ -77,10 +77,11 @@
|
|
|
77
77
|
"type": "string",
|
|
78
78
|
"minLength": 1,
|
|
79
79
|
"maxLength": 64,
|
|
80
|
+
"pattern": "^[A-Za-z0-9\\u00AA-\\uFFFF][A-Za-z0-9\\u00AA-\\uFFFF '&!._:;()/,-]*$",
|
|
80
81
|
"examples": [
|
|
81
82
|
"Leak"
|
|
82
83
|
],
|
|
83
|
-
"description": "Each severity below adds a HomeKit switch named with this prefix and the severity, such as Leak Critical. It also labels this alert in the Homebridge log. Safe to rename."
|
|
84
|
+
"description": "Each severity below adds a HomeKit switch named with this prefix and the severity, such as Leak Critical. Start it with a letter or digit, and use only letters, digits, spaces and common punctuation. It also labels this alert in the Homebridge log. Safe to rename."
|
|
84
85
|
},
|
|
85
86
|
"summary": {
|
|
86
87
|
"title": "PagerDuty Message",
|
|
@@ -149,7 +150,8 @@
|
|
|
149
150
|
"type": "string",
|
|
150
151
|
"default": "PagerDuty Maintenance",
|
|
151
152
|
"maxLength": 64,
|
|
152
|
-
"
|
|
153
|
+
"pattern": "^[A-Za-z0-9\\u00AA-\\uFFFF](?:[A-Za-z0-9\\u00AA-\\uFFFF '&!._:;()/,-]*[A-Za-z0-9\\u00AA-\\uFFFF])?$",
|
|
154
|
+
"description": "The name that HomeKit shows. Start and end it with a letter or digit. You can rename it at any time, and it keeps its room and automations."
|
|
153
155
|
},
|
|
154
156
|
"maxMinutes": {
|
|
155
157
|
"title": "Turn Off After (minutes)",
|
|
@@ -174,14 +176,15 @@
|
|
|
174
176
|
"title": "Delivery Fault Sensor",
|
|
175
177
|
"type": "boolean",
|
|
176
178
|
"default": true,
|
|
177
|
-
"description": "Adds a contact sensor to HomeKit. It opens when an alert could not be delivered for two minutes,
|
|
179
|
+
"description": "Adds a contact sensor to HomeKit that opens when a page is not going out, so HomeKit can tell you that nobody may have been paged. It opens at once when PagerDuty rejects an event, when an alert could not be delivered for two minutes, and when the signal store has been unreadable for five minutes."
|
|
178
180
|
},
|
|
179
181
|
"deliveryFaultSensorName": {
|
|
180
182
|
"title": "Sensor Name",
|
|
181
183
|
"type": "string",
|
|
182
184
|
"default": "PagerDuty Delivery",
|
|
183
185
|
"maxLength": 64,
|
|
184
|
-
"
|
|
186
|
+
"pattern": "^[A-Za-z0-9\\u00AA-\\uFFFF](?:[A-Za-z0-9\\u00AA-\\uFFFF '&!._:;()/,-]*[A-Za-z0-9\\u00AA-\\uFFFF])?$",
|
|
187
|
+
"description": "The name that HomeKit shows. Start and end it with a letter or digit. You can rename it at any time, and it keeps its room and automations."
|
|
185
188
|
},
|
|
186
189
|
"dryRun": {
|
|
187
190
|
"title": "Dry Run",
|
package/dist/controller.d.ts
CHANGED
|
@@ -55,6 +55,12 @@ export declare class AlertController {
|
|
|
55
55
|
private readonly catalogListeners;
|
|
56
56
|
private readonly abort;
|
|
57
57
|
private readonly knownForeignWriters;
|
|
58
|
+
/** Plugins already named for writing an `updated_at` that is not Unix milliseconds. */
|
|
59
|
+
private readonly knownBadClocks;
|
|
60
|
+
/** When each target's recent triggers were accepted, oldest first. In memory only. */
|
|
61
|
+
private readonly recentTriggers;
|
|
62
|
+
/** Damped targets already named in the log. */
|
|
63
|
+
private readonly dampedWarned;
|
|
58
64
|
private readonly outageGapKeys;
|
|
59
65
|
private state;
|
|
60
66
|
private plan;
|
|
@@ -63,7 +69,8 @@ export declare class AlertController {
|
|
|
63
69
|
private reader;
|
|
64
70
|
private storeUnreadableSince;
|
|
65
71
|
private catalog;
|
|
66
|
-
|
|
72
|
+
/** Plugin, signal, and severity. A new summary does not refresh the settings screen. */
|
|
73
|
+
private catalogStamp;
|
|
67
74
|
private lastStoreWarnAt;
|
|
68
75
|
private pendingRowSweep;
|
|
69
76
|
private started;
|
|
@@ -105,6 +112,17 @@ export declare class AlertController {
|
|
|
105
112
|
private recordRejected;
|
|
106
113
|
/** Alerts that had an unsent trigger during the outage and are now closed with nothing delivered. */
|
|
107
114
|
private countSuperseded;
|
|
115
|
+
/** Targets that sent {@link FLAP_MAX_TRIGGERS} triggers within the window. Forgets older triggers. */
|
|
116
|
+
private dampedKeys;
|
|
117
|
+
/** When a damped target's count falls below the limit: its oldest counted trigger leaves the window. */
|
|
118
|
+
private dampingEndsAt;
|
|
119
|
+
/**
|
|
120
|
+
* Warn once per spell of damping, and wake the sender when the first one
|
|
121
|
+
* ends. A spell lasts until the target's window clears, not until its held
|
|
122
|
+
* trigger goes away: a flapping alert closes and reopens within one spell,
|
|
123
|
+
* and must not warn each time.
|
|
124
|
+
*/
|
|
125
|
+
private noteDamping;
|
|
108
126
|
private handleDeadlines;
|
|
109
127
|
private scheduleDeadline;
|
|
110
128
|
private updateFault;
|
|
@@ -122,11 +140,23 @@ export declare class AlertController {
|
|
|
122
140
|
* untrusted.
|
|
123
141
|
*/
|
|
124
142
|
signalCatalog(): readonly CatalogEntry[] | undefined;
|
|
125
|
-
/** Called when a plugin or signal appears
|
|
143
|
+
/** Called when a plugin or signal appears or leaves, or a signal's severity changes. */
|
|
126
144
|
onCatalogChange(listener: () => void): void;
|
|
127
145
|
private pollSignals;
|
|
128
146
|
private updateCatalog;
|
|
129
147
|
private applySignalRows;
|
|
148
|
+
/**
|
|
149
|
+
* Switches a row change sets: every configured switch, plus a held switch
|
|
150
|
+
* that still has saved state, which keeps following its row as before.
|
|
151
|
+
*/
|
|
152
|
+
private drivenSwitches;
|
|
153
|
+
/** Name each plugin once whose `updated_at` had to be replaced by the clock. */
|
|
154
|
+
private reportBadClocks;
|
|
155
|
+
/**
|
|
156
|
+
* A busy store is routine and logs at debug, until it has been busy long
|
|
157
|
+
* enough to open the delivery sensor. Then it warns like any other cause, so
|
|
158
|
+
* the sensor never opens without a line that says why.
|
|
159
|
+
*/
|
|
130
160
|
private noteStoreUnavailable;
|
|
131
161
|
private noteStoreAvailable;
|
|
132
162
|
private warnAboutKeyChange;
|
package/dist/controller.js
CHANGED
|
@@ -31,7 +31,7 @@ const reconcile_1 = require("./state/reconcile");
|
|
|
31
31
|
const store_1 = require("./state/store");
|
|
32
32
|
const errors_1 = require("./utils/errors");
|
|
33
33
|
const redact_1 = require("./utils/redact");
|
|
34
|
-
const EMPTY_PLAN = { sendable: [], heldByMaintenance: [], rejected: [] };
|
|
34
|
+
const EMPTY_PLAN = { sendable: [], heldByMaintenance: [], damped: [], rejected: [] };
|
|
35
35
|
/** Owns desired and delivered state and keeps PagerDuty in line with it. */
|
|
36
36
|
class AlertController {
|
|
37
37
|
options;
|
|
@@ -49,6 +49,12 @@ class AlertController {
|
|
|
49
49
|
catalogListeners = [];
|
|
50
50
|
abort = new AbortController();
|
|
51
51
|
knownForeignWriters = new Set();
|
|
52
|
+
/** Plugins already named for writing an `updated_at` that is not Unix milliseconds. */
|
|
53
|
+
knownBadClocks = new Set();
|
|
54
|
+
/** When each target's recent triggers were accepted, oldest first. In memory only. */
|
|
55
|
+
recentTriggers = new Map();
|
|
56
|
+
/** Damped targets already named in the log. */
|
|
57
|
+
dampedWarned = new Set();
|
|
52
58
|
outageGapKeys = new Set();
|
|
53
59
|
state;
|
|
54
60
|
plan = EMPTY_PLAN;
|
|
@@ -57,7 +63,8 @@ class AlertController {
|
|
|
57
63
|
reader;
|
|
58
64
|
storeUnreadableSince = null;
|
|
59
65
|
catalog;
|
|
60
|
-
|
|
66
|
+
/** Plugin, signal, and severity. A new summary does not refresh the settings screen. */
|
|
67
|
+
catalogStamp = '';
|
|
61
68
|
lastStoreWarnAt = 0;
|
|
62
69
|
pendingRowSweep = false;
|
|
63
70
|
started = false;
|
|
@@ -112,7 +119,11 @@ class AlertController {
|
|
|
112
119
|
this.pendingRowSweep = this.allowed.length > 0;
|
|
113
120
|
this.retainSweep();
|
|
114
121
|
}
|
|
115
|
-
(0, mutations_1.pruneSignals)(state, {
|
|
122
|
+
(0, mutations_1.pruneSignals)(state, {
|
|
123
|
+
allowed: this.allowed,
|
|
124
|
+
switches: new Set(this.switches.keys()),
|
|
125
|
+
held: (refKey) => (0, config_1.isSwitchHeld)(this.config, refKey),
|
|
126
|
+
});
|
|
116
127
|
this.forgetRemovedAlerts();
|
|
117
128
|
if (state.maintenance.on && !this.config.maintenance.switch) {
|
|
118
129
|
(0, mutations_1.applyMaintenance)(state, { on: false, at: this.now(), maxMinutes: this.config.maintenance.maxMinutes });
|
|
@@ -132,6 +143,7 @@ class AlertController {
|
|
|
132
143
|
clearTimeout(this.timers.deadline);
|
|
133
144
|
clearInterval(this.timers.poll);
|
|
134
145
|
clearInterval(this.timers.health);
|
|
146
|
+
clearTimeout(this.timers.damping);
|
|
135
147
|
this.abort.abort();
|
|
136
148
|
await this.sender.stop();
|
|
137
149
|
this.reader?.close();
|
|
@@ -211,6 +223,7 @@ class AlertController {
|
|
|
211
223
|
openAlerts: Object.keys(this.requireState().delivered).length,
|
|
212
224
|
pending: this.plan.sendable.length,
|
|
213
225
|
heldByMaintenance: this.plan.heldByMaintenance.length,
|
|
226
|
+
damped: this.plan.damped.length,
|
|
214
227
|
rejected: this.plan.rejected.length,
|
|
215
228
|
deliveryFault: this.fault,
|
|
216
229
|
storeOk: this.allowed.length === 0 ? null : this.storeUnreadableSince === null,
|
|
@@ -225,11 +238,14 @@ class AlertController {
|
|
|
225
238
|
}
|
|
226
239
|
reconcileNow() {
|
|
227
240
|
const state = this.requireState();
|
|
241
|
+
const now = this.now();
|
|
242
|
+
const damped = this.dampedKeys(now);
|
|
228
243
|
const plan = (0, reconcile_1.reconcile)({
|
|
229
244
|
desired: (0, desired_1.computeDesired)(this.config, state),
|
|
230
245
|
delivered: state.delivered,
|
|
231
246
|
rejected: state.rejected,
|
|
232
247
|
maintenanceOn: state.maintenance.on,
|
|
248
|
+
damped,
|
|
233
249
|
hashContext: {
|
|
234
250
|
routingKeyFingerprint: state.routingKeyFingerprint ?? '',
|
|
235
251
|
region: this.config.region,
|
|
@@ -237,7 +253,8 @@ class AlertController {
|
|
|
237
253
|
},
|
|
238
254
|
});
|
|
239
255
|
this.pruneRejections(plan);
|
|
240
|
-
this.
|
|
256
|
+
this.noteDamping(plan, damped, now);
|
|
257
|
+
this.health.observe(plan, now);
|
|
241
258
|
if (this.sender.inOutage) {
|
|
242
259
|
for (const action of plan.sendable) {
|
|
243
260
|
if (action.kind === 'trigger') {
|
|
@@ -282,6 +299,7 @@ class AlertController {
|
|
|
282
299
|
recordDelivered(action) {
|
|
283
300
|
const state = this.requireState();
|
|
284
301
|
if (action.kind === 'trigger') {
|
|
302
|
+
this.recentTriggers.set(action.key, [...(this.recentTriggers.get(action.key) ?? []), this.now()]);
|
|
285
303
|
const existing = state.delivered[action.key];
|
|
286
304
|
state.delivered[action.key] = {
|
|
287
305
|
dedupKey: action.dedupKey,
|
|
@@ -317,6 +335,58 @@ class AlertController {
|
|
|
317
335
|
this.outageGapKeys.clear();
|
|
318
336
|
return count;
|
|
319
337
|
}
|
|
338
|
+
// --- Flap damping ----------------------------------------------------------------
|
|
339
|
+
/** Targets that sent {@link FLAP_MAX_TRIGGERS} triggers within the window. Forgets older triggers. */
|
|
340
|
+
dampedKeys(now) {
|
|
341
|
+
const damped = new Set();
|
|
342
|
+
for (const [key, times] of this.recentTriggers) {
|
|
343
|
+
const recent = times.filter((time) => now - time < settings_1.FLAP_WINDOW_MS);
|
|
344
|
+
if (recent.length === 0) {
|
|
345
|
+
this.recentTriggers.delete(key);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
this.recentTriggers.set(key, recent);
|
|
349
|
+
if (recent.length >= settings_1.FLAP_MAX_TRIGGERS) {
|
|
350
|
+
damped.add(key);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return damped;
|
|
354
|
+
}
|
|
355
|
+
/** When a damped target's count falls below the limit: its oldest counted trigger leaves the window. */
|
|
356
|
+
dampingEndsAt(key) {
|
|
357
|
+
const times = this.recentTriggers.get(key) ?? [];
|
|
358
|
+
return (times[times.length - settings_1.FLAP_MAX_TRIGGERS] ?? 0) + settings_1.FLAP_WINDOW_MS;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Warn once per spell of damping, and wake the sender when the first one
|
|
362
|
+
* ends. A spell lasts until the target's window clears, not until its held
|
|
363
|
+
* trigger goes away: a flapping alert closes and reopens within one spell,
|
|
364
|
+
* and must not warn each time.
|
|
365
|
+
*/
|
|
366
|
+
noteDamping(plan, damped, now) {
|
|
367
|
+
for (const key of this.dampedWarned) {
|
|
368
|
+
if (!damped.has(key)) {
|
|
369
|
+
this.dampedWarned.delete(key);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
let soonest;
|
|
373
|
+
for (const key of plan.damped) {
|
|
374
|
+
const endsAt = this.dampingEndsAt(key);
|
|
375
|
+
soonest = Math.min(soonest ?? endsAt, endsAt);
|
|
376
|
+
if (!this.dampedWarned.has(key)) {
|
|
377
|
+
this.dampedWarned.add(key);
|
|
378
|
+
const minutes = Math.max(1, Math.ceil((endsAt - now) / 60_000));
|
|
379
|
+
this.log.warn(`${(0, redact_1.forLog)(this.labelFor(key))}: ${settings_1.FLAP_MAX_TRIGGERS} triggers in ${settings_1.FLAP_WINDOW_MS / 60_000} min; `
|
|
380
|
+
+ `holding new triggers for up to ${minutes} min, then sending the current state. Resolves still go out`);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
clearTimeout(this.timers.damping);
|
|
384
|
+
this.timers.damping = undefined;
|
|
385
|
+
if (soonest !== undefined && !this.stopped) {
|
|
386
|
+
this.timers.damping = setTimeout(() => this.kick(), Math.max(0, soonest - now));
|
|
387
|
+
this.timers.damping.unref();
|
|
388
|
+
}
|
|
389
|
+
}
|
|
320
390
|
// --- Timers --------------------------------------------------------------------
|
|
321
391
|
handleDeadlines() {
|
|
322
392
|
const state = this.requireState();
|
|
@@ -412,7 +482,7 @@ class AlertController {
|
|
|
412
482
|
signalCatalog() {
|
|
413
483
|
return this.catalog;
|
|
414
484
|
}
|
|
415
|
-
/** Called when a plugin or signal appears
|
|
485
|
+
/** Called when a plugin or signal appears or leaves, or a signal's severity changes. */
|
|
416
486
|
onCatalogChange(listener) {
|
|
417
487
|
this.catalogListeners.push(listener);
|
|
418
488
|
}
|
|
@@ -441,11 +511,11 @@ class AlertController {
|
|
|
441
511
|
}
|
|
442
512
|
updateCatalog(catalog) {
|
|
443
513
|
this.catalog = catalog;
|
|
444
|
-
const
|
|
445
|
-
if (
|
|
514
|
+
const stamp = catalog.map((entry) => `${(0, schema_1.signalRefKey)(entry)} ${entry.severity}`).join('\n');
|
|
515
|
+
if (stamp === this.catalogStamp) {
|
|
446
516
|
return;
|
|
447
517
|
}
|
|
448
|
-
this.
|
|
518
|
+
this.catalogStamp = stamp;
|
|
449
519
|
for (const listener of this.catalogListeners) {
|
|
450
520
|
try {
|
|
451
521
|
listener();
|
|
@@ -457,7 +527,8 @@ class AlertController {
|
|
|
457
527
|
}
|
|
458
528
|
applySignalRows(result) {
|
|
459
529
|
for (const entry of result.catalog) {
|
|
460
|
-
|
|
530
|
+
const named = this.knownForeignWriters.has(entry.plugin) || (0, config_1.isSignalHeld)(this.config, (0, schema_1.signalRefKey)(entry));
|
|
531
|
+
if (!this.allowed.includes(entry.plugin) && !named) {
|
|
461
532
|
this.knownForeignWriters.add(entry.plugin);
|
|
462
533
|
this.log.info(`signal store: ${(0, redact_1.forLog)(entry.plugin)} writes signals; allow it under Plugin Signals to page for it`);
|
|
463
534
|
}
|
|
@@ -473,9 +544,10 @@ class AlertController {
|
|
|
473
544
|
rows: result.rows,
|
|
474
545
|
complete: result.complete,
|
|
475
546
|
allowed: this.allowed,
|
|
476
|
-
switches:
|
|
547
|
+
switches: this.drivenSwitches(state),
|
|
477
548
|
now: this.now(),
|
|
478
549
|
});
|
|
550
|
+
this.reportBadClocks(applied.timeOutOfRange);
|
|
479
551
|
const swept = this.pendingRowSweep && this.sweepClosedRows();
|
|
480
552
|
this.pendingRowSweep = false;
|
|
481
553
|
if (swept) {
|
|
@@ -489,11 +561,35 @@ class AlertController {
|
|
|
489
561
|
this.kick();
|
|
490
562
|
}
|
|
491
563
|
}
|
|
564
|
+
/**
|
|
565
|
+
* Switches a row change sets: every configured switch, plus a held switch
|
|
566
|
+
* that still has saved state, which keeps following its row as before.
|
|
567
|
+
*/
|
|
568
|
+
drivenSwitches(state) {
|
|
569
|
+
const held = Object.keys(state.switches).filter((refKey) => (0, config_1.isSwitchHeld)(this.config, refKey));
|
|
570
|
+
return new Set([...this.switches.keys(), ...held]);
|
|
571
|
+
}
|
|
572
|
+
/** Name each plugin once whose `updated_at` had to be replaced by the clock. */
|
|
573
|
+
reportBadClocks(refKeys) {
|
|
574
|
+
for (const key of refKeys) {
|
|
575
|
+
const plugin = key.slice(0, key.lastIndexOf('/'));
|
|
576
|
+
if (!this.knownBadClocks.has(plugin)) {
|
|
577
|
+
this.knownBadClocks.add(plugin);
|
|
578
|
+
this.log.info(`signal store: ${(0, redact_1.forLog)(plugin)} wrote an updated_at that is not a time in Unix milliseconds; using the time it was read`);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* A busy store is routine and logs at debug, until it has been busy long
|
|
584
|
+
* enough to open the delivery sensor. Then it warns like any other cause, so
|
|
585
|
+
* the sensor never opens without a line that says why.
|
|
586
|
+
*/
|
|
492
587
|
noteStoreUnavailable(reason) {
|
|
493
588
|
const now = this.now();
|
|
494
589
|
this.storeUnreadableSince ??= now;
|
|
495
590
|
const line = `signal store unavailable (${reason}); keeping the last rows read`;
|
|
496
|
-
|
|
591
|
+
const quietBusy = reason === 'busy' && now - this.storeUnreadableSince < settings_1.SIGNAL_STORE_FAULT_AFTER_MS;
|
|
592
|
+
if (!quietBusy && now - this.lastStoreWarnAt >= settings_1.OUTAGE_REWARN_MS) {
|
|
497
593
|
this.lastStoreWarnAt = now;
|
|
498
594
|
this.log.warn(line);
|
|
499
595
|
}
|
|
@@ -549,7 +645,7 @@ class AlertController {
|
|
|
549
645
|
const desired = (0, desired_1.computeDesired)(this.config, state);
|
|
550
646
|
let swept = false;
|
|
551
647
|
for (const target of desired.values()) {
|
|
552
|
-
if (target.key.startsWith(
|
|
648
|
+
if (target.key.startsWith(model_1.SIGNAL_TARGET_PREFIX) && !target.open && !target.held && state.delivered[target.key] === undefined) {
|
|
553
649
|
state.delivered[target.key] = { dedupKey: target.dedupKey, severity: 'info', openedAt: this.now() };
|
|
554
650
|
swept = true;
|
|
555
651
|
}
|
|
@@ -39,13 +39,16 @@ export declare function buildEvent(action: Action, input: {
|
|
|
39
39
|
source: string;
|
|
40
40
|
}): TriggerEvent | ResolveEvent;
|
|
41
41
|
/** How the sender treats a response status. */
|
|
42
|
-
export type StatusClass = 'delivered' | 'rejected' | 'rateLimited' | 'retry';
|
|
42
|
+
export type StatusClass = 'delivered' | 'rejected' | 'rateLimited' | 'refused' | 'retry';
|
|
43
43
|
/**
|
|
44
44
|
* Classify a status.
|
|
45
45
|
*
|
|
46
|
-
* `2xx` is delivered (anything but `202` also warns). `
|
|
47
|
-
*
|
|
48
|
-
*
|
|
46
|
+
* `2xx` is delivered (anything but `202` also warns). `400`, `413` and `422`
|
|
47
|
+
* reject the event, and no retry will change that. `408` and `429` wait
|
|
48
|
+
* minutes. Any other `4xx` is not something PagerDuty documents. It more
|
|
49
|
+
* likely comes from a proxy or an edge in front of PagerDuty than from the
|
|
50
|
+
* event, so it is retried on the same slow backoff as a rate limit rather than
|
|
51
|
+
* dropped. `3xx` (never followed), `5xx` and anything odd are retried.
|
|
49
52
|
*/
|
|
50
53
|
export declare function classifyStatus(status: number): StatusClass;
|
|
51
54
|
/**
|
package/dist/delivery/events.js
CHANGED
|
@@ -39,22 +39,34 @@ function buildEvent(action, input) {
|
|
|
39
39
|
},
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Statuses that say the event itself is wrong, so sending the same body again
|
|
44
|
+
* cannot help. PagerDuty documents only `400`; `413` and `422` say the same
|
|
45
|
+
* thing about the body.
|
|
46
|
+
*/
|
|
47
|
+
const EVENT_REJECTED = new Set([400, 413, 422]);
|
|
42
48
|
/**
|
|
43
49
|
* Classify a status.
|
|
44
50
|
*
|
|
45
|
-
* `2xx` is delivered (anything but `202` also warns). `
|
|
46
|
-
*
|
|
47
|
-
*
|
|
51
|
+
* `2xx` is delivered (anything but `202` also warns). `400`, `413` and `422`
|
|
52
|
+
* reject the event, and no retry will change that. `408` and `429` wait
|
|
53
|
+
* minutes. Any other `4xx` is not something PagerDuty documents. It more
|
|
54
|
+
* likely comes from a proxy or an edge in front of PagerDuty than from the
|
|
55
|
+
* event, so it is retried on the same slow backoff as a rate limit rather than
|
|
56
|
+
* dropped. `3xx` (never followed), `5xx` and anything odd are retried.
|
|
48
57
|
*/
|
|
49
58
|
function classifyStatus(status) {
|
|
50
59
|
if (status >= 200 && status < 300) {
|
|
51
60
|
return 'delivered';
|
|
52
61
|
}
|
|
62
|
+
if (EVENT_REJECTED.has(status)) {
|
|
63
|
+
return 'rejected';
|
|
64
|
+
}
|
|
53
65
|
if (status === 408 || status === 429) {
|
|
54
66
|
return 'rateLimited';
|
|
55
67
|
}
|
|
56
68
|
if (status >= 400 && status < 500) {
|
|
57
|
-
return '
|
|
69
|
+
return 'refused';
|
|
58
70
|
}
|
|
59
71
|
return 'retry';
|
|
60
72
|
}
|
|
@@ -34,10 +34,4 @@ export declare class DeliveryHealth {
|
|
|
34
34
|
now: number;
|
|
35
35
|
storeUnreadableSince: number | null;
|
|
36
36
|
}): DeliveryFaultCause[];
|
|
37
|
-
/** True when {@link causes} is not empty. */
|
|
38
|
-
isFault(input: {
|
|
39
|
-
plan: Plan;
|
|
40
|
-
now: number;
|
|
41
|
-
storeUnreadableSince: number | null;
|
|
42
|
-
}): boolean;
|
|
43
37
|
}
|
package/dist/delivery/health.js
CHANGED
|
@@ -65,12 +65,23 @@ export declare class Sender {
|
|
|
65
65
|
get inOutage(): boolean;
|
|
66
66
|
/** Something may have changed. Never cuts a backoff short. */
|
|
67
67
|
wake(): void;
|
|
68
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Stop sending. Nothing new starts, and a backoff is cut short. This does
|
|
70
|
+
* not cancel a request in flight: the controller aborts it, and an answer
|
|
71
|
+
* that still arrives is recorded as usual.
|
|
72
|
+
*/
|
|
69
73
|
stop(): Promise<void>;
|
|
70
74
|
private run;
|
|
71
75
|
/** Send one action and return how long to wait before the next. */
|
|
72
76
|
private attempt;
|
|
73
77
|
private logDelivered;
|
|
78
|
+
/**
|
|
79
|
+
* Record a failed attempt and return the wait before the next one.
|
|
80
|
+
*
|
|
81
|
+
* `fast` is a network or server failure: full jitter from 5 seconds. A rate
|
|
82
|
+
* limit, and a `4xx` that PagerDuty does not document, wait minutes, with
|
|
83
|
+
* equal jitter and any `Retry-After` honoured.
|
|
84
|
+
*/
|
|
74
85
|
private failed;
|
|
75
86
|
private recovered;
|
|
76
87
|
}
|
package/dist/delivery/sender.js
CHANGED
|
@@ -25,6 +25,12 @@ const redact_1 = require("../utils/redact");
|
|
|
25
25
|
const retry_after_1 = require("../utils/retry-after");
|
|
26
26
|
const timing_1 = require("../utils/timing");
|
|
27
27
|
const events_1 = require("./events");
|
|
28
|
+
/** How each kind of failure reads in the outage line. */
|
|
29
|
+
const FAILURE_WORDS = {
|
|
30
|
+
fast: 'is not reachable',
|
|
31
|
+
rateLimited: 'is rate limiting events',
|
|
32
|
+
refused: 'refused the request',
|
|
33
|
+
};
|
|
28
34
|
/** Equal jitter: at least half the window, so a `429` never retries at once. */
|
|
29
35
|
function equalJitterDelayMs(input) {
|
|
30
36
|
const exponent = Math.min(Math.max(input.attempt - 1, 0), 16);
|
|
@@ -67,7 +73,11 @@ class Sender {
|
|
|
67
73
|
this.loop = this.run();
|
|
68
74
|
}
|
|
69
75
|
}
|
|
70
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Stop sending. Nothing new starts, and a backoff is cut short. This does
|
|
78
|
+
* not cancel a request in flight: the controller aborts it, and an answer
|
|
79
|
+
* that still arrives is recorded as usual.
|
|
80
|
+
*/
|
|
71
81
|
async stop() {
|
|
72
82
|
this.stopped = true;
|
|
73
83
|
this.backoff?.interrupt();
|
|
@@ -107,8 +117,13 @@ class Sender {
|
|
|
107
117
|
response = await this.deps.post(action);
|
|
108
118
|
}
|
|
109
119
|
catch (error) {
|
|
120
|
+
if (this.stopped) {
|
|
121
|
+
// Aborted by shutdown. PagerDuty was not unreachable, so say nothing
|
|
122
|
+
// and count nothing; the next start sends whatever is still due.
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
110
125
|
this.deps.onRequest?.(this.now() - started, false);
|
|
111
|
-
return this.failed(action, { detail: (0, errors_1.describeError)(error),
|
|
126
|
+
return this.failed(action, { detail: (0, errors_1.describeError)(error), backoff: 'fast' });
|
|
112
127
|
}
|
|
113
128
|
const outcome = (0, events_1.classifyStatus)(response.status);
|
|
114
129
|
this.deps.onRequest?.(this.now() - started, outcome === 'delivered');
|
|
@@ -123,13 +138,14 @@ class Sender {
|
|
|
123
138
|
this.deps.onRejected(action, (0, events_1.rejectionReason)(response.status, response.body));
|
|
124
139
|
return 0;
|
|
125
140
|
case 'rateLimited':
|
|
141
|
+
case 'refused':
|
|
126
142
|
return this.failed(action, {
|
|
127
143
|
detail: `HTTP ${response.status}`,
|
|
128
|
-
|
|
144
|
+
backoff: outcome,
|
|
129
145
|
retryAfterMs: (0, retry_after_1.parseRetryAfterMs)(response.headers['retry-after'], settings_1.MAX_RETRY_AFTER_MS, this.now),
|
|
130
146
|
});
|
|
131
147
|
default:
|
|
132
|
-
return this.failed(action, { detail: `HTTP ${response.status}`,
|
|
148
|
+
return this.failed(action, { detail: `HTTP ${response.status}`, backoff: 'fast' });
|
|
133
149
|
}
|
|
134
150
|
}
|
|
135
151
|
logDelivered(action, status) {
|
|
@@ -139,21 +155,28 @@ class Sender {
|
|
|
139
155
|
this.deps.log.warn(`PagerDuty answered ${status} rather than 202; treated as accepted`);
|
|
140
156
|
}
|
|
141
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Record a failed attempt and return the wait before the next one.
|
|
160
|
+
*
|
|
161
|
+
* `fast` is a network or server failure: full jitter from 5 seconds. A rate
|
|
162
|
+
* limit, and a `4xx` that PagerDuty does not document, wait minutes, with
|
|
163
|
+
* equal jitter and any `Retry-After` honoured.
|
|
164
|
+
*/
|
|
142
165
|
failed(action, failure) {
|
|
143
166
|
this.failures += 1;
|
|
144
167
|
if (action.kind === 'trigger') {
|
|
145
168
|
this.attemptedDuringOutage.add(action.key);
|
|
146
169
|
}
|
|
147
|
-
const delayMs = failure.
|
|
148
|
-
?
|
|
170
|
+
const delayMs = failure.backoff === 'fast'
|
|
171
|
+
? (0, timing_1.backoffDelayMs)({ attempt: this.failures, baseMs: settings_1.BACKOFF_BASE_MS, maxMs: settings_1.BACKOFF_MAX_MS, random: this.random })
|
|
172
|
+
: Math.max(failure.retryAfterMs ?? 0, equalJitterDelayMs({
|
|
149
173
|
attempt: this.failures,
|
|
150
174
|
baseMs: settings_1.RATE_LIMIT_BACKOFF_BASE_MS,
|
|
151
175
|
maxMs: settings_1.BACKOFF_MAX_MS,
|
|
152
176
|
random: this.random,
|
|
153
|
-
}))
|
|
154
|
-
: (0, timing_1.backoffDelayMs)({ attempt: this.failures, baseMs: settings_1.BACKOFF_BASE_MS, maxMs: settings_1.BACKOFF_MAX_MS, random: this.random });
|
|
177
|
+
}));
|
|
155
178
|
const now = this.now();
|
|
156
|
-
const what = failure.
|
|
179
|
+
const what = FAILURE_WORDS[failure.backoff];
|
|
157
180
|
const line = `PagerDuty ${what} (${failure.detail}); retrying in ${Math.round(delayMs / 1_000)}s`;
|
|
158
181
|
if (this.outageSince === null || now - this.lastOutageWarnAt >= settings_1.OUTAGE_REWARN_MS) {
|
|
159
182
|
this.outageSince ??= now;
|
|
@@ -53,7 +53,7 @@ class BaseAccessory {
|
|
|
53
53
|
/** Throw the HAP error that shows No Response when unavailable. */
|
|
54
54
|
requireAvailable() {
|
|
55
55
|
if (this.unavailable) {
|
|
56
|
-
throw new this.host.api.hap.HapStatusError(
|
|
56
|
+
throw new this.host.api.hap.HapStatusError(this.host.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* @fileoverview Opt-in diagnostics collector.
|
|
8
8
|
*
|
|
9
9
|
* It reads only in-memory state through `readGauges`; it never touches the
|
|
10
|
-
* network
|
|
10
|
+
* network. The config it echoes is the validated one, so the echo shows what
|
|
11
|
+
* is running rather than what was typed, and the routing key appears only as
|
|
12
|
+
* present.
|
|
11
13
|
*/
|
|
12
|
-
import type { DeliveryGauges, DiagnosticsSnapshot,
|
|
14
|
+
import type { DeliveryGauges, DiagnosticsSnapshot, ResolvedConfig } from '../types';
|
|
13
15
|
/** Health classification result. */
|
|
14
16
|
export interface HealthRollup {
|
|
15
17
|
health: 'healthy' | 'degraded';
|
|
@@ -17,7 +19,7 @@ export interface HealthRollup {
|
|
|
17
19
|
}
|
|
18
20
|
interface CollectorOptions {
|
|
19
21
|
pluginVersion: string;
|
|
20
|
-
config:
|
|
22
|
+
config: ResolvedConfig;
|
|
21
23
|
now?: () => number;
|
|
22
24
|
}
|
|
23
25
|
/** Accumulates diagnostics counters and renders heartbeat and snapshot reports. */
|