@voltro/plugin-prometheus 0.33.0 → 0.34.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.
Files changed (3) hide show
  1. package/CHANGELOG.md +1801 -0
  2. package/dist/index.js +36 -33
  3. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,40 +1,40 @@
1
1
  import { Effect as e } from "effect";
2
- import { definePlugin as t } from "@voltro/protocol";
3
- import { checkBearer as n } from "@voltro/protocol/session";
4
- import { snapshotMetrics as r } from "@voltro/runtime";
5
- import { pluginEnv as i } from "@voltro/env";
2
+ import { definePlugin as t, pluginInstanceName as n } from "@voltro/protocol";
3
+ import { checkBearer as r } from "@voltro/protocol/session";
4
+ import { snapshotMetrics as i } from "@voltro/runtime";
5
+ import { pluginEnv as a } from "@voltro/env";
6
6
  //#region src/format.ts
7
- var a = (e) => e.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/"/g, "\\\""), o = (e, t) => {
7
+ var o = (e) => e.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/"/g, "\\\""), s = (e, t) => {
8
8
  let n = {
9
9
  ...e,
10
10
  ...t
11
11
  }, r = Object.keys(n);
12
- return r.length === 0 ? "" : "{" + r.map((e) => `${e}="${a(String(n[e]))}"`).join(",") + "}";
13
- }, s = (e) => Number.isFinite(e) ? String(e) : e > 0 ? "+Inf" : "-Inf", c = {
12
+ return r.length === 0 ? "" : "{" + r.map((e) => `${e}="${o(String(n[e]))}"`).join(",") + "}";
13
+ }, c = (e) => Number.isFinite(e) ? String(e) : e > 0 ? "+Inf" : "-Inf", l = {
14
14
  counter: "counter",
15
15
  gauge: "gauge",
16
16
  histogram: "histogram",
17
17
  summary: "summary",
18
18
  frequency: "gauge"
19
- }, l = (e, t) => {
19
+ }, u = (e, t) => {
20
20
  switch (e.type) {
21
21
  case "counter":
22
22
  case "gauge":
23
- t.push(`${e.name}${o(e.labels)} ${s(e.value ?? 0)}`);
23
+ t.push(`${e.name}${s(e.labels)} ${c(e.value ?? 0)}`);
24
24
  break;
25
25
  case "histogram":
26
- for (let n of e.buckets ?? []) t.push(`${e.name}_bucket${o(e.labels, { le: s(n.le) })} ${s(n.count)}`);
27
- t.push(`${e.name}_bucket${o(e.labels, { le: "+Inf" })} ${s(e.count ?? 0)}`), t.push(`${e.name}_sum${o(e.labels)} ${s(e.sum ?? 0)}`), t.push(`${e.name}_count${o(e.labels)} ${s(e.count ?? 0)}`);
26
+ for (let n of e.buckets ?? []) t.push(`${e.name}_bucket${s(e.labels, { le: c(n.le) })} ${c(n.count)}`);
27
+ t.push(`${e.name}_bucket${s(e.labels, { le: "+Inf" })} ${c(e.count ?? 0)}`), t.push(`${e.name}_sum${s(e.labels)} ${c(e.sum ?? 0)}`), t.push(`${e.name}_count${s(e.labels)} ${c(e.count ?? 0)}`);
28
28
  break;
29
29
  case "summary":
30
- for (let n of e.quantiles ?? []) t.push(`${e.name}${o(e.labels, { quantile: s(n.quantile) })} ${s(n.value)}`);
31
- t.push(`${e.name}_sum${o(e.labels)} ${s(e.sum ?? 0)}`), t.push(`${e.name}_count${o(e.labels)} ${s(e.count ?? 0)}`);
30
+ for (let n of e.quantiles ?? []) t.push(`${e.name}${s(e.labels, { quantile: c(n.quantile) })} ${c(n.value)}`);
31
+ t.push(`${e.name}_sum${s(e.labels)} ${c(e.sum ?? 0)}`), t.push(`${e.name}_count${s(e.labels)} ${c(e.count ?? 0)}`);
32
32
  break;
33
33
  case "frequency":
34
- for (let [n, r] of Object.entries(e.occurrences ?? {})) t.push(`${e.name}${o(e.labels, { bucket: n })} ${s(r)}`);
34
+ for (let [n, r] of Object.entries(e.occurrences ?? {})) t.push(`${e.name}${s(e.labels, { bucket: n })} ${c(r)}`);
35
35
  break;
36
36
  }
37
- }, u = (e) => {
37
+ }, d = (e) => {
38
38
  let t = /* @__PURE__ */ new Map();
39
39
  for (let n of e) {
40
40
  let e = t.get(n.name);
@@ -43,11 +43,11 @@ var a = (e) => e.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/"/g, "\\\
43
43
  let n = [];
44
44
  for (let [e, r] of t) {
45
45
  let t = r[0], i = t.description ?? e;
46
- n.push(`# HELP ${e} ${i.replace(/\\/g, "\\\\").replace(/\n/g, " ")}`), n.push(`# TYPE ${e} ${c[t.type]}`);
47
- for (let e of r) l(e, n);
46
+ n.push(`# HELP ${e} ${i.replace(/\\/g, "\\\\").replace(/\n/g, " ")}`), n.push(`# TYPE ${e} ${l[t.type]}`);
47
+ for (let e of r) u(e, n);
48
48
  }
49
49
  return n.join("\n") + "\n";
50
- }, d = (e) => {
50
+ }, f = (e) => {
51
51
  let t = process.memoryUsage(), n = process.cpuUsage(), r = [
52
52
  {
53
53
  name: "process_resident_memory_bytes",
@@ -78,44 +78,47 @@ var a = (e) => e.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/"/g, "\\\
78
78
  value: 1,
79
79
  description: "Voltro build info (constant 1, version in the label)."
80
80
  }), r;
81
- }, f = "text/plain; version=0.0.4; charset=utf-8", p = i([{
81
+ }, p = "text/plain; version=0.0.4; charset=utf-8", m = a([{
82
82
  name: "PROMETHEUS_TOKEN",
83
83
  required: !1,
84
84
  secret: !0,
85
85
  description: "Bearer token required on the scrape endpoint; unset leaves /metrics open."
86
- }]), m = (i = {}) => {
87
- let a = i.path ?? "/metrics", o = p.read("PROMETHEUS_TOKEN", i.token), s = i.processMetrics ?? !0, c = {
86
+ }]), h = (a = {}) => {
87
+ let o = a.path ?? "/metrics", s = m.read("PROMETHEUS_TOKEN", a.token), c = a.processMetrics ?? !0, l = {
88
88
  method: "GET",
89
- path: a,
89
+ path: o,
90
90
  handle: async (t) => {
91
- if (!n(t.headers, o, { openWhenUnset: !0 })) return {
91
+ if (!r(t.headers, s, { openWhenUnset: !0 })) return {
92
92
  status: 401,
93
93
  body: "unauthorized",
94
94
  contentType: "text/plain"
95
95
  };
96
- let a = await e.runPromise(r);
96
+ let n = await e.runPromise(i);
97
97
  return {
98
98
  status: 200,
99
- body: u(s ? [...a, ...d(i.version)] : a),
100
- contentType: f,
99
+ body: d(c ? [...n, ...f(a.version)] : n),
100
+ contentType: p,
101
101
  headers: { "cache-control": "no-store" }
102
102
  };
103
103
  }
104
104
  };
105
105
  return t({
106
- name: i.name ? `@voltro/plugin-prometheus#${i.name}` : "@voltro/plugin-prometheus",
106
+ name: n({
107
+ base: "@voltro/plugin-prometheus",
108
+ instance: a.name
109
+ }),
107
110
  description: "Prometheus exporter — scrapes the unified Metrics-API at a /metrics endpoint in text exposition format.",
108
- declaredEnv: p.declared,
109
- httpRoutes: [c],
111
+ declaredEnv: m.declared,
112
+ httpRoutes: [l],
110
113
  onActivate: (t) => e.sync(() => {
111
114
  t.logger.info("prometheus exporter active", {
112
- path: a,
113
- tokenGated: !!o,
114
- processMetrics: s
115
+ path: o,
116
+ tokenGated: !!s,
117
+ processMetrics: c
115
118
  });
116
119
  }),
117
120
  onDeactivate: () => e.void
118
121
  });
119
122
  };
120
123
  //#endregion
121
- export { u as formatPrometheus, d as processMetrics, m as prometheusPlugin };
124
+ export { d as formatPrometheus, f as processMetrics, h as prometheusPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltro/plugin-prometheus",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "Prometheus exporter — scrapes the framework's unified Metrics-API (Effect MetricRegistry) at GET /metrics in Prometheus text exposition format. Counters, histograms (with buckets), gauges + custom metrics; optional bearer-token gate + node process metrics.",
5
5
  "keywords": [
6
6
  "voltro",
@@ -33,9 +33,9 @@
33
33
  "node": ">=24.0.0"
34
34
  },
35
35
  "dependencies": {
36
- "@voltro/env": "0.33.0",
37
- "@voltro/protocol": "0.33.0",
38
- "@voltro/runtime": "0.33.0"
36
+ "@voltro/env": "0.34.0",
37
+ "@voltro/protocol": "0.34.0",
38
+ "@voltro/runtime": "0.34.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "effect": "^3.22.0"