Skip to content

Commit

Permalink
feat: add prometheus metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Nov 18, 2024
1 parent e9f4ef4 commit fde1513
Show file tree
Hide file tree
Showing 8 changed files with 3,457 additions and 980 deletions.
98 changes: 42 additions & 56 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ extends:
- plugin:unicorn/recommended
#- plugin:security/recommended
#- plugin:sonarjs/recommended
#- xo
- plugin:github/typescript
- plugin:import/typescript
- xo-typescript
- plugin:ava/recommended
- xo
- plugin:prettier/recommended

plugins:
Expand All @@ -37,66 +40,49 @@ parser: '@typescript-eslint/parser'

parserOptions:
ecmaVersion: 2020
project: ./**/tsconfig.*
project: '**/tsconfig.json'

overrides:
- files: '*.ts'
extends:
- plugin:github/typescript
- plugin:import/typescript
- xo-typescript
- plugin:prettier/recommended
parserOptions:
ecmaVersion: 2020
project: ./**/tsconfig.*
rules:
prettier/prettier: off
'@typescript-eslint/naming-convention':
[
error,
{ selector: default, format: [camelCase] },
{ selector: import, modifiers: [default], format: null },
{ selector: objectLiteralProperty, format: null },
{ selector: enumMember, format: [PascalCase] },
{ selector: typeProperty, format: null },
rules:
'@typescript-eslint/naming-convention':
[
error,
{ selector: default, format: [camelCase] },
{ selector: import, modifiers: [default], format: null },
{ selector: objectLiteralProperty, format: null },
{ selector: enumMember, format: [PascalCase] },
{ selector: typeProperty, format: null },

{
selector: variableLike,
format: [camelCase, UPPER_CASE],
leadingUnderscore: allow,
},
{ selector: variable, modifiers: [destructured], format: null },
{
selector: parameter,
format: [camelCase],
leadingUnderscore: allow,
},
{
selector: variableLike,
format: [camelCase, UPPER_CASE],
leadingUnderscore: allow,
},
{ selector: variable, modifiers: [destructured], format: null },
{ selector: parameter, format: [camelCase], leadingUnderscore: allow },

{
selector: memberLike,
modifiers: [private],
format: [camelCase],
leadingUnderscore: require,
},
{
selector: memberLike,
modifiers: [private],
format: [camelCase],
leadingUnderscore: require,
},

{ selector: typeLike, format: [PascalCase] },
{ selector: parameter, modifiers: [destructured], format: null },
]
'@typescript-eslint/restrict-template-expressions': 0
'@typescript-eslint/no-shadow': warn
'@typescript-eslint/no-unused-vars':
[
warn,
{
args: after-used,
ignoreRestSiblings: true,
varsIgnorePattern: ^_,
argsIgnorePattern: ^_,
},
]
'@typescript-eslint/consistent-type-definitions': [warn, interface]
{ selector: typeLike, format: [PascalCase] },
{ selector: parameter, modifiers: [destructured], format: null },
]
'@typescript-eslint/restrict-template-expressions': 0
'@typescript-eslint/no-unused-vars':
[
warn,
{
args: after-used,
ignoreRestSiblings: true,
varsIgnorePattern: ^_,
argsIgnorePattern: ^_,
},
]
'@typescript-eslint/consistent-type-definitions': [warn, interface]

rules:
notice/notice:
- error
- template: |
Expand Down
725 changes: 367 additions & 358 deletions .yarn/releases/yarn-4.5.0.cjs → .yarn/releases/yarn-4.5.1.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ packageExtensions:
"#ansi-styles": "npm:[email protected]"
"#supports-color": "npm:[email protected]"

