@getstrata/bootstrap 2.2.7 → 2.2.8

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # @getstrata/bootstrap changelog
2
2
 
3
+ ## 2.2.8
4
+
5
+ - Add bounded read-only Postgres outbox metrics
6
+
3
7
  ## 2.2.7
4
8
 
5
9
  - Where an ordinary operation needs SQL because the framework cannot express it
@@ -1,4 +1,15 @@
1
- declare function createMetricsRoutes(): {
1
+ import { type OutboxMetricsCollector } from "@getstrata/core/events/outbox";
2
+ import { type RedisQueueSnapshotOptions } from "@getstrata/core/queue/queueMetrics";
3
+ interface MetricsRoutesOptions {
4
+ /** Opt in to shared Redis queue observations; no database or failed-job scan. */
5
+ queue?: RedisQueueSnapshotOptions & {
6
+ redisUrl: string;
7
+ };
8
+ /** Explicit platform outbox observation; caller owns collector shutdown. */
9
+ outbox?: Pick<OutboxMetricsCollector, "collect">;
10
+ }
11
+ declare function createMetricsRoutes(options?: MetricsRoutesOptions): {
2
12
  "/metrics": (request: Request) => Promise<Response>;
3
13
  };
14
+ export type { MetricsRoutesOptions };
4
15
  export { createMetricsRoutes };
@@ -1,7 +1,12 @@
1
1
  // @bun
2
2
  // ../../src/bootstrap/metricsRoutes.ts
3
3
  import { timingSafeEqual } from "crypto";
4
+ import { renderOutboxMetrics } from "@getstrata/core/events/outbox";
4
5
  import { prometheusRegistry } from "@getstrata/core/metrics/prometheus";
6
+ import {
7
+ readRedisQueueSnapshot,
8
+ renderRedisQueueMetrics
9
+ } from "@getstrata/core/queue/queueMetrics";
5
10
  import { isProductionEnv } from "@getstrata/core/runtime/appEnv";
6
11
  function tokensMatch(left, right) {
7
12
  const leftBuffer = Buffer.from(left);
@@ -23,16 +28,33 @@ function authorizeMetrics(request) {
23
28
  }
24
29
  return true;
25
30
  }
26
- function createMetricsRoutes() {
31
+ function createMetricsRoutes(options = {}) {
32
+ let collection;
33
+ const collect = () => {
34
+ if (!options.queue && !options.outbox)
35
+ return Promise.resolve("");
36
+ const failure = (name) => `# HELP strata_${name}_collector_success Whether the configured ${name} collection succeeded.
37
+ # TYPE strata_${name}_collector_success gauge
38
+ strata_${name}_collector_success 0
39
+ `;
40
+ collection ??= Promise.all([
41
+ options.queue ? readRedisQueueSnapshot(options.queue.redisUrl, options.queue).then(renderRedisQueueMetrics).catch(() => failure("queue")) : Promise.resolve(""),
42
+ options.outbox ? Promise.resolve().then(() => options.outbox?.collect()).then((snapshot) => snapshot ? renderOutboxMetrics(snapshot) : "").catch(() => failure("outbox")) : Promise.resolve("")
43
+ ]).then((parts) => parts.join("")).finally(() => {
44
+ collection = undefined;
45
+ });
46
+ return collection;
47
+ };
27
48
  return {
28
49
  "/metrics": async (request) => {
29
50
  if (!authorizeMetrics(request)) {
30
51
  return new Response("Not Found", { status: 404 });
31
52
  }
32
- return new Response(prometheusRegistry.renderMetrics(), {
53
+ return new Response(prometheusRegistry.renderMetrics() + await collect(), {
33
54
  status: 200,
34
55
  headers: {
35
- "content-type": "text/plain; version=0.0.4; charset=utf-8"
56
+ "content-type": "text/plain; version=0.0.4; charset=utf-8",
57
+ "cache-control": "no-store"
36
58
  }
37
59
  });
38
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/bootstrap",
3
- "version": "2.2.7",
3
+ "version": "2.2.8",
4
4
  "description": "Strata application bootstrap: HttpKernel, DI, web session helpers",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -190,7 +190,7 @@
190
190
  "access": "public"
191
191
  },
192
192
  "peerDependencies": {
193
- "@getstrata/core": "^2.2.7",
193
+ "@getstrata/core": "^2.2.8",
194
194
  "typescript": "^5.9.0 || ^6.0.0 || ^7.0.0"
195
195
  },
196
196
  "engines": {