Skip to content

Commit

Permalink
Adding 'express-prom-bundle' middleware, & creating 'prometheus' to c…
Browse files Browse the repository at this point in the history
…onfig (WIP)
  • Loading branch information
avoidwork committed Aug 30, 2024
1 parent 57e1e02 commit 9c08f5c
Show file tree
Hide file tree
Showing 15 changed files with 988 additions and 15 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ Everything is optional! You can provide as much, or as little configuration as y
origins: ["*"],
pageSize: 5,
port: 8000,
prometheus: {
enabled: false,
metrics: {
includeMethod: true,
includePath: true,
includeStatusCode: true,
includeUp: true
}
},
rate: {
enabled: false,
limit: 450,
Expand Down
21 changes: 21 additions & 0 deletions dist/tenso.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var fastXmlParser = require('fast-xml-parser');
var sync = require('csv-stringify/sync');
var keysort = require('keysort');
var url = require('url');
var promBundle = require('express-prom-bundle');
var redis = require('ioredis');
var cookie = require('cookie-parser');
var session = require('express-session');
Expand Down Expand Up @@ -286,6 +287,15 @@ const config = {
origins: [WILDCARD],
pageSize: INT_5,
port: INT_8000,
prometheus: {
enabled: false,
metrics: {
includeMethod: true,
includePath: true,
includeStatusCode: true,
includeUp: true
}
},
rate: {
enabled: false,
limit: INT_450,
Expand Down Expand Up @@ -810,6 +820,9 @@ function parse (req, res, next) {
next(valid === false ? exception : void 0);
}

// Prometheus metrics
const prometheus = config => promBundle(config);

function asyncFlag (req, res, next) {
req.protectAsync = true;
next();
Expand Down Expand Up @@ -1281,6 +1294,14 @@ class Tenso extends woodland.Woodland {
return [body, status, headers];
};

// Prometheus metrics
if (this.prometheus.enabled) {
const middleware = prometheus(this.prometheus.metrics);

this.log("type=init, message\"Prometheus metrics enabled\"");
this.always(middleware).ignore(middleware);
}

// Payload handling
this.always(payload).ignore(payload);
this.always(parse).ignore(parse);
Expand Down
22 changes: 20 additions & 2 deletions dist/tenso.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license BSD-3-Clause
* @version 17.0.4
*/
import {readFileSync}from'node:fs';import http,{STATUS_CODES}from'node:http';import https from'node:https';import {createRequire}from'node:module';import {join,resolve}from'node:path';import {fileURLToPath,URL as URL$1}from'node:url';import {Woodland}from'woodland';import {merge}from'tiny-merge';import {eventsource}from'tiny-eventsource';import {parse as parse$1,stringify as stringify$1}from'tiny-jsonl';import {coerce}from'tiny-coerce';import YAML from'yamljs';import {XMLBuilder}from'fast-xml-parser';import {stringify}from'csv-stringify/sync';import {keysort}from'keysort';import {URL}from'url';import redis from'ioredis';import cookie from'cookie-parser';import session from'express-session';import passport from'passport';import passportJWT from'passport-jwt';import {BasicStrategy}from'passport-http';import {Strategy}from'passport-http-bearer';import {Strategy as Strategy$1}from'passport-oauth2';import lusca from'lusca';import {randomInt,randomUUID}from'node:crypto';import RedisStore from'connect-redis';const ACCESS_CONTROL = "access-control";
import {readFileSync}from'node:fs';import http,{STATUS_CODES}from'node:http';import https from'node:https';import {createRequire}from'node:module';import {join,resolve}from'node:path';import {fileURLToPath,URL as URL$1}from'node:url';import {Woodland}from'woodland';import {merge}from'tiny-merge';import {eventsource}from'tiny-eventsource';import {parse as parse$1,stringify as stringify$1}from'tiny-jsonl';import {coerce}from'tiny-coerce';import YAML from'yamljs';import {XMLBuilder}from'fast-xml-parser';import {stringify}from'csv-stringify/sync';import {keysort}from'keysort';import {URL}from'url';import promBundle from'express-prom-bundle';import redis from'ioredis';import cookie from'cookie-parser';import session from'express-session';import passport from'passport';import passportJWT from'passport-jwt';import {BasicStrategy}from'passport-http';import {Strategy}from'passport-http-bearer';import {Strategy as Strategy$1}from'passport-oauth2';import lusca from'lusca';import {randomInt,randomUUID}from'node:crypto';import RedisStore from'connect-redis';const ACCESS_CONTROL = "access-control";
const ALGORITHMS = "algorithms";
const ALLOW = "allow";
const AUDIENCE = "audience";
Expand Down Expand Up @@ -253,6 +253,15 @@ const X_RATELIMIT_RESET = "x-ratelimit-reset";const config = {
origins: [WILDCARD],
pageSize: INT_5,
port: INT_8000,
prometheus: {
enabled: false,
metrics: {
includeMethod: true,
includePath: true,
includeStatusCode: true,
includeUp: true
}
},
rate: {
enabled: false,
limit: INT_450,
Expand Down Expand Up @@ -713,7 +722,8 @@ function marshal (obj, rel, item_collection, root, seen, links, server) {
}

next(valid === false ? exception : void 0);
}function asyncFlag (req, res, next) {
}// Prometheus metrics
const prometheus = config => promBundle(config);function asyncFlag (req, res, next) {
req.protectAsync = true;
next();
}function bypass (req, res, next) {
Expand Down Expand Up @@ -1162,6 +1172,14 @@ class Tenso extends Woodland {
return [body, status, headers];
};

// Prometheus metrics
if (this.prometheus.enabled) {
const middleware = prometheus(this.prometheus.metrics);

this.log("type=init, message\"Prometheus metrics enabled\"");
this.always(middleware).ignore(middleware);
}

// Payload handling
this.always(payload).ignore(payload);
this.always(parse).ignore(parse);
Expand Down
Loading

0 comments on commit 9c08f5c

Please sign in to comment.