Skip to content

Commit fde1513

Browse files
committed
feat: add prometheus metrics
1 parent e9f4ef4 commit fde1513

File tree

8 files changed

+3457
-980
lines changed

8 files changed

+3457
-980
lines changed

.eslintrc.yaml

Lines changed: 42 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ extends:
1212
- plugin:unicorn/recommended
1313
#- plugin:security/recommended
1414
#- plugin:sonarjs/recommended
15+
#- xo
16+
- plugin:github/typescript
17+
- plugin:import/typescript
18+
- xo-typescript
1519
- plugin:ava/recommended
16-
- xo
1720
- plugin:prettier/recommended
1821

1922
plugins:
@@ -37,66 +40,49 @@ parser: '@typescript-eslint/parser'
3740

3841
parserOptions:
3942
ecmaVersion: 2020
40-
project: ./**/tsconfig.*
43+
project: '**/tsconfig.json'
4144

42-
overrides:
43-
- files: '*.ts'
44-
extends:
45-
- plugin:github/typescript
46-
- plugin:import/typescript
47-
- xo-typescript
48-
- plugin:prettier/recommended
49-
parserOptions:
50-
ecmaVersion: 2020
51-
project: ./**/tsconfig.*
52-
rules:
53-
prettier/prettier: off
54-
'@typescript-eslint/naming-convention':
55-
[
56-
error,
57-
{ selector: default, format: [camelCase] },
58-
{ selector: import, modifiers: [default], format: null },
59-
{ selector: objectLiteralProperty, format: null },
60-
{ selector: enumMember, format: [PascalCase] },
61-
{ selector: typeProperty, format: null },
45+
rules:
46+
'@typescript-eslint/naming-convention':
47+
[
48+
error,
49+
{ selector: default, format: [camelCase] },
50+
{ selector: import, modifiers: [default], format: null },
51+
{ selector: objectLiteralProperty, format: null },
52+
{ selector: enumMember, format: [PascalCase] },
53+
{ selector: typeProperty, format: null },
6254

63-
{
64-
selector: variableLike,
65-
format: [camelCase, UPPER_CASE],
66-
leadingUnderscore: allow,
67-
},
68-
{ selector: variable, modifiers: [destructured], format: null },
69-
{
70-
selector: parameter,
71-
format: [camelCase],
72-
leadingUnderscore: allow,
73-
},
55+
{
56+
selector: variableLike,
57+
format: [camelCase, UPPER_CASE],
58+
leadingUnderscore: allow,
59+
},
60+
{ selector: variable, modifiers: [destructured], format: null },
61+
{ selector: parameter, format: [camelCase], leadingUnderscore: allow },
7462

75-
{
76-
selector: memberLike,
77-
modifiers: [private],
78-
format: [camelCase],
79-
leadingUnderscore: require,
80-
},
63+
{
64+
selector: memberLike,
65+
modifiers: [private],
66+
format: [camelCase],
67+
leadingUnderscore: require,
68+
},
8169

82-
{ selector: typeLike, format: [PascalCase] },
83-
{ selector: parameter, modifiers: [destructured], format: null },
84-
]
85-
'@typescript-eslint/restrict-template-expressions': 0
86-
'@typescript-eslint/no-shadow': warn
87-
'@typescript-eslint/no-unused-vars':
88-
[
89-
warn,
90-
{
91-
args: after-used,
92-
ignoreRestSiblings: true,
93-
varsIgnorePattern: ^_,
94-
argsIgnorePattern: ^_,
95-
},
96-
]
97-
'@typescript-eslint/consistent-type-definitions': [warn, interface]
70+
{ selector: typeLike, format: [PascalCase] },
71+
{ selector: parameter, modifiers: [destructured], format: null },
72+
]
73+
'@typescript-eslint/restrict-template-expressions': 0
74+
'@typescript-eslint/no-unused-vars':
75+
[
76+
warn,
77+
{
78+
args: after-used,
79+
ignoreRestSiblings: true,
80+
varsIgnorePattern: ^_,
81+
argsIgnorePattern: ^_,
82+
},
83+
]
84+
'@typescript-eslint/consistent-type-definitions': [warn, interface]
9885

