@tryghost/prometheus-metrics 1.0.5 → 1.0.6

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.
package/README.md CHANGED
@@ -3,6 +3,10 @@
3
3
  A standalone server for exporting prometheus metrics from Ghost
4
4
 
5
5
 
6
+ ## Purpose
7
+
8
+ Prometheus metrics integration for exposing Ghost runtime counters, gauges, and histograms.
9
+
6
10
  ## Usage
7
11
 
8
12
 
@@ -4,15 +4,21 @@ type ServerConfig = {
4
4
  host: string;
5
5
  port: number;
6
6
  };
7
+ type CreateApp = () => express.Application;
8
+ type CreateStoppableServer = (server: ReturnType<express.Application['listen']>, grace?: number) => stoppable.StoppableServer;
7
9
  export declare class MetricsServer {
8
10
  private serverConfig;
9
11
  private handler;
10
12
  private app;
11
13
  private httpServer;
12
14
  private isShuttingDown;
13
- constructor({ serverConfig, handler }: {
15
+ private createApp;
16
+ private createStoppableServer;
17
+ constructor({ serverConfig, handler, createApp, createStoppableServer }: {
14
18
  serverConfig: ServerConfig;
15
19
  handler: express.Handler;
20
+ createApp?: CreateApp;
21
+ createStoppableServer?: CreateStoppableServer;
16
22
  });
17
23
  start(): Promise<{
18
24
  app: express.Application;
@@ -14,29 +14,30 @@ class MetricsServer {
14
14
  app;
15
15
  httpServer;
16
16
  isShuttingDown;
17
- constructor({ serverConfig, handler }) {
18
- // initialize local variables
17
+ createApp;
18
+ createStoppableServer;
19
+ constructor({ serverConfig, handler, createApp, createStoppableServer }) {
19
20
  this.serverConfig = serverConfig;
20
21
  this.handler = handler;
21
22
  this.app = null;
22
23
  this.httpServer = null;
23
24
  this.isShuttingDown = false;
25
+ this.createApp = createApp ?? express_1.default;
26
+ this.createStoppableServer = createStoppableServer ?? stoppable_1.default;
24
27
  }
25
28
  async start() {
26
- // start the server
27
29
  debug('Starting metrics server');
28
- this.app = (0, express_1.default)();
30
+ this.app = this.createApp();
29
31
  this.app.get('/metrics', this.handler);
30
32
  const httpServer = this.app.listen(this.serverConfig.port, this.serverConfig.host, () => {
31
33
  debug(`Metrics server listening at ${this.serverConfig.host}:${this.serverConfig.port}`);
32
34
  });
33
- this.httpServer = (0, stoppable_1.default)(httpServer, 0);
35
+ this.httpServer = this.createStoppableServer(httpServer, 0);
34
36
  process.on('SIGINT', () => this.shutdown());
35
37
  process.on('SIGTERM', () => this.shutdown());
36
38
  return { app: this.app, httpServer: this.httpServer };
37
39
  }
38
40
  async stop() {
39
- // stop the server
40
41
  debug('Stopping metrics server');
41
42
  if (this.httpServer && this.httpServer.listening) {
42
43
  await this.httpServer.stop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/prometheus-metrics",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/TryGhost/framework.git",
@@ -17,7 +17,7 @@
17
17
  "build": "yarn build:ts",
18
18
  "build:ts": "tsc",
19
19
  "prepare": "tsc",
20
- "test:unit": "NODE_ENV=testing c8 --src src --all --check-coverage --90 --reporter text --reporter cobertura mocha -r ts-node/register './test/**/*.test.ts'",
20
+ "test:unit": "NODE_ENV=testing c8 --src src --all --check-coverage --100 --reporter text --reporter cobertura mocha -r ts-node/register './test/**/*.test.ts'",
21
21
  "test": "yarn test:types && yarn test:unit",
22
22
  "test:types": "tsc --noEmit",
23
23
  "lint:code": "eslint src/ --ext .ts --cache",