Skip to content

Commit aecff85

Browse files
committed
feat(lib-prom): pseudo metric support
1 parent 7bfb34b commit aecff85

File tree

25 files changed

+526
-342
lines changed

25 files changed

+526
-342
lines changed

oada/.yarnrc.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ packageExtensions:
4848
peerDependencies:
4949
"@types/ws": "*"
5050
fastify: "*"
51-
eslint-plugin-sonarjs@*:
52-
dependencies:
53-
"@typescript-eslint/utils": "*"
5451
fastify-graceful-shutdown@*:
5552
peerDependencies:
5653
fastify: "*"

oada/eslint.config.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import typescript from 'typescript-eslint';
3030

3131
import _import from 'eslint-plugin-import';
3232
import ava from 'eslint-plugin-ava';
33-
import github from 'eslint-plugin-github';
3433
import noConstructorBind from 'eslint-plugin-no-constructor-bind';
3534
import noSecrets from 'eslint-plugin-no-secrets';
3635
import node from 'eslint-plugin-n';
@@ -67,7 +66,7 @@ export default typescript.config(
6766
regexp.configs['flat/recommended'],
6867
...fixupConfigRules(
6968
compat.extends(
70-
'plugin:github/recommended',
69+
// 'plugin:github/recommended',
7170
'plugin:promise/recommended',
7271
'plugin:optimize-regex/recommended',
7372
'plugin:import/recommended',
@@ -104,13 +103,13 @@ export default typescript.config(
104103
},
105104
{
106105
plugins: {
107-
'github': fixupPluginRules(github),
106+
// 'github': fixupPluginRules(github),
108107
'promise': fixupPluginRules(promise),
109108
'optimize-regex': fixupPluginRules(optimizeRegex),
110109
'no-constructor-bind': noConstructorBind,
111110
'import': fixupPluginRules(_import),
112111
'no-secrets': noSecrets,
113-
// Sonarjs,
112+
// sonarjs,
114113
'ava': fixupPluginRules(ava),
115114
notice,
116115
},
@@ -323,6 +322,7 @@ export default typescript.config(
323322
'no-dupe-class-members': 'off',
324323
'no-useless-constructor': 'off',
325324
'no-invalid-this': 'off',
325+
'sonarjs/sonar-no-fallthrough': 'off',
326326
'filenames/match-regex': 'off',
327327
'i18n-text/no-en': 'off',
328328
'github/no-implicit-buggy-globals': 'off',

oada/libs/lib-arangodb/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"@oada/models": "workspace:^",
6060
"@oada/oadaify": "^2.1.0",
6161
"@oada/types": "^4.0.0",
62-
"arangojs": "^9.0.0",
62+
"arangojs": "^9.1.0",
6363
"bcryptjs": "^2.4.3",
6464
"debug": "^4.3.7",
6565
"deep-equal": "^2.2.3",
@@ -75,7 +75,7 @@
7575
"@types/deep-equal": "^1.0.4",
7676
"@types/flat": "^5.0.5",
7777
"@types/json-pointer": "^1.0.34",
78-
"@types/node": "^22.5.5",
78+
"@types/node": "^22.7.3",
7979
"ava": "6.1.3",
8080
"type-fest": "^4.26.1"
8181
},

oada/libs/lib-kafka/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"@ava/typescript": "^5.0.0",
4949
"@types/convict": "^6.1.6",
5050
"@types/debug": "^4.1.12",
51-
"@types/node": "^22.5.5",
51+
"@types/node": "^22.7.3",
5252
"@types/uuid": "^10.0.0",
5353
"ava": "6.1.3"
5454
},

oada/libs/lib-prom/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
"devDependencies": {
4343
"@ava/typescript": "^5.0.0",
4444
"@types/convict": "^6.1.6",
45-
"@types/node": "^22.5.5",
45+
"@types/node": "^22.7.3",
4646
"@types/ws": "^8.5.12",
4747
"ava": "6.1.3",
48-
"fastify-plugin": "^5.0.0"
48+
"fastify-plugin": "^5.0.1"
4949
},
5050
"volta": {
5151
"node": "22.5.1"

oada/libs/lib-prom/src/index.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import { config } from './config.js';
1919

2020
import { createServer } from 'node:http';
2121

22-
import { collectDefaultMetrics, register } from 'prom-client';
22+
import {
23+
Gauge,
24+
type MetricConfiguration,
25+
collectDefaultMetrics,
26+
register,
27+
} from 'prom-client';
2328
import type NStats from 'nstats';
2429

2530
collectDefaultMetrics({ register });
@@ -37,6 +42,7 @@ export const nstats: typeof NStats = (...parameters) => {
3742
*
3843
* *Starts automatically, don't try to start manually.*
3944
*/
45+
// eslint-disable-next-line sonarjs/no-misused-promises
4046
export const server = createServer(async (_, response) => {
4147
try {
4248
const metrics = await register.metrics();
@@ -60,3 +66,47 @@ const { port, host } = config.get('prometheus');
6066
server.listen({ host, port });
6167

6268
export * from 'prom-client';
69+
70+
export interface PseudoMetricConfiguration<T extends string> {
71+
name: `${string}_info`;
72+
help: string;
73+
labels?: Record<T, string>;
74+
collect?: (this: PseudoMetric<T>) => void | Promise<void>;
75+
registers: MetricConfiguration<T>['registers'];
76+
}
77+
78+
/**
79+
* A pseudo-metric that provides metadata about the process to prometheus
80+
*
81+
* The lables are the reported metadata
82+
*
83+
* @see {@link https://www.robustperception.io/exposing-the-software-version-to-prometheus/}
84+
*/
85+
export class PseudoMetric<T extends string = string> {
86+
readonly #gauge;
87+
88+
constructor({
89+
name,
90+
help,
91+
labels,
92+
registers,
93+
collect = () => {
94+
this.set(labels!);
95+
},
96+
}: PseudoMetricConfiguration<T>) {
97+
this.#gauge = new Gauge<T>({
98+
name,
99+
help,
100+
aggregator: 'first',
101+
registers,
102+
collect: () => collect.call(this),
103+
});
104+
}
105+
106+
/**
107+
* !! ***You should only call this from within a collect callback***
108+
*/
109+
public set(labels: Record<T, string>) {
110+
this.#gauge.set(labels, 1);
111+
}
112+
}

oada/libs/models/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"node": "22.5.1"
3939
},
4040
"devDependencies": {
41-
"@types/node": "^22.5.5",
42-
"jose": "^5.9.2"
41+
"@types/node": "^22.7.3",
42+
"jose": "^5.9.3"
4343
}
4444
}

oada/libs/pino-debug/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
"pino": "^9.4.0",
2929
"pino-caller": "^3.4.0",
3030
"pino-debug": "^2.0.0",
31-
"pino-loki": "^2.3.0",
31+
"pino-loki": "^2.3.1",
3232
"pino-pretty": "^11.2.2",
3333
"tslib": "2.7.0"
3434
},
3535
"devDependencies": {
3636
"@types/debug": "^4.1.12",
37-
"@types/node": "^22.5.5"
37+
"@types/node": "^22.7.3"
3838
},
3939
"peerDependencies": {
4040
"debug": "*"

oada/libs/pino-debug/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/* eslint-disable unicorn/prefer-module */
1919

20-
/* eslint-disable import/no-dynamic-require */
20+
2121

2222
import { resolve } from 'node:path';
2323

oada/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@
1818
"@eslint/compat": "^1.1.1",
1919
"@eslint/config-inspector": "^0.5.4",
2020
"@eslint/eslintrc": "^3.1.0",
21-
"@eslint/js": "^9.10.0",
21+
"@eslint/js": "^9.11.1",
2222
"@tsconfig/node20": "^20.1.4",
2323
"@types/eslint": "^9.6.1",
2424
"@types/mocha": "^10.0.8",
25-
"@types/node": "^22.5.5",
26-
"@typescript-eslint/eslint-plugin": "^8.6.0",
27-
"@typescript-eslint/parser": "^8.6.0",
25+
"@types/node": "^22.7.3",
26+
"@typescript-eslint/eslint-plugin": "^8.7.0",
27+
"@typescript-eslint/parser": "^8.7.0",
2828
"@yarnpkg/sdks": "^3.2.0",
29-
"browserslist": "^4.23.3",
29+
"browserslist": "^4.24.0",
3030
"c8": "^10.1.2",
31-
"eslint": "^9.10.0",
31+
"eslint": "^9.11.1",
3232
"eslint-config-prettier": "^9.1.0",
3333
"eslint-config-xo": "^0.46.0",
34-
"eslint-config-xo-typescript": "^6.0.0",
34+
"eslint-config-xo-typescript": "^7.0.0",
3535
"eslint-formatter-pretty": "^6.0.1",
3636
"eslint-import-resolver-node": "^0.3.9",
3737
"eslint-import-resolver-typescript": "^3.6.3",
3838
"eslint-plugin-array-func": "^5.0.2",
3939
"eslint-plugin-ava": "^15.0.1",
40-
"eslint-plugin-escompat": "^3.11.1",
40+
"eslint-plugin-escompat": "^3.11.3",
4141
"eslint-plugin-eslint-comments": "^3.2.0",
4242
"eslint-plugin-filenames": "^1.3.2",
4343
"eslint-plugin-github": "^5.0.2",
@@ -59,9 +59,9 @@
5959
"prettier": "^3.3.3",
6060
"tslib": "2.7.0",
6161
"typescript": "5.6.2",
62-
"typescript-eslint": "^8.6.0",
62+
"typescript-eslint": "^8.7.0",
6363
"update-browserslist-db": "^1.1.0",
64-
"zx": "^8.1.7"
64+
"zx": "^8.1.8"
6565
},
6666
"dependencies": {
6767
"pino-pretty": "^11.2.2"

0 commit comments

Comments
 (0)