@remit/logger-lambda 0.0.15 → 0.0.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/logger-lambda",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "scripts": {
18
18
  "test:typecheck": "tsgo --noEmit",
19
- "test:run": "node --experimental-test-module-mocks --import tsx --experimental-test-coverage --test-coverage-include='src/**' --test-coverage-exclude='src/**/*.test.ts' --test-coverage-exclude='src/**/*.test.tsx' --test-coverage-lines=98 --test 'src/**/*.test.ts'",
19
+ "test:run": "node $NODE_TEST_FLAGS --experimental-test-module-mocks --import tsx --experimental-test-coverage --test-coverage-include='src/**' --test-coverage-exclude='src/**/*.test.ts' --test-coverage-exclude='src/**/*.test.tsx' --test-coverage-lines=98 --test 'src/**/*.test.ts'",
20
20
  "test": "npm run test:typecheck && npm run test:run",
21
21
  "build": "npm run test:typecheck"
22
22
  },
@@ -178,18 +178,33 @@ describe("metrics registry", () => {
178
178
  );
179
179
  });
180
180
 
181
- it("declares no unlabelled series, so no process renders a value it cannot know", async () => {
181
+ it("declares no application series, so no process renders a value it cannot know", async () => {
182
182
  const text = await renderMetrics();
183
183
  const samples = text
184
184
  .split("\n")
185
- .filter((line) => line.length > 0 && !line.startsWith("#"));
185
+ .filter((line) => line.startsWith("remit_"));
186
186
  assert.deepEqual(
187
187
  samples,
188
188
  [],
189
- "a fresh registry must render nothing until something records",
189
+ "a fresh registry must render no remit series until something records",
190
190
  );
191
191
  });
192
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
+
193
208
  it("runs registered collectors before rendering", async () => {
194
209
  let ran = 0;
195
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 { Counter, Gauge, Histogram, Registry } from "prom-client";
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 a series enters it. The registry
16
- * itself is exported for a service that owns a signal of its own shape — the
17
- * queue sidecar's per-queue depth gauges — so the whole process still renders
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