99-
rules:
10086
notice/notice:
10187
- error
10288
- template: |

.yarn/releases/yarn-4.5.0.cjs renamed to .yarn/releases/yarn-4.5.1.cjs

Lines changed: 367 additions & 358 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ packageExtensions:
77
"#ansi-styles": "npm:ansi-styles@6.1.0"
88
"#supports-color": "npm:supports-color@9.2.2"
99

10-
yarnPath: .yarn/releases/yarn-4.5.0.cjs
10+
yarnPath: .yarn/releases/yarn-4.5.1.cjs

package.json

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@trellisfw/monitor",
3-
"version": "2.2.6",
3+
"version": "3.0.0",
44
"description": "A Trellis microservice to respond to monitor pings, spawn and check things internally, and respond with success or fail",
55
"main": "dist/index.js",
66
"type": "module",
@@ -35,71 +35,73 @@
3535
},
3636
"dependencies": {
3737
"@oada/client": "5.2.3",
38-
"convict": "^6.2.4",
38+
"@oada/lib-config": "^4.0.0",
39+
"@oada/lib-prom": "^4.0.1",
40+
"@oada/pino-debug": "^4.0.1",
3941
"debug": "^4.3.7",
40-
"dotenv": "^16.4.5",
4142
"express": "^4.21.1",
4243
"ksuid": "^3.0.0",
4344
"micromatch": "^4.0.8",
4445
"moment": "^2.30.1",
4546
"node-cron": "^3.0.3",
4647
"tiny-json-http": "^7.5.1",
47-
"tslib": "^2.8.0"
48+
"tslib": "^2.8.1"
4849
},
4950
"devDependencies": {
5051
"@ava/typescript": "^5.0.0",
51-
"@sinonjs/fake-timers": "^13.0.2",
52+
"@sinonjs/fake-timers": "^13.0.5",
5253
"@tsconfig/node22": "^22.0.0",
5354
"@types/convict": "^6.1.6",
5455
"@types/debug": "^4.1.12",
55-
"@types/express": "^4.17.21",
56+
"@types/express": "^5.0.0",
5657
"@types/micromatch": "^4.0.9",
57-
"@types/node": "22.5.5",
58+
"@types/node": "22.9.0",
5859
"@types/node-cron": "^3.0.11",
5960
"@types/sinonjs__fake-timers": "^8.1.5",
6061
"@types/tiny-json-http": "^7.3.4",
61-
"@typescript-eslint/eslint-plugin": "^7.18.0",
62-
"@typescript-eslint/parser": "^7.18.0",
62+
"@typescript-eslint/eslint-plugin": "^8.15.0",
63+
"@typescript-eslint/parser": "^8.15.0",
6364
"@yarnpkg/sdks": "^3.2.0",
64-
"ava": "6.1.3",
65+
"ava": "6.2.0",
6566
"ava-nock": "^2.1.0",
6667
"cross-env": "^7.0.3",
6768
"eslint": "^8.57.1",
6869
"eslint-config-prettier": "^9.1.0",
69-
"eslint-config-xo": "^0.45.0",
70-
"eslint-config-xo-typescript": "^4.0.0",
70+
"eslint-config-xo": "^0.46.0",
71+
"eslint-config-xo-typescript": "^5.0.0",
7172
"eslint-formatter-pretty": "^6.0.1",
7273
"eslint-import-resolver-node": "^0.3.9",
7374
"eslint-plugin-array-func": "^5.0.2",
7475
"eslint-plugin-ava": "^15.0.1",
75-
"eslint-plugin-escompat": "^3.11.3",
76+
"eslint-plugin-escompat": "^3.11.4",
7677
"eslint-plugin-eslint-comments": "^3.2.0",
7778
"eslint-plugin-filenames": "^1.3.2",
7879
"eslint-plugin-github": "^5.0.2",
7980
"eslint-plugin-i18n-text": "^1.0.1",
8081
"eslint-plugin-import": "^2.31.0",
8182
"eslint-plugin-no-constructor-bind": "^2.0.4",
8283
"eslint-plugin-no-only-tests": "^3.3.0",
83-
"eslint-plugin-no-secrets": "^1.0.2",
84+
"eslint-plugin-no-secrets": "^1.1.2",
8485
"eslint-plugin-node": "^11.1.0",
8586
"eslint-plugin-notice": "^1.0.0",
8687
"eslint-plugin-optimize-regex": "^1.2.1",
8788
"eslint-plugin-prettier": "^5.2.1",
88-
"eslint-plugin-promise": "^6.6.0",
89-
"eslint-plugin-regexp": "^2.6.0",
89+
"eslint-plugin-promise": "^7.1.0",
90+
"eslint-plugin-regexp": "^2.7.0",
9091
"eslint-plugin-security": "^3.0.1",
91-
"eslint-plugin-sonarjs": "^1.0.4",
92-
"eslint-plugin-unicorn": "^54.0.0",
92+
"eslint-plugin-sonarjs": "^2.0.4",
93+
"eslint-plugin-unicorn": "^56.0.0",
9394
"isomorphic-timers-promises": "^1.0.1",
9495
"minimist": "^1.2.8",
95-
"nock": "^13.5.5",
96+
"nock": "^13.5.6",
9697
"prettier": "^3.3.3",
9798
"typescript": "^5.6.3"
9899
},
99100
"resolutions": {
101+
"cross-spawn": "^7.0.5",
100102
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz"
101103
},
102-
"packageManager": "yarn@4.5.0",
104+
"packageManager": "yarn@4.5.1",
103105
"volta": {
104106
"node": "22.9.0"
105107
}

