@axinom/mosaic-db-common 0.38.0-rc.0 → 0.38.0-rc.2

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.
@@ -7,8 +7,8 @@ import { DbLogger } from '../common';
7
7
  * or a value of `0` otherwise.
8
8
  *
9
9
  * @param pgPool The Postgres Pool to use for checking the connectivity. The connectivity test will be done at the point of metric collection.
10
- * @param pgPoolType The Postgres Pool to check connectivity for. The connectivity test will be done at the point of metric collection.
11
- * @param timeoutInMilliSeconds The maximum time the connectivity check will run during metric collection. Defaults to `1000ms`.
10
+ * @param pgPoolType The Postgres Pool to check connectivity for.
11
+ * @param timeoutInMilliSeconds The maximum time the connectivity check will run during metric collection. Defaults to `10000ms`.
12
12
  * @returns A `Gauge` metric with a name `ax_postgres_<pgPoolType>_connectivity`.
13
13
  */
14
14
  export declare const createPostgresPoolConnectivityMetric: (logger: DbLogger, pgPool: Pool, pgPoolType: 'dbOwnerPool' | 'envOwnerPool' | 'loginPool', timeoutInMilliSeconds?: number) => Metric<string>;
@@ -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;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"}
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,CA2Bf,CAAC"}
@@ -9,21 +9,23 @@ const createTimeout = (timeoutInMilliSeconds) => new Promise((_, reject) => setT
9
9
  * or a value of `0` otherwise.
10
10
  *
11
11
  * @param pgPool The Postgres Pool to use for checking the connectivity. The connectivity test will be done at the point of metric collection.
12
- * @param pgPoolType The Postgres Pool to check connectivity for. The connectivity test will be done at the point of metric collection.
13
- * @param timeoutInMilliSeconds The maximum time the connectivity check will run during metric collection. Defaults to `1000ms`.
12
+ * @param pgPoolType The Postgres Pool to check connectivity for.
13
+ * @param timeoutInMilliSeconds The maximum time the connectivity check will run during metric collection. Defaults to `10000ms`.
14
14
  * @returns A `Gauge` metric with a name `ax_postgres_<pgPoolType>_connectivity`.
15
15
  */
16
- const createPostgresPoolConnectivityMetric = (logger, pgPool, pgPoolType, timeoutInMilliSeconds = 1000) => {
16
+ const createPostgresPoolConnectivityMetric = (logger, pgPool, pgPoolType, timeoutInMilliSeconds = 10000) => {
17
17
  return new prom_client_1.Gauge({
18
18
  name: `ax_postgres_${pgPoolType}_connectivity`,
19
- help: `Connection status from the service to the database via the ${pgPoolType}`,
19
+ help: `Connection time from the service to the database via the ${pgPoolType} in milliseconds`,
20
20
  async collect() {
21
21
  try {
22
+ const startTime = process.hrtime();
22
23
  await Promise.race([
23
24
  pgPool.query(`SELECT NOW() AS PostgresPoolConnectivityMetric`),
24
25
  createTimeout(timeoutInMilliSeconds),
25
26
  ]);
26
- this.set(1);
27
+ const duration = process.hrtime(startTime);
28
+ this.set(duration[1] / 1e6);
27
29
  }
28
30
  catch (error) {
29
31
  if (error.message === 'METRIC_COLLECTION_TIMEOUT') {
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"postgres-metrics.js","sourceRoot":"","sources":["../../src/monitoring/postgres-metrics.ts"],"names":[],"mappings":";;;AACA,6CAA4C;AAG5C,MAAM,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 @@
1
1
  {
2
2
  "name": "@axinom/mosaic-db-common",
3
- "version": "0.38.0-rc.0",
3
+ "version": "0.38.0-rc.2",
4
4
  "description": "This library encapsulates database-related functionality to develop Mosaic based services.",
5
5
  "author": "Axinom",
6
6
  "license": "PROPRIETARY",
@@ -54,5 +54,5 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  },
57
- "gitHead": "c759240b5649f2b249b94193c2b10823bee383be"
57
+ "gitHead": "4918cf4edaf640b1ef1c26aa983bc6a41d691c83"
58
58
  }
@@ -16,27 +16,29 @@ const createTimeout = (timeoutInMilliSeconds: number): Promise<void> =>
16
16
  * or a value of `0` otherwise.
17
17
  *
18
18
  * @param pgPool The Postgres Pool to use for checking the connectivity. The connectivity test will be done at the point of metric collection.
19
- * @param pgPoolType The Postgres Pool to check connectivity for. The connectivity test will be done at the point of metric collection.
20
- * @param timeoutInMilliSeconds The maximum time the connectivity check will run during metric collection. Defaults to `1000ms`.
19
+ * @param pgPoolType The Postgres Pool to check connectivity for.
20
+ * @param timeoutInMilliSeconds The maximum time the connectivity check will run during metric collection. Defaults to `10000ms`.
21
21
  * @returns A `Gauge` metric with a name `ax_postgres_<pgPoolType>_connectivity`.
22
22
  */
23
23
  export const createPostgresPoolConnectivityMetric = (
24
24
  logger: DbLogger,
25
25
  pgPool: Pool,
26
26
  pgPoolType: 'dbOwnerPool' | 'envOwnerPool' | 'loginPool',
27
- timeoutInMilliSeconds = 1000,
27
+ timeoutInMilliSeconds = 10000,
28
28
  ): Metric<string> => {
29
29
  return new Gauge({
30
30
  name: `ax_postgres_${pgPoolType}_connectivity`,
31
- help: `Connection status from the service to the database via the ${pgPoolType}`,
31
+ help: `Connection time from the service to the database via the ${pgPoolType} in milliseconds`,
32
32
 
33
33
  async collect() {
34
34
  try {
35
+ const startTime = process.hrtime();
35
36
  await Promise.race([
36
37
  pgPool.query(`SELECT NOW() AS PostgresPoolConnectivityMetric`),
37
38
  createTimeout(timeoutInMilliSeconds),
38
39
  ]);
39
- this.set(1);
40
+ const duration = process.hrtime(startTime);
41
+ this.set(duration[1] / 1e6);
40
42
  } catch (error) {
41
43
  if ((<Error>error).message === 'METRIC_COLLECTION_TIMEOUT') {
42
44
  logger.error(