@axinom/mosaic-db-common 0.34.0-rc.10 → 0.34.0-rc.11

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.
@@ -1,5 +1,6 @@
1
1
  import { Pool } from 'pg';
2
2
  import { Metric } from 'prom-client';
3
+ import { DbLogger } from '../common';
3
4
  /**
4
5
  * Creates a `Gauge` metric with the name `ax_postgres_<pgPoolType>_connectivity` which can be added to a metric Registry.
5
6
  * This metric will have a value of `1` if the Database can be reached via the corresponding Pool (within the given timeout),
@@ -10,5 +11,5 @@ import { Metric } from 'prom-client';
10
11
  * @param timeoutInMilliSeconds The maximum time the connectivity check will run during metric collection. Defaults to `1000ms`.
11
12
  * @returns A `Gauge` metric with a name `ax_postgres_<pgPoolType>_connectivity`.
12
13
  */
13
- export declare const createPostgresPoolConnectivityMetric: (pgPool: Pool, pgPoolType: 'dbOwnerPool' | 'envOwnerPool' | 'loginPool', timeoutInMilliSeconds?: number) => Metric<string>;
14
+ export declare const createPostgresPoolConnectivityMetric: (logger: DbLogger, pgPool: Pool, pgPoolType: 'dbOwnerPool' | 'envOwnerPool' | 'loginPool', timeoutInMilliSeconds?: number) => Metric<string>;
14
15
  //# sourceMappingURL=postgres-metrics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-metrics.d.ts","sourceRoot":"","sources":["../../src/monitoring/postgres-metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAS,MAAM,EAAE,MAAM,aAAa,CAAC;AAO5C;;;;;;;;;GASG;AACH,eAAO,MAAM,oCAAoC,WACvC,IAAI,cACA,aAAa,GAAG,cAAc,GAAG,WAAW,qCAEvD,OAAO,MAAM,CAiBf,CAAC"}
