@canmingir/link-express 1.6.6 → 1.6.7

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/postgres.js +92 -87
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canmingir/link-express",
3
- "version": "1.6.6",
3
+ "version": "1.6.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "NucTeam",
package/src/postgres.js CHANGED
@@ -8,12 +8,15 @@ const { DBMetrics } = require("./metrics/dbMetrics");
8
8
  const {
9
9
  postgres: { uri, debug = false, sync },
10
10
  project,
11
- pushGateway,
11
+ metrics,
12
12
  } = config();
13
13
 
14
- const metrics = new DBMetrics();
14
+ let dbMetrics = null;
15
15
 
16
- metrics.startPushgateway(pushGateway);
16
+ if (metrics.enabled) {
17
+ dbMetrics = new DBMetrics();
18
+ dbMetrics.startPushgateway(metrics.pushGateway);
19
+ }
17
20
 
18
21
  const originalDestroy = Model.prototype.destroy;
19
22
 
@@ -32,91 +35,93 @@ const sequelize = new Sequelize(process.env.PG || uri, {
32
35
  timestamps: false,
33
36
  paranoid: false,
34
37
  },
35
- hooks: {
36
- beforeFind: (options = {}) => {
37
- const timer = metrics.dbReadLatency.startTimer();
38
- options.metricsTimer = timer;
39
- options.metricsType = "read";
40
- },
41
- afterFind: (result, options = {}) => {
42
- if (options?.metricsTimer) {
43
- options.metricsTimer();
44
- metrics.dbReadOps.inc();
45
- }
46
- },
47
-
48
- beforeCreate: (instance, options = {}) => {
49
- const timer = metrics.dbWriteLatency.startTimer();
50
- options.metricsTimer = timer;
51
- options.metricsType = "write";
52
- },
53
- afterCreate: (instance, options = {}) => {
54
- if (options?.metricsTimer) {
55
- options.metricsTimer();
56
- metrics.dbWriteOps.inc();
57
- }
58
- },
59
-
60
- beforeUpdate: (instance, options = {}) => {
61
- const timer = metrics.dbWriteLatency.startTimer();
62
- options.metricsTimer = timer;
63
- options.metricsType = "write";
64
- },
65
- afterUpdate: (instance, options = {}) => {
66
- if (options?.metricsTimer) {
67
- options.metricsTimer();
68
- metrics.dbWriteOps.inc();
69
- }
70
- },
71
-
72
- beforeDestroy: (instance, options = {}) => {
73
- const timer = metrics.dbWriteLatency.startTimer();
74
- options.metricsTimer = timer;
75
- options.metricsType = "write";
76
- },
77
- afterDestroy: (instance, options = {}) => {
78
- if (options?.metricsTimer) {
79
- options.metricsTimer();
80
- metrics.dbWriteOps.inc();
38
+ hooks: metrics.enabled
39
+ ? {
40
+ beforeFind: (options = {}) => {
41
+ const timer = dbMetrics.dbReadLatency.startTimer();
42
+ options.metricsTimer = timer;
43
+ options.metricsType = "read";
44
+ },
45
+ afterFind: (result, options = {}) => {
46
+ if (options?.metricsTimer) {
47
+ options.metricsTimer();
48
+ dbMetrics.dbReadOps.inc();
49
+ }
50
+ },
51
+
52
+ beforeCreate: (instance, options = {}) => {
53
+ const timer = dbMetrics.dbWriteLatency.startTimer();
54
+ options.metricsTimer = timer;
55
+ options.metricsType = "write";
56
+ },
57
+ afterCreate: (instance, options = {}) => {
58
+ if (options?.metricsTimer) {
59
+ options.metricsTimer();
60
+ dbMetrics.dbWriteOps.inc();
61
+ }
62
+ },
63
+
64
+ beforeUpdate: (instance, options = {}) => {
65
+ const timer = dbMetrics.dbWriteLatency.startTimer();
66
+ options.metricsTimer = timer;
67
+ options.metricsType = "write";
68
+ },
69
+ afterUpdate: (instance, options = {}) => {
70
+ if (options?.metricsTimer) {
71
+ options.metricsTimer();
72
+ dbMetrics.dbWriteOps.inc();
73
+ }
74
+ },
75
+
76
+ beforeDestroy: (instance, options = {}) => {
77
+ const timer = dbMetrics.dbWriteLatency.startTimer();
78
+ options.metricsTimer = timer;
79
+ options.metricsType = "write";
80
+ },
81
+ afterDestroy: (instance, options = {}) => {
82
+ if (options?.metricsTimer) {
83
+ options.metricsTimer();
84
+ dbMetrics.dbWriteOps.inc();
85
+ }
86
+ },
87
+
88
+ beforeBulkCreate: (instances, options = {}) => {
89
+ const timer = dbMetrics.dbWriteLatency.startTimer();
90
+ options.metricsTimer = timer;
91
+ options.metricsType = "write";
92
+ },
93
+ afterBulkCreate: (instances, options = {}) => {
94
+ if (options?.metricsTimer) {
95
+ options.metricsTimer();
96
+ dbMetrics.dbWriteOps.inc(instances.length || 1);
97
+ }
98
+ },
99
+
100
+ beforeBulkUpdate: (instances, options = {}) => {
101
+ const timer = dbMetrics.dbWriteLatency.startTimer();
102
+ options.metricsTimer = timer;
103
+ options.metricsType = "write";
104
+ },
105
+ afterBulkUpdate: (instances, options = {}) => {
106
+ if (options?.metricsTimer) {
107
+ options.metricsTimer();
108
+ dbMetrics.dbWriteOps.inc(instances.length || 1);
109
+ }
110
+ },
111
+
112
+ beforeBulkDestroy: (options = {}) => {
113
+ const timer = dbMetrics.dbWriteLatency.startTimer();
114
+ options.metricsTimer = timer;
115
+ options.metricsType = "write";
116
+ },
117
+ afterBulkDestroy: (options = {}) => {
118
+ if (options?.metricsTimer) {
119
+ options.metricsTimer();
120
+ dbMetrics.dbWriteOps.inc(1);
121
+ }
122
+ },
81
123
  }
82
- },
83
-
84
- beforeBulkCreate: (instances, options = {}) => {
85
- const timer = metrics.dbWriteLatency.startTimer();
86
- options.metricsTimer = timer;
87
- options.metricsType = "write";
88
- },
89
- afterBulkCreate: (instances, options = {}) => {
90
- if (options?.metricsTimer) {
91
- options.metricsTimer();
92
- metrics.dbWriteOps.inc(instances.length || 1);
93
- }
94
- },
95
-
96
- beforeBulkUpdate: (instances, options = {}) => {
97
- const timer = metrics.dbWriteLatency.startTimer();
98
- options.metricsTimer = timer;
99
- options.metricsType = "write";
100
- },
101
- afterBulkUpdate: (instances, options = {}) => {
102
- if (options?.metricsTimer) {
103
- options.metricsTimer();
104
- metrics.dbWriteOps.inc(instances.length || 1);
105
- }
106
- },
107
-
108
- beforeBulkDestroy: (options = {}) => {
109
- const timer = metrics.dbWriteLatency.startTimer();
110
- options.metricsTimer = timer;
111
- options.metricsType = "write";
112
- },
113
- afterBulkDestroy: (options = {}) => {
114
- if (options?.metricsTimer) {
115
- options.metricsTimer();
116
- metrics.dbWriteOps.inc(1);
117
- }
118
- },
119
- },
124
+ : {},
120
125
  });
121
126
 
122
127
  const seed = async () => {