@remit/logger-lambda 0.0.14 → 0.0.16
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/package.json +1 -1
- package/src/metrics.test.ts +18 -4
- package/src/metrics.ts +24 -5
package/package.json
CHANGED
package/src/metrics.test.ts
CHANGED
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
recordImapFailure,
|
|
13
13
|
recordQueueEvent,
|
|
14
14
|
recordSmtpFailure,
|
|
15
|
-
registry,
|
|
16
15
|
renderMetrics,
|
|
17
16
|
resetMetrics,
|
|
18
17
|
setAccountSyncAges,
|
|
@@ -179,18 +178,33 @@ describe("metrics registry", () => {
|
|
|
179
178
|
);
|
|
180
179
|
});
|
|
181
180
|
|
|
182
|
-
it("declares no
|
|
181
|
+
it("declares no application series, so no process renders a value it cannot know", async () => {
|
|
183
182
|
const text = await renderMetrics();
|
|
184
183
|
const samples = text
|
|
185
184
|
.split("\n")
|
|
186
|
-
.filter((line) => line.
|
|
185
|
+
.filter((line) => line.startsWith("remit_"));
|
|
187
186
|
assert.deepEqual(
|
|
188
187
|
samples,
|
|
189
188
|
[],
|
|
190
|
-
"a fresh registry must render
|
|
189
|
+
"a fresh registry must render no remit series until something records",
|
|
191
190
|
);
|
|
192
191
|
});
|
|
193
192
|
|
|
193
|
+
it("reports this process's own memory and event-loop health", async () => {
|
|
194
|
+
const text = await renderMetrics();
|
|
195
|
+
for (const name of [
|
|
196
|
+
"nodejs_heap_size_used_bytes",
|
|
197
|
+
"nodejs_heap_size_total_bytes",
|
|
198
|
+
"nodejs_external_memory_bytes",
|
|
199
|
+
"process_resident_memory_bytes",
|
|
200
|
+
]) {
|
|
201
|
+
assert.match(text, new RegExp(`^# TYPE ${name} gauge$`, "m"));
|
|
202
|
+
assert.ok(sample(text, name) > 0, `${name} rendered no value`);
|
|
203
|
+
}
|
|
204
|
+
assert.match(text, /^# TYPE nodejs_eventloop_lag_seconds gauge$/m);
|
|
205
|
+
assert.ok(sample(text, "nodejs_eventloop_lag_seconds") >= 0);
|
|
206
|
+
});
|
|
207
|
+
|
|
194
208
|
it("runs registered collectors before rendering", async () => {
|
|
195
209
|
let ran = 0;
|
|
196
210
|
onScrape(async () => {
|
package/src/metrics.ts
CHANGED
|
@@ -4,7 +4,13 @@ import {
|
|
|
4
4
|
type Server,
|
|
5
5
|
type ServerResponse,
|
|
6
6
|
} from "node:http";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
Counter,
|
|
9
|
+
collectDefaultMetrics,
|
|
10
|
+
Gauge,
|
|
11
|
+
Histogram,
|
|
12
|
+
Registry,
|
|
13
|
+
} from "prom-client";
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
16
|
* The process-wide metric registry every service renders at `/metrics`
|
|
@@ -12,13 +18,26 @@ import { Counter, Gauge, Histogram, Registry } from "prom-client";
|
|
|
12
18
|
* emitted CloudWatch Embedded Metric Format, which no configuration turns into
|
|
13
19
|
* a scrape endpoint; this registry is what the endpoint renders.
|
|
14
20
|
*
|
|
15
|
-
* The exported recorders are the only way
|
|
16
|
-
* itself is exported for a service that owns a signal of its own shape
|
|
17
|
-
* queue sidecar's per-queue depth gauges — so the whole process still
|
|
18
|
-
* from one registry.
|
|
21
|
+
* The exported recorders are the only way an application series enters it. The
|
|
22
|
+
* registry itself is exported for a service that owns a signal of its own shape
|
|
23
|
+
* — the queue sidecar's per-queue depth gauges — so the whole process still
|
|
24
|
+
* renders from one registry.
|
|
19
25
|
*/
|
|
20
26
|
export const registry = new Registry();
|
|
21
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Heap, resident memory and event-loop lag, read from the process itself. On a
|
|
30
|
+
* self-hosted box memory is the dimension that actually runs out, and nothing
|
|
31
|
+
* else in the deployment reports it.
|
|
32
|
+
*
|
|
33
|
+
* These are unlabelled series present in every service at once, which the
|
|
34
|
+
* application gauges deliberately avoid. A process always knows its own heap,
|
|
35
|
+
* so the value is right in all of them and `instance` tells them apart; a
|
|
36
|
+
* backlog or a queue depth would be a confident zero everywhere it is not
|
|
37
|
+
* computed.
|
|
38
|
+
*/
|
|
39
|
+
collectDefaultMetrics({ register: registry });
|
|
40
|
+
|
|
22
41
|
/** Content type of the exposition format `renderMetrics` produces. */
|
|
23
42
|
export const metricsContentType = registry.contentType;
|
|
24
43
|
|