1
+ {"version":3,"file":"postgres-metrics.d.ts","sourceRoot":"","sources":["../../src/monitoring/postgres-metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAS,MAAM,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAUrC;;;;;;;;;GASG;AACH,eAAO,MAAM,oCAAoC,WACvC,QAAQ,UACR,IAAI,cACA,aAAa,GAAG,cAAc,GAAG,WAAW,qCAEvD,OAAO,MAAM,CAyBf,CAAC"}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createPostgresPoolConnectivityMetric = void 0;
4
4
  const prom_client_1 = require("prom-client");
5
- const createTimeout = (timeoutInMilliSeconds) => new Promise((_, reject) => setTimeout(() => reject(), timeoutInMilliSeconds));
5
+ const createTimeout = (timeoutInMilliSeconds) => new Promise((_, reject) => setTimeout(() => reject(new Error('METRIC_COLLECTION_TIMEOUT')), timeoutInMilliSeconds));
6
6
  /**
7
7
  * Creates a `Gauge` metric with the name `ax_postgres_<pgPoolType>_connectivity` which can be added to a metric Registry.
8
8
  * This metric will have a value of `1` if the Database can be reached via the corresponding Pool (within the given timeout),
@@ -13,7 +13,7 @@ const createTimeout = (timeoutInMilliSeconds) => new Promise((_, reject) => setT
13
13
  * @param timeoutInMilliSeconds The maximum time the connectivity check will run during metric collection. Defaults to `1000ms`.
14
14
  * @returns A `Gauge` metric with a name `ax_postgres_<pgPoolType>_connectivity`.
15
15
  */
16
- const createPostgresPoolConnectivityMetric = (pgPool, pgPoolType, timeoutInMilliSeconds = 1000) => {
16
+ const createPostgresPoolConnectivityMetric = (logger, pgPool, pgPoolType, timeoutInMilliSeconds = 1000) => {
17
17
  return new prom_client_1.Gauge({
18
18
  name: `ax_postgres_${pgPoolType}_connectivity`,
19
19
  help: `Connection status from the service to the database via the ${pgPoolType}`,
@@ -25,7 +25,13 @@ const createPostgresPoolConnectivityMetric = (pgPool, pgPoolType, timeoutInMilli
25
25
  ]);
26
26
  this.set(1);
27
27
  }
28
- catch (_a) {
28
+ catch (error) {
29
+ if (error.message === 'METRIC_COLLECTION_TIMEOUT') {
30
+ logger.error(`A METRIC_COLLECTION_TIMEOUT error occurred while checking connectivity to the database via the ${pgPoolType} with a timeout of ${timeoutInMilliSeconds}ms.`);
31
+ }
32
+ else {
33
+ logger.error(error, `METRIC_COLLECTION_ERROR`);
34
+ }
29
35
  this.set(0);
30
36
  }
31
37
  },
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-metrics.js","sourceRoot":"","sources":["../../src/monitoring/postgres-metrics.ts"],"names":[],"mappings":";;;AACA,6CAA4C;AAE5C,MAAM,aAAa,GAAG,CAAC,qBAA6B,EAAiB,EAAE,CACrE,IAAI,OAAO,CAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAC9B,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,qBAAqB,CAAC,CAClD,CAAC;AAEJ;;;;;;;;;GASG;AACI,MAAM,oCAAoC,GAAG,CAClD,MAAY,EACZ,UAAwD,EACxD,qBAAqB,GAAG,IAAI,EACZ,EAAE;IAClB,OAAO,IAAI,mBAAK,CAAC;QACf,IAAI,EAAE,eAAe,UAAU,eAAe;QAC9C,IAAI,EAAE,8DAA8D,UAAU,EAAE;QAEhF,KAAK,CAAC,OAAO;YACX,IAAI;gBACF,MAAM,OAAO,CAAC,IAAI,CAAC;oBACjB,MAAM,CAAC,KAAK,CAAC,gDAAgD,CAAC;oBAC9D,aAAa,CAAC,qBAAqB,CAAC;iBACrC,CAAC,CAAC;gBACH,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACb;YAAC,WAAM;gBACN,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACb;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AArBW,QAAA,oCAAoC,wCAqB/C"}
1
+ {"version":3,"file":"postgres-metrics.js","sourceRoot":"","sources":["../../src/monitoring/postgres-metrics.ts"],"names":[],"mappings":";;;AACA,6CAA4C;AAG5C,MAAM,aAAa,GAAG,CAAC,qBAA6B,EAAiB,EAAE,CACrE,IAAI,OAAO,CAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAC9B,UAAU,CACR,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC,EACpD,qBAAqB,CACtB,CACF,CAAC;AAEJ;;;;;;;;;GASG;AACI,MAAM,oCAAoC,GAAG,CAClD,MAAgB,EAChB,MAAY,EACZ,UAAwD,EACxD,qBAAqB,GAAG,IAAI,EACZ,EAAE;IAClB,OAAO,IAAI,mBAAK,CAAC;QACf,IAAI,EAAE,eAAe,UAAU,eAAe;QAC9C,IAAI,EAAE,8DAA8D,UAAU,EAAE;QAEhF,KAAK,CAAC,OAAO;YACX,IAAI;gBACF,MAAM,OAAO,CAAC,IAAI,CAAC;oBACjB,MAAM,CAAC,KAAK,CAAC,gDAAgD,CAAC;oBAC9D,aAAa,CAAC,qBAAqB,CAAC;iBACrC,CAAC,CAAC;gBACH,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACb;YAAC,OAAO,KAAK,EAAE;gBACd,IAAY,KAAM,CAAC,OAAO,KAAK,2BAA2B,EAAE;oBAC1D,MAAM,CAAC,KAAK,CACV,kGAAkG,UAAU,sBAAsB,qBAAqB,KAAK,CAC7J,CAAC;iBACH;qBAAM;oBACL,MAAM,CAAC,KAAK,CAAQ,KAAK,EAAE,yBAAyB,CAAC,CAAC;iBACvD;gBAED,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACb;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AA9BW,QAAA,oCAAoC,wCA8B/C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axinom/mosaic-db-common",
3
- "version": "0.34.0-rc.10",
3
+ "version": "0.34.0-rc.11",
4
4
  "description": "This library encapsulates database-related functionality to develop Mosaic based services.",
5
5
  "author": "Axinom",
6
6
  "license": "PROPRIETARY",
@@ -34,7 +34,7 @@
34
34
  "graphile-migrate": "^1.4.0",
35
35
  "pg": "^8.11.3",
36
36
  "pg-logical-replication": "^2.0.3",
37
- "prom-client": "^13.2.0",
37
+ "prom-client": "^15.1.0",
38
38
  "readdirp": "^3.4.0",
39
39
  "yargs": "^16.2.0",
40
40
  "zapatos": "3.6.0"
@@ -53,5 +53,5 @@
53
53
  "publishConfig": {
54
54
  "access": "public"
55
55
  },
56
- "gitHead": "996702d66aaab62214cb3db5f20966918e6b1007"
56
+ "gitHead": "c9f280af27b6f60912a1f6a3dbe7952c00203672"
57
57
  }
@@ -1,9 +1,13 @@
1
1
  import { Pool } from 'pg';
2
2
  import { Gauge, Metric } from 'prom-client';
3
+ import { DbLogger } from '../common';
3
4
 
4
5
  const createTimeout = (timeoutInMilliSeconds: number): Promise<void> =>
5
6
  new Promise<void>((_, reject) =>
6
- setTimeout(() => reject(), timeoutInMilliSeconds),
7
+ setTimeout(
8
+ () => reject(new Error('METRIC_COLLECTION_TIMEOUT')),
9
+ timeoutInMilliSeconds,
10
+ ),
7
11
  );
8
12
 
9
13
  /**
@@ -17,6 +21,7 @@ const createTimeout = (timeoutInMilliSeconds: number): Promise<void> =>
17
21
  * @returns A `Gauge` metric with a name `ax_postgres_<pgPoolType>_connectivity`.
18
22
  */
19
23
  export const createPostgresPoolConnectivityMetric = (
24
+ logger: DbLogger,
20
25
  pgPool: Pool,
21
26
  pgPoolType: 'dbOwnerPool' | 'envOwnerPool' | 'loginPool',
22
27
  timeoutInMilliSeconds = 1000,
@@ -32,7 +37,15 @@ export const createPostgresPoolConnectivityMetric = (
32
37
  createTimeout(timeoutInMilliSeconds),
33
38
  ]);
34
39
  this.set(1);
35
- } catch {
40
+ } catch (error) {
41
+ if ((<Error>error).message === 'METRIC_COLLECTION_TIMEOUT') {
42
+ logger.error(
43
+ `A METRIC_COLLECTION_TIMEOUT error occurred while checking connectivity to the database via the ${pgPoolType} with a timeout of ${timeoutInMilliSeconds}ms.`,
44
+ );
45
+ } else {
46
+ logger.error(<Error>error, `METRIC_COLLECTION_ERROR`);
47
+ }
48
+
36
49
  this.set(0);
37
50
  }
38
51
  },