yarnPath: .yarn/releases/yarn-4.5.0.cjs
yarnPath: .yarn/releases/yarn-4.5.1.cjs
42 changes: 22 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@trellisfw/monitor",
"version": "2.2.6",
"version": "3.0.0",
"description": "A Trellis microservice to respond to monitor pings, spawn and check things internally, and respond with success or fail",
"main": "dist/index.js",
"type": "module",
Expand Down Expand Up @@ -35,71 +35,73 @@
},
"dependencies": {
"@oada/client": "5.2.3",
"convict": "^6.2.4",
"@oada/lib-config": "^4.0.0",
"@oada/lib-prom": "^4.0.1",
"@oada/pino-debug": "^4.0.1",
"debug": "^4.3.7",
"dotenv": "^16.4.5",
"express": "^4.21.1",
"ksuid": "^3.0.0",
"micromatch": "^4.0.8",
"moment": "^2.30.1",
"node-cron": "^3.0.3",
"tiny-json-http": "^7.5.1",
"tslib": "^2.8.0"
"tslib": "^2.8.1"
},
"devDependencies": {
"@ava/typescript": "^5.0.0",
"@sinonjs/fake-timers": "^13.0.2",
"@sinonjs/fake-timers": "^13.0.5",
"@tsconfig/node22": "^22.0.0",
"@types/convict": "^6.1.6",
"@types/debug": "^4.1.12",
"@types/express": "^4.17.21",
"@types/express": "^5.0.0",
"@types/micromatch": "^4.0.9",
"@types/node": "22.5.5",
"@types/node": "22.9.0",
"@types/node-cron": "^3.0.11",
"@types/sinonjs__fake-timers": "^8.1.5",
"@types/tiny-json-http": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@typescript-eslint/eslint-plugin": "^8.15.0",
"@typescript-eslint/parser": "^8.15.0",
"@yarnpkg/sdks": "^3.2.0",
"ava": "6.1.3",
"ava": "6.2.0",
"ava-nock": "^2.1.0",
"cross-env": "^7.0.3",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-config-xo": "^0.45.0",
"eslint-config-xo-typescript": "^4.0.0",
"eslint-config-xo": "^0.46.0",
"eslint-config-xo-typescript": "^5.0.0",
"eslint-formatter-pretty": "^6.0.1",
"eslint-import-resolver-node": "^0.3.9",
"eslint-plugin-array-func": "^5.0.2",
"eslint-plugin-ava": "^15.0.1",
"eslint-plugin-escompat": "^3.11.3",
"eslint-plugin-escompat": "^3.11.4",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-github": "^5.0.2",
"eslint-plugin-i18n-text": "^1.0.1",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-no-constructor-bind": "^2.0.4",
"eslint-plugin-no-only-tests": "^3.3.0",
"eslint-plugin-no-secrets": "^1.0.2",
"eslint-plugin-no-secrets": "^1.1.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-notice": "^1.0.0",
"eslint-plugin-optimize-regex": "^1.2.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^6.6.0",
"eslint-plugin-regexp": "^2.6.0",
"eslint-plugin-promise": "^7.1.0",
"eslint-plugin-regexp": "^2.7.0",
"eslint-plugin-security": "^3.0.1",
"eslint-plugin-sonarjs": "^1.0.4",
"eslint-plugin-unicorn": "^54.0.0",
"eslint-plugin-sonarjs": "^2.0.4",
"eslint-plugin-unicorn": "^56.0.0",
"isomorphic-timers-promises": "^1.0.1",
"minimist": "^1.2.8",
"nock": "^13.5.5",
"nock": "^13.5.6",
"prettier": "^3.3.3",
"typescript": "^5.6.3"
},
"resolutions": {
"cross-spawn": "^7.0.5",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz"
},
"packageManager": "[email protected].0",
"packageManager": "[email protected].1",
"volta": {
"node": "22.9.0"
}
Expand Down
8 changes: 4 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import { dirname, join } from 'node:path';
import url from 'node:url';

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

load();

const config = convict({
const { config } = await load({
oada: {
domain: {
doc: 'OADA API domain',
Expand All @@ -36,6 +34,7 @@ const config = convict({
doc: 'OADA API token',
format: String,
default: 'god',
sensitive: true,
env: 'TOKEN',
},
},
Expand All @@ -44,6 +43,7 @@ const config = convict({
doc: 'Token expected on incoming requests',
format: String,
default: 'god',
sensitive: true,
// TODO: fix capitalization
env: 'incomingToken',
},
Expand Down
19 changes: 19 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import config from './config.js';

import '@oada/pino-debug';

// eslint-disable-next-line unicorn/import-style
import { join } from 'node:path';
import { readdir } from 'node:fs/promises';
Expand All @@ -27,6 +29,7 @@ import express from 'express';
import micromatch from 'micromatch';
import moment from 'moment';

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

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

new PseudoMetric({
name: 'trellis_monitor_info',
help: 'The info of trellis monitor',
labels: {
server: notifyname,
},
});
// TODO: Labels for each separate test?
new Gauge({
name: 'trellis_monitor_server_status_success',
help: 'The status of the server being monitored',
collect() {
this.set(status.global.status === 'success' ? 1 : 0);
},
});

// Load monitor tests
const rawtests = new Map<string, Test>();
info('Loading all monitor tests from %s', testdir);
Expand Down
16 changes: 0 additions & 16 deletions tsconfig.eslint.json

This file was deleted.

Loading

0 comments on commit fde1513

Please sign in to comment.