@axinom/mosaic-db-common 0.34.0-rc.1 → 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.
- package/dist/messaging/messaging-counter.d.ts +1 -0
- package/dist/messaging/messaging-counter.d.ts.map +1 -1
- package/dist/messaging/messaging-counter.js +1 -0
- package/dist/messaging/messaging-counter.js.map +1 -1
- package/dist/monitoring/postgres-metrics.d.ts +2 -1
- package/dist/monitoring/postgres-metrics.d.ts.map +1 -1
- package/dist/monitoring/postgres-metrics.js +9 -3
- package/dist/monitoring/postgres-metrics.js.map +1 -1
- package/migrations/define/define-functions.sql +40 -0
- package/package.json +3 -3
- package/src/messaging/messaging-counter.ts +1 -0
- package/src/monitoring/postgres-metrics.ts +15 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messaging-counter.d.ts","sourceRoot":"","sources":["../../src/messaging/messaging-counter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAyC9C,MAAM,WAAW,wBAAwB;IACvC,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChE;AAED;;;GAGG;AACH,eAAO,MAAM,+BAA+B,cAC/B,WAAW,KACrB,QAAQ,IAAI,CAQd,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"messaging-counter.d.ts","sourceRoot":"","sources":["../../src/messaging/messaging-counter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAyC9C,MAAM,WAAW,wBAAwB;IACvC,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChE;AAED;;;GAGG;AACH,eAAO,MAAM,+BAA+B,cAC/B,WAAW,KACrB,QAAQ,IAAI,CAQd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AAE;QAClB,MAAM,8BAA8B,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,+BAA+B,mCAU1C;AAEF
|
|
1
|
+
{"version":3,"file":"messaging-counter.js","sourceRoot":"","sources":["../../src/messaging/messaging-counter.ts"],"names":[],"mappings":";;;AAAA,mCAA+E;AAG/E,MAAM,sBAAsB,GAAG,KAAK,EAClC,GAAW,EACX,SAAsB,EACL,EAAE;IACnB,OAAO,IAAA,gBAAW,EAChB,SAAS,EACT,mBAAc,CAAC,YAAY,EAC3B,KAAK,EAAE,SAAS,EAAE,EAAE;QAClB,MAAM,UAAU,GAAG;YACjB,GAAG,EAAE,GAAG;SACT,CAAC;QACF,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,MAAM,IAAA,QAAG,EAAA;;oBAEjB,IAAA,SAAI,EAAC,UAAU,CAAC;;;;;;OAM7B,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAEjB,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,EAAE;YACxB,wDAAwD;YACxD,4GAA4G;YAC5G,MAAM,8BAA8B,CAAC,SAAS,CAAC,CAAC;SACjD;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,8BAA8B,GAAG,KAAK,EAC1C,SAAiD,EAClC,EAAE;IACjB,MAAM,IAAA,QAAG,EAAA,qFAAqF,CAAC,GAAG,CAChG,SAAS,CACV,CAAC;AACJ,CAAC,CAAC;AAMF;;;GAGG;AACI,MAAM,+BAA+B,GAAG,KAAK,EAClD,SAAsB,EACP,EAAE;IACjB,MAAM,IAAA,gBAAW,EACf,SAAS,EACT,mBAAc,CAAC,YAAY,EAC3B,KAAK,EAAE,SAAS,EAAE,EAAE;QAClB,MAAM,8BAA8B,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,+BAA+B,mCAU1C;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EG;AACI,MAAM,oBAAoB,GAAG,CAAC,SAAsB,EAAE,EAAE;IAC7D,OAAO,SAAS,IAAI;QAGlB,OAAO;YACL,eAAe,EAAE,UAAU,GAAW,EAAE,IAA8B;gBACpE,sBAAsB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,IAAI,CACzC,CAAC,OAAe,EAAE,EAAE;oBAClB,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBACtB,CAAC,EACD,CAAC,GAAU,EAAE,EAAE;oBACb,IAAI,GAAG,EAAE;wBACP,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;qBAClB;gBACH,CAAC,CACF,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,oBAAoB,wBAmB/B"}
|
|
@@ -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;
|
|
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 (
|
|
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;
|
|
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"}
|
|
@@ -854,6 +854,46 @@ BEGIN
|
|
|
854
854
|
END;
|
|
855
855
|
$$;
|
|
856
856
|
|
|
857
|
+
/*-snippet
|
|
858
|
+
{
|
|
859
|
+
"body": [
|
|
860
|
+
"SELECT ax_define.create_messaging_health_monitorying();"
|
|
861
|
+
],
|
|
862
|
+
"description": [
|
|
863
|
+
"Creates a table that will store a key when a health check is conducted and triggers to notify the application about updates in that table."
|
|
864
|
+
]
|
|
865
|
+
}
|
|
866
|
+
snippet-*/
|
|
867
|
+
CREATE OR REPLACE FUNCTION ax_define.create_messaging_health_monitoring()
|
|
868
|
+
RETURNS void LANGUAGE plpgsql AS $$
|
|
869
|
+
BEGIN
|
|
870
|
+
|
|
871
|
+
EXECUTE 'DROP TABLE IF EXISTS app_private.messaging_health CASCADE;';
|
|
872
|
+
EXECUTE '
|
|
873
|
+
CREATE TABLE app_private.messaging_health (
|
|
874
|
+
key TEXT PRIMARY KEY,
|
|
875
|
+
success BOOLEAN
|
|
876
|
+
);';
|
|
877
|
+
|
|
878
|
+
EXECUTE 'CREATE OR REPLACE FUNCTION app_private.messaging_health_notify()
|
|
879
|
+
RETURNS trigger
|
|
880
|
+
LANGUAGE plpgsql
|
|
881
|
+
AS $function$
|
|
882
|
+
BEGIN
|
|
883
|
+
PERFORM pg_notify(''messaging_health_handled'', row_to_json(NEW)::text);
|
|
884
|
+
RETURN NULL;
|
|
885
|
+
END;
|
|
886
|
+
$function$ ';
|
|
887
|
+
|
|
888
|
+
EXECUTE 'DROP TRIGGER IF EXISTS _500_messaging_health_trigger ON app_private.messaging_health;';
|
|
889
|
+
EXECUTE 'CREATE trigger _500_messaging_health_trigger
|
|
890
|
+
AFTER UPDATE ON app_private.messaging_health
|
|
891
|
+
FOR EACH ROW EXECUTE PROCEDURE app_private.messaging_health_notify();';
|
|
892
|
+
|
|
893
|
+
END;
|
|
894
|
+
$$;
|
|
895
|
+
|
|
896
|
+
|
|
857
897
|
/*-snippet
|
|
858
898
|
{
|
|
859
899
|
"body": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-db-common",
|
|
3
|
-
"version": "0.34.0-rc.
|
|
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": "^
|
|
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": "
|
|
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(
|
|
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
|
},
|