src/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
import { dirname, join } from 'node:path';
2020
import url from 'node:url';
2121

22-
import convict from 'convict';
23-
import { config as load } from 'dotenv';
22+
import load from '@oada/lib-config';
2423

25-
load();
2624

27-
const config = convict({
25+
const { config } = await load({
2826
oada: {
2927
domain: {
3028
doc: 'OADA API domain',
@@ -36,6 +34,7 @@ const config = convict({
3634
doc: 'OADA API token',
3735
format: String,
3836
default: 'god',
37+
sensitive: true,
3938
env: 'TOKEN',
4039
},
4140
},
@@ -44,6 +43,7 @@ const config = convict({
4443
doc: 'Token expected on incoming requests',
4544
format: String,
4645
default: 'god',
46+
sensitive: true,
4747
// TODO: fix capitalization
4848
env: 'incomingToken',
4949
},

src/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import config from './config.js';
1919

20+
import '@oada/pino-debug';
21+
2022
// eslint-disable-next-line unicorn/import-style
2123
import { join } from 'node:path';
2224
import { readdir } from 'node:fs/promises';
@@ -27,6 +29,7 @@ import express from 'express';
2729
import micromatch from 'micromatch';
2830
import moment from 'moment';
2931

32+
import { Gauge, PseudoMetric } from '@oada/lib-prom';
3033
import { type OADAClient, connect } from '@oada/client';
3134

3235
// eslint-disable-next-line import/no-namespace
@@ -127,6 +130,22 @@ const status: Status = {
127130
};
128131
const failures = new Map<string, TestResult>();
129132

133+
new PseudoMetric({
134+
name: 'trellis_monitor_info',
135+
help: 'The info of trellis monitor',
136+
labels: {
137+
server: notifyname,
138+
},
139+
});
140+
// TODO: Labels for each separate test?
141+
new Gauge({
142+
name: 'trellis_monitor_server_status_success',
143+
help: 'The status of the server being monitored',
144+
collect() {
145+
this.set(status.global.status === 'success' ? 1 : 0);
146+
},
147+
});
148+
130149
// Load monitor tests
131150
const rawtests = new Map<string, Test>();
132151
info('Loading all monitor tests from %s', testdir);

tsconfig.eslint.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)