@adalo/metrics 0.0.0-staging.1

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 (85) hide show
  1. package/.env.example +14 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc +61 -0
  4. package/.github/pull_request_template.md +14 -0
  5. package/.github/workflows/code-style.yml +29 -0
  6. package/.github/workflows/deploy-staging.yml +34 -0
  7. package/.github/workflows/deploy.yml +29 -0
  8. package/.github/workflows/tests.yml +17 -0
  9. package/.idea/codeStyles/Project.xml +101 -0
  10. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  11. package/.idea/git_toolbox_prj.xml +15 -0
  12. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  13. package/.idea/jsLibraryMappings.xml +6 -0
  14. package/.idea/prettier.xml +6 -0
  15. package/.idea/vcs.xml +6 -0
  16. package/.prettierrc +10 -0
  17. package/README-health.md +234 -0
  18. package/README.md +120 -0
  19. package/__tests__/metricsRedisClient.test.js +138 -0
  20. package/babel.config.js +20 -0
  21. package/lib/health/databaseChecker.d.ts +43 -0
  22. package/lib/health/databaseChecker.d.ts.map +1 -0
  23. package/lib/health/databaseChecker.js +189 -0
  24. package/lib/health/databaseChecker.js.map +1 -0
  25. package/lib/health/healthCheckCache.d.ts +59 -0
  26. package/lib/health/healthCheckCache.d.ts.map +1 -0
  27. package/lib/health/healthCheckCache.js +187 -0
  28. package/lib/health/healthCheckCache.js.map +1 -0
  29. package/lib/health/healthCheckClient.d.ts +124 -0
  30. package/lib/health/healthCheckClient.d.ts.map +1 -0
  31. package/lib/health/healthCheckClient.js +324 -0
  32. package/lib/health/healthCheckClient.js.map +1 -0
  33. package/lib/health/healthCheckUtils.d.ts +52 -0
  34. package/lib/health/healthCheckUtils.d.ts.map +1 -0
  35. package/lib/health/healthCheckUtils.js +129 -0
  36. package/lib/health/healthCheckUtils.js.map +1 -0
  37. package/lib/health/healthCheckWorker.d.ts +2 -0
  38. package/lib/health/healthCheckWorker.d.ts.map +1 -0
  39. package/lib/health/healthCheckWorker.js +70 -0
  40. package/lib/health/healthCheckWorker.js.map +1 -0
  41. package/lib/index.d.ts +10 -0
  42. package/lib/index.d.ts.map +1 -0
  43. package/lib/index.js +105 -0
  44. package/lib/index.js.map +1 -0
  45. package/lib/metrics/baseMetricsClient.d.ts +174 -0
  46. package/lib/metrics/baseMetricsClient.d.ts.map +1 -0
  47. package/lib/metrics/baseMetricsClient.js +428 -0
  48. package/lib/metrics/baseMetricsClient.js.map +1 -0
  49. package/lib/metrics/metricsClient.d.ts +95 -0
  50. package/lib/metrics/metricsClient.d.ts.map +1 -0
  51. package/lib/metrics/metricsClient.js +239 -0
  52. package/lib/metrics/metricsClient.js.map +1 -0
  53. package/lib/metrics/metricsDatabaseClient.d.ts +74 -0
  54. package/lib/metrics/metricsDatabaseClient.d.ts.map +1 -0
  55. package/lib/metrics/metricsDatabaseClient.js +218 -0
  56. package/lib/metrics/metricsDatabaseClient.js.map +1 -0
  57. package/lib/metrics/metricsQueueRedisClient.d.ts +57 -0
  58. package/lib/metrics/metricsQueueRedisClient.d.ts.map +1 -0
  59. package/lib/metrics/metricsQueueRedisClient.js +277 -0
  60. package/lib/metrics/metricsQueueRedisClient.js.map +1 -0
  61. package/lib/metrics/metricsRedisClient.d.ts +71 -0
  62. package/lib/metrics/metricsRedisClient.d.ts.map +1 -0
  63. package/lib/metrics/metricsRedisClient.js +370 -0
  64. package/lib/metrics/metricsRedisClient.js.map +1 -0
  65. package/lib/redisUtils.d.ts +53 -0
  66. package/lib/redisUtils.d.ts.map +1 -0
  67. package/lib/redisUtils.js +140 -0
  68. package/lib/redisUtils.js.map +1 -0
  69. package/package.json +66 -0
  70. package/scripts/README.md +43 -0
  71. package/scripts/clearMetrics.js +6 -0
  72. package/src/health/databaseChecker.js +183 -0
  73. package/src/health/healthCheckCache.js +216 -0
  74. package/src/health/healthCheckClient.js +347 -0
  75. package/src/health/healthCheckUtils.js +125 -0
  76. package/src/health/healthCheckWorker.js +71 -0
  77. package/src/index.ts +9 -0
  78. package/src/metrics/baseMetricsClient.js +494 -0
  79. package/src/metrics/metricsClient.js +284 -0
  80. package/src/metrics/metricsDatabaseClient.js +236 -0
  81. package/src/metrics/metricsQueueRedisClient.js +352 -0
  82. package/src/metrics/metricsRedisClient.js +417 -0
  83. package/src/redisUtils.js +155 -0
  84. package/tsconfig.json +19 -0
  85. package/tsconfig.types.json +11 -0
@@ -0,0 +1,370 @@
1
+ "use strict";
2
+
3
+ const {
4
+ BaseMetricsClient
5
+ } = require('./baseMetricsClient');
6
+ const {
7
+ getRedisClientType,
8
+ REDIS_V4,
9
+ IOREDIS,
10
+ REDIS_V3
11
+ } = require('../redisUtils');
12
+ const redisConnectionStableFields = ['name', 'flags', 'cmd'];
13
+ const redisConnectionFields = ['name', 'flags', 'tot-mem', 'cmd'];
14
+
15
+ /**
16
+ * RedisMetricsClient extends BaseMetricsClient to collect
17
+ * Redis metrics periodically and push them to Prometheus Pushgateway.
18
+ *
19
+ * @extends BaseMetricsClient
20
+ */
21
+ class RedisMetricsClient extends BaseMetricsClient {
22
+ /**
23
+ * @param {Object} options
24
+ * @param {any} options.redisClient - Redis client instance (required)
25
+ * @param {string} [options.appName] - Application name (from BaseMetricsClient)
26
+ * @param {string} [options.dynoId] - Dyno/instance ID (from BaseMetricsClient)
27
+ * @param {string} [options.processType] - Process type (from BaseMetricsClient)
28
+ * @param {boolean} [options.enabled] - Enable metrics collection (from BaseMetricsClient)
29
+ * @param {boolean} [options.logValues] - Log metrics values (from BaseMetricsClient)
30
+ * @param {string} [options.pushgatewayUrl] - PushGateway URL (from BaseMetricsClient)
31
+ * @param {string} [options.pushgatewaySecret] - PushGateway secret token (from BaseMetricsClient)
32
+ * @param {number} [options.intervalSec] - Interval in seconds for pushing metrics (from BaseMetricsClient)
33
+ * @param {boolean} [options.removeOldMetrics] - Remove old metrics by service (from BaseMetricsClient)
34
+ * @param {function} [options.startupValidation] - Function to validate startup (from BaseMetricsClient)
35
+ * @param {boolean} [options.disablePushgateway] - Disable pushing to Pushgateway (use HTTP scraping instead)
36
+ */
37
+ constructor({
38
+ redisClient,
39
+ ...metricsConfig
40
+ } = {}) {
41
+ if (redisClient == null) {
42
+ throw new Error('RedisMetricsClient requires redisClient');
43
+ }
44
+ const intervalSec = metricsConfig.intervalSec || parseInt(process.env.METRICS_QUEUE_INTERVAL_SEC || '', 10) || 5;
45
+ super({
46
+ ...metricsConfig,
47
+ processType: metricsConfig.processType || 'queue-metrics',
48
+ intervalSec
49
+ });
50
+
51
+ /** Redis client used for metrics */
52
+ this.redisClient = redisClient;
53
+ this.redisClientType = getRedisClientType(redisClient);
54
+
55
+ /** Label names for Redis metrics: app + process_type only (no dyno_id). */
56
+ this._redisLabelNames = ['app', 'process_type'];
57
+
58
+ /** Counter for Redis connection metrics */
59
+ this.redisConnectionsGauge = this.createGauge({
60
+ name: 'app_redis_connections_count',
61
+ help: 'Redis client connections',
62
+ labelNames: [...this._redisLabelNames, ...redisConnectionStableFields]
63
+ });
64
+ this.redisConnectionsMemoryGauge = this.createGauge({
65
+ name: 'app_redis_connections_memory_usage_count',
66
+ help: 'Redis client connections',
67
+ labelNames: [...this._redisLabelNames, ...redisConnectionStableFields]
68
+ });
69
+
70
+ /** Gauge for Redis memory usage */
71
+ this.redisMemoryGauge = this.createGauge({
72
+ name: 'app_redis_memory_bytes',
73
+ help: 'Redis memory usage in bytes',
74
+ labelNames: [...this._redisLabelNames, 'memory_type']
75
+ });
76
+
77
+ /** Gauge for Redis operation stats */
78
+ this.redisStatsGauge = this.createGauge({
79
+ name: 'app_redis_stats_total',
80
+ help: 'Redis operation statistics',
81
+ labelNames: [...this._redisLabelNames, 'operation']
82
+ });
83
+
84
+ // Track emitted connection label combinations so we can:
85
+ // - emit a one-shot 0 for series that disappear (overwrite last non-zero sample)
86
+ // - then stop emitting them on subsequent scrapes
87
+ //
88
+ // This is mainly needed because we label connections by `cmd`,
89
+ // and Redis `CLIENT LIST` `cmd` is volatile.
90
+ this._redisConnSeenKeys = new Set();
91
+ this._redisConnZeroedKeys = new Set();
92
+ this._setCleanupHandlers();
93
+ }
94
+ getRedisConnections = async () => {
95
+ if (!this.redisClient) throw new Error('Redis client not provided');
96
+
97
+ // node-redis v3 (uses callback)
98
+ if (this.redisClientType === REDIS_V3) {
99
+ return new Promise((resolve, reject) => {
100
+ this.redisClient.send_command('CLIENT', ['LIST'], (err, result) => {
101
+ if (err) {
102
+ reject(new Error(`Failed to get CLIENT LIST: ${err.message}`));
103
+ } else resolve(result);
104
+ });
105
+ });
106
+ }
107
+
108
+ // node-redis v4
109
+ if (this.redisClientType === REDIS_V4) {
110
+ try {
111
+ return this.redisClient.sendCommand(['CLIENT', 'LIST']);
112
+ } catch (err) {
113
+ throw new Error(`Failed to get CLIENT LIST: ${err.message}`);
114
+ }
115
+ }
116
+ if (this.redisClientType === IOREDIS) {
117
+ try {
118
+ return this.redisClient.client('LIST');
119
+ } catch (err) {
120
+ throw new Error(`Failed to get CLIENT LIST: ${err.message}`);
121
+ }
122
+ }
123
+ throw new Error('Unsupported Redis client type');
124
+ };
125
+ getRedisInfo = async section => {
126
+ if (!this.redisClient) throw new Error('Redis client not provided');
127
+
128
+ // node-redis v3 (uses callback)
129
+ if (this.redisClientType === REDIS_V3) {
130
+ return new Promise((resolve, reject) => {
131
+ this.redisClient.info(section, (err, result) => {
132
+ if (err) reject(err);else resolve(result);
133
+ });
134
+ });
135
+ }
136
+
137
+ // node-redis v4 or ioredis (info returns Promise)
138
+ if (this.redisClientType === REDIS_V4 || this.redisClientType === IOREDIS) {
139
+ try {
140
+ return this.redisClient.info(section);
141
+ } catch (err) {
142
+ throw new Error(`Failed to get Redis INFO: ${err.message}`);
143
+ }
144
+ }
145
+ throw new Error('Unsupported Redis client type');
146
+ };
147
+ parseRedisConnections = clientsStr => {
148
+ return clientsStr.split('\n').filter(line => line.trim() !== '').map(line => {
149
+ const parts = line.split(' ');
150
+ const client = {};
151
+ parts.forEach(p => {
152
+ const eqIdx = p.indexOf('=');
153
+ if (eqIdx === -1) return;
154
+ const k = p.slice(0, eqIdx);
155
+ const v = p.slice(eqIdx + 1);
156
+ if (redisConnectionFields.includes(k)) {
157
+ client[k] = v;
158
+ }
159
+ });
160
+ return client;
161
+ });
162
+ };
163
+
164
+ /**
165
+ * Collect basic Redis INFO metrics: clients, memory, stats
166
+ * @returns {Promise<void>}
167
+ */
168
+ collectRedisMetrics = async () => {
169
+ try {
170
+ const [memoryInfoStr, statsInfoStr, connectionsInfoStr] = await Promise.all([this.getRedisInfo('memory'), this.getRedisInfo('stats'), this.getRedisConnections()]);
171
+ const labels = {
172
+ app: this.appName,
173
+ process_type: this.processType
174
+ };
175
+ const connections = this.parseRedisConnections(connectionsInfoStr);
176
+ if (this.logValues) {
177
+ // "IN" data: raw client list from Redis
178
+ console.log('[queue-metrics] Redis CLIENT LIST (raw):\n', connectionsInfoStr);
179
+ console.log('[queue-metrics] Redis CLIENT LIST (raw) length:', connectionsInfoStr.length);
180
+
181
+ // "OUT" data: parsed fields used for metrics
182
+ console.log('[queue-metrics] Redis CLIENT LIST (parsed) count:', connections.length);
183
+ console.log('[queue-metrics] Redis CLIENT LIST (parsed sample, first 10):', JSON.stringify(connections.slice(0, 10), null, 2));
184
+ const missing = {
185
+ name: 0,
186
+ flags: 0,
187
+ cmd: 0,
188
+ 'tot-mem': 0
189
+ };
190
+ connections.forEach(c => {
191
+ if (!c.name) missing.name += 1;
192
+ if (!c.flags) missing.flags += 1;
193
+ if (!c.cmd) missing.cmd += 1;
194
+ if (!c['tot-mem']) missing['tot-mem'] += 1;
195
+ });
196
+ console.log('[queue-metrics] Redis CLIENT LIST (parsed) missing fields:', missing);
197
+ }
198
+ const grouped = {};
199
+ connections.forEach(conn => {
200
+ const {
201
+ name,
202
+ flags,
203
+ 'tot-mem': totMem,
204
+ cmd
205
+ } = conn;
206
+
207
+ // build grouping key (includes default gauge labels later)
208
+ const key = JSON.stringify({
209
+ name,
210
+ flags,
211
+ cmd
212
+ });
213
+ if (!grouped[key]) {
214
+ grouped[key] = {
215
+ labels: {
216
+ name,
217
+ flags,
218
+ cmd
219
+ },
220
+ count: 0,
221
+ memory: 0
222
+ };
223
+ }
224
+ grouped[key].count += 1;
225
+ const mem = parseInt(totMem, 10);
226
+ grouped[key].memory += Number.isFinite(mem) ? mem : 0;
227
+ });
228
+
229
+ // Ensure sets exist even if older instance is hot-reloaded.
230
+ if (!this._redisConnSeenKeys) this._redisConnSeenKeys = new Set();
231
+ if (!this._redisConnZeroedKeys) this._redisConnZeroedKeys = new Set();
232
+ const currentKeys = new Set(Object.keys(grouped));
233
+ for (const k of currentKeys) {
234
+ this._redisConnSeenKeys.add(k);
235
+ if (this._redisConnZeroedKeys.has(k)) {
236
+ this._redisConnZeroedKeys.delete(k);
237
+ }
238
+ }
239
+
240
+ // Reset gauges each scrape so we only export:
241
+ // - current snapshot series
242
+ // - one-shot zeros for recently disappeared series
243
+ this.redisConnectionsGauge.reset();
244
+ this.redisConnectionsMemoryGauge.reset();
245
+
246
+ // Emit one-shot zeros for series that disappeared since last seen.
247
+ for (const k of this._redisConnSeenKeys) {
248
+ if (currentKeys.has(k)) continue;
249
+ if (this._redisConnZeroedKeys.has(k)) continue;
250
+ try {
251
+ const valueLabels = JSON.parse(k);
252
+ this.redisConnectionsGauge.set({
253
+ ...labels,
254
+ ...valueLabels
255
+ }, 0);
256
+ this.redisConnectionsMemoryGauge.set({
257
+ ...labels,
258
+ ...valueLabels
259
+ }, 0);
260
+ this._redisConnZeroedKeys.add(k);
261
+ } catch {
262
+ // ignore malformed key
263
+ }
264
+ }
265
+ if (this.logValues) {
266
+ const groups = Object.values(grouped);
267
+ const groupedTotal = groups.reduce((sum, g) => sum + (g.count || 0), 0);
268
+ console.log('[queue-metrics] Redis connections grouped buckets:', groups.length);
269
+ console.log('[queue-metrics] Redis connections grouped total:', groupedTotal);
270
+ console.log('[queue-metrics] Redis connections seen keys:', this._redisConnSeenKeys.size);
271
+ console.log('[queue-metrics] Redis connections zeroed keys:', this._redisConnZeroedKeys.size);
272
+ console.log('[queue-metrics] Redis connections grouped sample (first 10):', JSON.stringify(groups.slice(0, 10), null, 2));
273
+ }
274
+ Object.values(grouped).forEach(({
275
+ labels: valueLabels,
276
+ count,
277
+ memory
278
+ }) => {
279
+ this.redisConnectionsGauge.set({
280
+ ...labels,
281
+ ...valueLabels
282
+ }, count);
283
+ this.redisConnectionsMemoryGauge.set({
284
+ ...labels,
285
+ ...valueLabels
286
+ }, memory);
287
+ });
288
+ const parseRedisInfo = infoStr => Object.fromEntries(infoStr.split('\r\n').filter(line => line && !line.startsWith('#')).map(line => line.split(':', 2)).filter(parts => parts.length === 2 && parts[0] && parts[1]));
289
+ const memory = parseRedisInfo(memoryInfoStr);
290
+ const stats = parseRedisInfo(statsInfoStr);
291
+ if (memory.used_memory) {
292
+ this.redisMemoryGauge.set({
293
+ ...labels,
294
+ memory_type: 'used'
295
+ }, parseInt(memory.used_memory, 10) || 0);
296
+ }
297
+ if (memory.maxmemory) {
298
+ this.redisMemoryGauge.set({
299
+ ...labels,
300
+ memory_type: 'max'
301
+ }, parseInt(memory.maxmemory, 10) || 0);
302
+ }
303
+ if (stats.instantaneous_ops_per_sec) {
304
+ this.redisStatsGauge.set({
305
+ ...labels,
306
+ operation: 'ops_per_sec'
307
+ }, parseInt(stats.instantaneous_ops_per_sec, 10) || 0);
308
+ }
309
+ } catch (error) {
310
+ console.warn(`[queue-metrics] Failed to collect Redis metrics:`, error.message);
311
+ }
312
+ };
313
+
314
+ /**
315
+ * Collect metrics for all Redis and push to Prometheus Pushgateway
316
+ * @returns {Promise<void>}
317
+ */
318
+ pushRedisMetrics = async () => {
319
+ try {
320
+ await this.collectRedisMetrics();
321
+ await this.gatewayPush();
322
+ this.clearAllCounters();
323
+ if (this.metricsLogValues) {
324
+ const metricObjects = await this.registry.getMetricsAsJSON();
325
+ console.info(`[queue-metrics] Collected metrics for Redis`, JSON.stringify(metricObjects, null, 2));
326
+ }
327
+ } catch (error) {
328
+ console.error(`[queue-metrics] Failed to collect Redis metrics: ${error.message}`);
329
+ throw error;
330
+ }
331
+ };
332
+
333
+ /**
334
+ * Start periodic collection.
335
+ * @param {number} [intervalSec=this.intervalSec] - Interval in seconds
336
+ */
337
+ startPush = (intervalSec = this.intervalSec) => {
338
+ this._startPush(intervalSec, () => {
339
+ this.pushRedisMetrics().catch(err => {
340
+ console.error(`[queue-metrics] Failed to push Redis metrics:`, err);
341
+ });
342
+ });
343
+ };
344
+
345
+ /**
346
+ * Cleanup Redis client and exit process.
347
+ * @returns {Promise<void>}
348
+ */
349
+ cleanup = async () => {
350
+ try {
351
+ if (!this.redisClient) return;
352
+ if (this.redisClientType === REDIS_V3 || this.redisClientType === REDIS_V4) {
353
+ await this.redisClient.quit();
354
+ } else if (this.redisClientType === IOREDIS) {
355
+ await this.redisClient.disconnect();
356
+ }
357
+ } catch (err) {
358
+ console.error('[queue-metrics] Error closing Redis client:', err);
359
+ }
360
+ process.exit(0);
361
+ };
362
+ _setCleanupHandlers = () => {
363
+ process.on('SIGINT', this.cleanup);
364
+ process.on('SIGTERM', this.cleanup);
365
+ };
366
+ }
367
+ module.exports = {
368
+ RedisMetricsClient
369
+ };
370
+ //# sourceMappingURL=metricsRedisClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metricsRedisClient.js","names":["BaseMetricsClient","require","getRedisClientType","REDIS_V4","IOREDIS","REDIS_V3","redisConnectionStableFields","redisConnectionFields","RedisMetricsClient","constructor","redisClient","metricsConfig","Error","intervalSec","parseInt","process","env","METRICS_QUEUE_INTERVAL_SEC","processType","redisClientType","_redisLabelNames","redisConnectionsGauge","createGauge","name","help","labelNames","redisConnectionsMemoryGauge","redisMemoryGauge","redisStatsGauge","_redisConnSeenKeys","Set","_redisConnZeroedKeys","_setCleanupHandlers","getRedisConnections","Promise","resolve","reject","send_command","err","result","message","sendCommand","client","getRedisInfo","section","info","parseRedisConnections","clientsStr","split","filter","line","trim","map","parts","forEach","p","eqIdx","indexOf","k","slice","v","includes","collectRedisMetrics","memoryInfoStr","statsInfoStr","connectionsInfoStr","all","labels","app","appName","process_type","connections","logValues","console","log","length","JSON","stringify","missing","flags","cmd","c","grouped","conn","totMem","key","count","memory","mem","Number","isFinite","currentKeys","Object","keys","add","has","delete","reset","valueLabels","parse","set","groups","values","groupedTotal","reduce","sum","g","size","parseRedisInfo","infoStr","fromEntries","startsWith","stats","used_memory","memory_type","maxmemory","instantaneous_ops_per_sec","operation","error","warn","pushRedisMetrics","gatewayPush","clearAllCounters","metricsLogValues","metricObjects","registry","getMetricsAsJSON","startPush","_startPush","catch","cleanup","quit","disconnect","exit","on","module","exports"],"sources":["../../src/metrics/metricsRedisClient.js"],"sourcesContent":["const { BaseMetricsClient } = require('./baseMetricsClient')\nconst {\n getRedisClientType,\n REDIS_V4,\n IOREDIS,\n REDIS_V3,\n} = require('../redisUtils')\n\nconst redisConnectionStableFields = ['name', 'flags', 'cmd']\nconst redisConnectionFields = ['name', 'flags', 'tot-mem', 'cmd']\n\n/**\n * RedisMetricsClient extends BaseMetricsClient to collect\n * Redis metrics periodically and push them to Prometheus Pushgateway.\n *\n * @extends BaseMetricsClient\n */\nclass RedisMetricsClient extends BaseMetricsClient {\n /**\n * @param {Object} options\n * @param {any} options.redisClient - Redis client instance (required)\n * @param {string} [options.appName] - Application name (from BaseMetricsClient)\n * @param {string} [options.dynoId] - Dyno/instance ID (from BaseMetricsClient)\n * @param {string} [options.processType] - Process type (from BaseMetricsClient)\n * @param {boolean} [options.enabled] - Enable metrics collection (from BaseMetricsClient)\n * @param {boolean} [options.logValues] - Log metrics values (from BaseMetricsClient)\n * @param {string} [options.pushgatewayUrl] - PushGateway URL (from BaseMetricsClient)\n * @param {string} [options.pushgatewaySecret] - PushGateway secret token (from BaseMetricsClient)\n * @param {number} [options.intervalSec] - Interval in seconds for pushing metrics (from BaseMetricsClient)\n * @param {boolean} [options.removeOldMetrics] - Remove old metrics by service (from BaseMetricsClient)\n * @param {function} [options.startupValidation] - Function to validate startup (from BaseMetricsClient)\n * @param {boolean} [options.disablePushgateway] - Disable pushing to Pushgateway (use HTTP scraping instead)\n */\n constructor({ redisClient, ...metricsConfig } = {}) {\n if (redisClient == null) {\n throw new Error('RedisMetricsClient requires redisClient')\n }\n\n const intervalSec =\n metricsConfig.intervalSec ||\n parseInt(process.env.METRICS_QUEUE_INTERVAL_SEC || '', 10) ||\n 5\n\n super({\n ...metricsConfig,\n processType: metricsConfig.processType || 'queue-metrics',\n intervalSec,\n })\n\n /** Redis client used for metrics */\n this.redisClient = redisClient\n this.redisClientType = getRedisClientType(redisClient)\n\n /** Label names for Redis metrics: app + process_type only (no dyno_id). */\n this._redisLabelNames = ['app', 'process_type']\n\n /** Counter for Redis connection metrics */\n this.redisConnectionsGauge = this.createGauge({\n name: 'app_redis_connections_count',\n help: 'Redis client connections',\n labelNames: [...this._redisLabelNames, ...redisConnectionStableFields],\n })\n\n this.redisConnectionsMemoryGauge = this.createGauge({\n name: 'app_redis_connections_memory_usage_count',\n help: 'Redis client connections',\n labelNames: [...this._redisLabelNames, ...redisConnectionStableFields],\n })\n\n /** Gauge for Redis memory usage */\n this.redisMemoryGauge = this.createGauge({\n name: 'app_redis_memory_bytes',\n help: 'Redis memory usage in bytes',\n labelNames: [...this._redisLabelNames, 'memory_type'],\n })\n\n /** Gauge for Redis operation stats */\n this.redisStatsGauge = this.createGauge({\n name: 'app_redis_stats_total',\n help: 'Redis operation statistics',\n labelNames: [...this._redisLabelNames, 'operation'],\n })\n\n // Track emitted connection label combinations so we can:\n // - emit a one-shot 0 for series that disappear (overwrite last non-zero sample)\n // - then stop emitting them on subsequent scrapes\n //\n // This is mainly needed because we label connections by `cmd`,\n // and Redis `CLIENT LIST` `cmd` is volatile.\n this._redisConnSeenKeys = new Set()\n this._redisConnZeroedKeys = new Set()\n\n this._setCleanupHandlers()\n }\n\n getRedisConnections = async () => {\n if (!this.redisClient) throw new Error('Redis client not provided')\n\n // node-redis v3 (uses callback)\n if (this.redisClientType === REDIS_V3) {\n return new Promise((resolve, reject) => {\n this.redisClient.send_command('CLIENT', ['LIST'], (err, result) => {\n if (err) {\n reject(new Error(`Failed to get CLIENT LIST: ${err.message}`))\n } else resolve(result)\n })\n })\n }\n\n // node-redis v4\n if (this.redisClientType === REDIS_V4) {\n try {\n return this.redisClient.sendCommand(['CLIENT', 'LIST'])\n } catch (err) {\n throw new Error(`Failed to get CLIENT LIST: ${err.message}`)\n }\n }\n\n if (this.redisClientType === IOREDIS) {\n try {\n return this.redisClient.client('LIST')\n } catch (err) {\n throw new Error(`Failed to get CLIENT LIST: ${err.message}`)\n }\n }\n\n throw new Error('Unsupported Redis client type')\n }\n\n getRedisInfo = async section => {\n if (!this.redisClient) throw new Error('Redis client not provided')\n\n // node-redis v3 (uses callback)\n if (this.redisClientType === REDIS_V3) {\n return new Promise((resolve, reject) => {\n this.redisClient.info(section, (err, result) => {\n if (err) reject(err)\n else resolve(result)\n })\n })\n }\n\n // node-redis v4 or ioredis (info returns Promise)\n if (this.redisClientType === REDIS_V4 || this.redisClientType === IOREDIS) {\n try {\n return this.redisClient.info(section)\n } catch (err) {\n throw new Error(`Failed to get Redis INFO: ${err.message}`)\n }\n }\n\n throw new Error('Unsupported Redis client type')\n }\n\n parseRedisConnections = clientsStr => {\n return clientsStr\n .split('\\n')\n .filter(line => line.trim() !== '')\n .map(line => {\n const parts = line.split(' ')\n const client = {}\n parts.forEach(p => {\n const eqIdx = p.indexOf('=')\n if (eqIdx === -1) return\n const k = p.slice(0, eqIdx)\n const v = p.slice(eqIdx + 1)\n if (redisConnectionFields.includes(k)) {\n client[k] = v\n }\n })\n return client\n })\n }\n\n /**\n * Collect basic Redis INFO metrics: clients, memory, stats\n * @returns {Promise<void>}\n */\n collectRedisMetrics = async () => {\n try {\n const [memoryInfoStr, statsInfoStr, connectionsInfoStr] =\n await Promise.all([\n this.getRedisInfo('memory'),\n this.getRedisInfo('stats'),\n this.getRedisConnections(),\n ])\n\n const labels = { app: this.appName, process_type: this.processType }\n\n const connections = this.parseRedisConnections(connectionsInfoStr)\n\n if (this.logValues) {\n // \"IN\" data: raw client list from Redis\n console.log(\n '[queue-metrics] Redis CLIENT LIST (raw):\\n',\n connectionsInfoStr\n )\n console.log(\n '[queue-metrics] Redis CLIENT LIST (raw) length:',\n connectionsInfoStr.length\n )\n\n // \"OUT\" data: parsed fields used for metrics\n console.log(\n '[queue-metrics] Redis CLIENT LIST (parsed) count:',\n connections.length\n )\n console.log(\n '[queue-metrics] Redis CLIENT LIST (parsed sample, first 10):',\n JSON.stringify(connections.slice(0, 10), null, 2)\n )\n\n const missing = { name: 0, flags: 0, cmd: 0, 'tot-mem': 0 }\n connections.forEach(c => {\n if (!c.name) missing.name += 1\n if (!c.flags) missing.flags += 1\n if (!c.cmd) missing.cmd += 1\n if (!c['tot-mem']) missing['tot-mem'] += 1\n })\n console.log(\n '[queue-metrics] Redis CLIENT LIST (parsed) missing fields:',\n missing\n )\n }\n\n const grouped = {}\n connections.forEach(conn => {\n const { name, flags, 'tot-mem': totMem, cmd } = conn\n\n // build grouping key (includes default gauge labels later)\n const key = JSON.stringify({ name, flags, cmd })\n\n if (!grouped[key]) {\n grouped[key] = {\n labels: { name, flags, cmd },\n count: 0,\n memory: 0,\n }\n }\n\n grouped[key].count += 1\n const mem = parseInt(totMem, 10)\n grouped[key].memory += Number.isFinite(mem) ? mem : 0\n })\n\n // Ensure sets exist even if older instance is hot-reloaded.\n if (!this._redisConnSeenKeys) this._redisConnSeenKeys = new Set()\n if (!this._redisConnZeroedKeys) this._redisConnZeroedKeys = new Set()\n\n const currentKeys = new Set(Object.keys(grouped))\n for (const k of currentKeys) {\n this._redisConnSeenKeys.add(k)\n if (this._redisConnZeroedKeys.has(k)) {\n this._redisConnZeroedKeys.delete(k)\n }\n }\n\n // Reset gauges each scrape so we only export:\n // - current snapshot series\n // - one-shot zeros for recently disappeared series\n this.redisConnectionsGauge.reset()\n this.redisConnectionsMemoryGauge.reset()\n\n // Emit one-shot zeros for series that disappeared since last seen.\n for (const k of this._redisConnSeenKeys) {\n if (currentKeys.has(k)) continue\n if (this._redisConnZeroedKeys.has(k)) continue\n try {\n const valueLabels = JSON.parse(k)\n this.redisConnectionsGauge.set({ ...labels, ...valueLabels }, 0)\n this.redisConnectionsMemoryGauge.set({ ...labels, ...valueLabels }, 0)\n this._redisConnZeroedKeys.add(k)\n } catch {\n // ignore malformed key\n }\n }\n\n if (this.logValues) {\n const groups = Object.values(grouped)\n const groupedTotal = groups.reduce((sum, g) => sum + (g.count || 0), 0)\n console.log(\n '[queue-metrics] Redis connections grouped buckets:',\n groups.length\n )\n console.log(\n '[queue-metrics] Redis connections grouped total:',\n groupedTotal\n )\n console.log(\n '[queue-metrics] Redis connections seen keys:',\n this._redisConnSeenKeys.size\n )\n console.log(\n '[queue-metrics] Redis connections zeroed keys:',\n this._redisConnZeroedKeys.size\n )\n console.log(\n '[queue-metrics] Redis connections grouped sample (first 10):',\n JSON.stringify(groups.slice(0, 10), null, 2)\n )\n }\n\n Object.values(grouped).forEach(\n ({ labels: valueLabels, count, memory }) => {\n this.redisConnectionsGauge.set({ ...labels, ...valueLabels }, count)\n this.redisConnectionsMemoryGauge.set(\n { ...labels, ...valueLabels },\n memory\n )\n }\n )\n\n const parseRedisInfo = infoStr =>\n Object.fromEntries(\n infoStr\n .split('\\r\\n')\n .filter(line => line && !line.startsWith('#'))\n .map(line => line.split(':', 2))\n .filter(parts => parts.length === 2 && parts[0] && parts[1])\n )\n\n const memory = parseRedisInfo(memoryInfoStr)\n const stats = parseRedisInfo(statsInfoStr)\n\n if (memory.used_memory) {\n this.redisMemoryGauge.set(\n { ...labels, memory_type: 'used' },\n parseInt(memory.used_memory, 10) || 0\n )\n }\n if (memory.maxmemory) {\n this.redisMemoryGauge.set(\n { ...labels, memory_type: 'max' },\n parseInt(memory.maxmemory, 10) || 0\n )\n }\n\n if (stats.instantaneous_ops_per_sec) {\n this.redisStatsGauge.set(\n { ...labels, operation: 'ops_per_sec' },\n parseInt(stats.instantaneous_ops_per_sec, 10) || 0\n )\n }\n } catch (error) {\n console.warn(\n `[queue-metrics] Failed to collect Redis metrics:`,\n error.message\n )\n }\n }\n\n /**\n * Collect metrics for all Redis and push to Prometheus Pushgateway\n * @returns {Promise<void>}\n */\n pushRedisMetrics = async () => {\n try {\n await this.collectRedisMetrics()\n await this.gatewayPush()\n this.clearAllCounters()\n\n if (this.metricsLogValues) {\n const metricObjects = await this.registry.getMetricsAsJSON()\n console.info(\n `[queue-metrics] Collected metrics for Redis`,\n JSON.stringify(metricObjects, null, 2)\n )\n }\n } catch (error) {\n console.error(\n `[queue-metrics] Failed to collect Redis metrics: ${error.message}`\n )\n throw error\n }\n }\n\n /**\n * Start periodic collection.\n * @param {number} [intervalSec=this.intervalSec] - Interval in seconds\n */\n startPush = (intervalSec = this.intervalSec) => {\n this._startPush(intervalSec, () => {\n this.pushRedisMetrics().catch(err => {\n console.error(`[queue-metrics] Failed to push Redis metrics:`, err)\n })\n })\n }\n\n /**\n * Cleanup Redis client and exit process.\n * @returns {Promise<void>}\n */\n cleanup = async () => {\n try {\n if (!this.redisClient) return\n\n if (\n this.redisClientType === REDIS_V3 ||\n this.redisClientType === REDIS_V4\n ) {\n await this.redisClient.quit()\n } else if (this.redisClientType === IOREDIS) {\n await this.redisClient.disconnect()\n }\n } catch (err) {\n console.error('[queue-metrics] Error closing Redis client:', err)\n }\n process.exit(0)\n }\n\n _setCleanupHandlers = () => {\n process.on('SIGINT', this.cleanup)\n process.on('SIGTERM', this.cleanup)\n }\n}\n\nmodule.exports = { RedisMetricsClient }\n"],"mappings":";;AAAA,MAAM;EAAEA;AAAkB,CAAC,GAAGC,OAAO,CAAC,qBAAqB,CAAC;AAC5D,MAAM;EACJC,kBAAkB;EAClBC,QAAQ;EACRC,OAAO;EACPC;AACF,CAAC,GAAGJ,OAAO,CAAC,eAAe,CAAC;AAE5B,MAAMK,2BAA2B,GAAG,CAAC,MAAM,EAAE,OAAO,EAA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param {string} [appName='undefined-app'] - Fallback app name if BUILD_APP_NAME is not set.
5
+ * @returns {(client: any, name: string) => void}
6
+ */
7
+ export function createSetClientNameForRedisV3(appName?: string | undefined): (client: any, name: string) => void;
8
+ /**
9
+ * Creates a function to set Redis client name for node-redis v4.
10
+ *
11
+ * @param {string} [appName='undefined-app']
12
+ * @returns {(client: any, name: string) => void}
13
+ */
14
+ export function createSetClientNameForRedisV4(appName?: string | undefined): (client: any, name: string) => void;
15
+ /**
16
+ * Creates a function to set Redis client name for ioredis.
17
+ *
18
+ * @param {string} [appName='undefined-app']
19
+ * @returns {(client: any, name: string) => void}
20
+ */
21
+ export function createSetClientNameForIoredis(appName?: string | undefined): (client: any, name: string) => void;
22
+ /**
23
+ * Check if a Redis client is an ioredis instance
24
+ *
25
+ * @param {any} client - Redis client instance
26
+ * @returns {boolean} True if the client is ioredis
27
+ */
28
+ export function isIORedis(client: any): boolean;
29
+ /**
30
+ * Get Redis client type
31
+ *
32
+ * @param {any} client - Redis client instance
33
+ * @returns {string} One of IOREDIS, REDIS_V3, REDIS_V4
34
+ */
35
+ export function getRedisClientType(client: any): string;
36
+ export const REDIS_V4: "REDIS_V4";
37
+ export const REDIS_V3: "REDIS_V3";
38
+ export const IOREDIS: "IOREDIS";
39
+ /**
40
+ * Get the default Redis client name.
41
+ *
42
+ * @param {Object} options - Options for generating Redis name.
43
+ * @param {string} [options.name='undefined-name'] - Fallback name if none is provided.
44
+ * @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.
45
+ * @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.
46
+ * @returns {string} The generated Redis client name.
47
+ */
48
+ export function getRedisName({ name, appName, processName }: {
49
+ name?: string | undefined;
50
+ appName?: string | undefined;
51
+ processName?: string | undefined;
52
+ }): string;
53
+ //# sourceMappingURL=redisUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redisUtils.d.ts","sourceRoot":"","sources":["../src/redisUtils.js"],"names":[],"mappings":"AAsBA;;;;;GAKG;AACH,sFAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAuB/C;AA4BD;;;;;GAKG;AACH,sFAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAmB/C;AAjDD;;;;;GAKG;AACH,sFAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAoB/C;AA2BD;;;;;GAKG;AACH,kCAHW,GAAG,GACD,OAAO,CASnB;AAED;;;;;GAKG;AACH,2CAHW,GAAG,GACD,MAAM,CAqBlB;AA9ID,kCAA2B;AAC3B,kCAA2B;AAC3B,gCAAyB;AAKzB;;;;;;;;GAQG;AACH;IAL4B,IAAI;IACJ,OAAO;IACP,WAAW;IAC1B,MAAM,CAMlB"}
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+
3
+ const REDIS_V4 = 'REDIS_V4';
4
+ const REDIS_V3 = 'REDIS_V3';
5
+ const IOREDIS = 'IOREDIS';
6
+ const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno';
7
+ const defaultAppName = process.env.BUILD_APP_NAME;
8
+
9
+ /**
10
+ * Get the default Redis client name.
11
+ *
12
+ * @param {Object} options - Options for generating Redis name.
13
+ * @param {string} [options.name='undefined-name'] - Fallback name if none is provided.
14
+ * @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.
15
+ * @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.
16
+ * @returns {string} The generated Redis client name.
17
+ */
18
+ const getRedisName = ({
19
+ name = 'undefined-name',
20
+ appName,
21
+ processName
22
+ }) => {
23
+ return `${appName || defaultAppName || 'undefined-app'}:${processName || dyno}:${name}`;
24
+ };
25
+
26
+ /**
27
+ * Creates a configured setClientName function for node-redis v3.
28
+ *
29
+ * @param {string} [appName='undefined-app'] - Fallback app name if BUILD_APP_NAME is not set.
30
+ * @returns {(client: any, name: string) => void}
31
+ */
32
+ const createSetClientNameForRedisV3 = (appName = 'undefined-app') => {
33
+ return (client, name) => {
34
+ if (process.env.NODE_ENV !== 'test') {
35
+ client.on('connect', () => {
36
+ client.send_command('CLIENT', ['SETNAME', getRedisName({
37
+ name,
38
+ appName: defaultAppName || appName
39
+ })], err => {
40
+ if (err) {
41
+ console.error(`Failed to set client name for ${name}:`, err);
42
+ } else {
43
+ console.log(`Connected to Redis for pid:${process.pid} (${name})`);
44
+ }
45
+ });
46
+ });
47
+ }
48
+ };
49
+ };
50
+
51
+ /**
52
+ * Creates a function to set Redis client name for ioredis.
53
+ *
54
+ * @param {string} [appName='undefined-app']
55
+ * @returns {(client: any, name: string) => void}
56
+ */
57
+ const createSetClientNameForIoredis = (appName = 'undefined-app') => {
58
+ return (client, name) => {
59
+ if (process.env.NODE_ENV !== 'test') {
60
+ client.once('connect', () => {
61
+ client.call('CLIENT', ['SETNAME', getRedisName({
62
+ name,
63
+ appName: defaultAppName || appName
64
+ })]).then(() => {
65
+ console.log(`Connected to Redis for pid:${process.pid} (${name})`);
66
+ }).catch(err => {
67
+ console.error(`Failed to set client name for ${name}:`, err);
68
+ });
69
+ });
70
+ }
71
+ };
72
+ };
73
+
74
+ /**
75
+ * Creates a function to set Redis client name for node-redis v4.
76
+ *
77
+ * @param {string} [appName='undefined-app']
78
+ * @returns {(client: any, name: string) => void}
79
+ */
80
+ const createSetClientNameForRedisV4 = (appName = 'undefined-app') => {
81
+ return (client, name) => {
82
+ if (process.env.NODE_ENV !== 'test') {
83
+ client.on('ready', async () => {
84
+ try {
85
+ await client.sendCommand(['CLIENT', 'SETNAME', getRedisName({
86
+ name,
87
+ appName: defaultAppName || appName
88
+ })]);
89
+ console.log(`Connected to Redis for pid:${process.pid} (${name})`);
90
+ } catch (err) {
91
+ console.error(`Failed to set client name for ${name}:`, err);
92
+ }
93
+ });
94
+ }
95
+ };
96
+ };
97
+
98
+ /**
99
+ * Check if a Redis client is an ioredis instance
100
+ *
101
+ * @param {any} client - Redis client instance
102
+ * @returns {boolean} True if the client is ioredis
103
+ */
104
+ const isIORedis = client => {
105
+ return client && typeof client.sendCommand === 'function' && typeof client.disconnect === 'function' && client.options !== undefined;
106
+ };
107
+
108
+ /**
109
+ * Get Redis client type
110
+ *
111
+ * @param {any} client - Redis client instance
112
+ * @returns {string} One of IOREDIS, REDIS_V3, REDIS_V4
113
+ */
114
+ const getRedisClientType = client => {
115
+ if (typeof client?.send_command === 'function') {
116
+ console.log('Detected node-redis redis_v3');
117
+ return REDIS_V3;
118
+ }
119
+ if (typeof client?.info === 'function' && typeof client?.sendCommand === 'function' && typeof client?.setex !== 'function') {
120
+ console.log('Detected node-redis redis_v4');
121
+ return REDIS_V4;
122
+ }
123
+ if (isIORedis(client)) {
124
+ console.log('Detected node-redis ioredis');
125
+ return IOREDIS;
126
+ }
127
+ throw new Error(`Failed to get Redis client type`);
128
+ };
129
+ module.exports = {
130
+ createSetClientNameForRedisV3,
131
+ createSetClientNameForRedisV4,
132
+ createSetClientNameForIoredis,
133
+ isIORedis,
134
+ getRedisClientType,
135
+ REDIS_V4,
136
+ REDIS_V3,
137
+ IOREDIS,
138
+ getRedisName
139
+ };
140
+ //# sourceMappingURL=redisUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redisUtils.js","names":["REDIS_V4","REDIS_V3","IOREDIS","dyno","process","env","BUILD_DYNO_PROCESS_TYPE","defaultAppName","BUILD_APP_NAME","getRedisName","name","appName","processName","createSetClientNameForRedisV3","client","NODE_ENV","on","send_command","err","console","error","log","pid","createSetClientNameForIoredis","once","call","then","catch","createSetClientNameForRedisV4","sendCommand","isIORedis","disconnect","options","undefined","getRedisClientType","info","setex","Error","module","exports"],"sources":["../src/redisUtils.js"],"sourcesContent":["const REDIS_V4 = 'REDIS_V4'\nconst REDIS_V3 = 'REDIS_V3'\nconst IOREDIS = 'IOREDIS'\n\nconst dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'\nconst defaultAppName = process.env.BUILD_APP_NAME\n\n/**\n * Get the default Redis client name.\n *\n * @param {Object} options - Options for generating Redis name.\n * @param {string} [options.name='undefined-name'] - Fallback name if none is provided.\n * @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.\n * @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.\n * @returns {string} The generated Redis client name.\n */\nconst getRedisName = ({ name = 'undefined-name', appName, processName }) => {\n return `${appName || defaultAppName || 'undefined-app'}:${\n processName || dyno\n }:${name}`\n}\n\n/**\n * Creates a configured setClientName function for node-redis v3.\n *\n * @param {string} [appName='undefined-app'] - Fallback app name if BUILD_APP_NAME is not set.\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForRedisV3 = (appName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.on('connect', () => {\n client.send_command(\n 'CLIENT',\n [\n 'SETNAME',\n getRedisName({ name, appName: defaultAppName || appName }),\n ],\n err => {\n if (err) {\n console.error(`Failed to set client name for ${name}:`, err)\n } else {\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n }\n }\n )\n })\n }\n }\n}\n\n/**\n * Creates a function to set Redis client name for ioredis.\n *\n * @param {string} [appName='undefined-app']\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForIoredis = (appName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.once('connect', () => {\n client\n .call('CLIENT', [\n 'SETNAME',\n getRedisName({ name, appName: defaultAppName || appName }),\n ])\n .then(() => {\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n })\n .catch(err => {\n console.error(`Failed to set client name for ${name}:`, err)\n })\n })\n }\n }\n}\n\n/**\n * Creates a function to set Redis client name for node-redis v4.\n *\n * @param {string} [appName='undefined-app']\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForRedisV4 = (appName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.on('ready', async () => {\n try {\n await client.sendCommand([\n 'CLIENT',\n 'SETNAME',\n getRedisName({ name, appName: defaultAppName || appName }),\n ])\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n } catch (err) {\n console.error(`Failed to set client name for ${name}:`, err)\n }\n })\n }\n }\n}\n\n/**\n * Check if a Redis client is an ioredis instance\n *\n * @param {any} client - Redis client instance\n * @returns {boolean} True if the client is ioredis\n */\nconst isIORedis = client => {\n return (\n client &&\n typeof client.sendCommand === 'function' &&\n typeof client.disconnect === 'function' &&\n client.options !== undefined\n )\n}\n\n/**\n * Get Redis client type\n *\n * @param {any} client - Redis client instance\n * @returns {string} One of IOREDIS, REDIS_V3, REDIS_V4\n */\nconst getRedisClientType = client => {\n if (typeof client?.send_command === 'function') {\n console.log('Detected node-redis redis_v3')\n return REDIS_V3\n }\n if (\n typeof client?.info === 'function' &&\n typeof client?.sendCommand === 'function' &&\n typeof client?.setex !== 'function'\n ) {\n console.log('Detected node-redis redis_v4')\n return REDIS_V4\n }\n if (isIORedis(client)) {\n console.log('Detected node-redis ioredis')\n return IOREDIS\n }\n\n throw new Error(`Failed to get Redis client type`)\n}\n\nmodule.exports = {\n createSetClientNameForRedisV3,\n createSetClientNameForRedisV4,\n createSetClientNameForIoredis,\n isIORedis,\n getRedisClientType,\n REDIS_V4,\n REDIS_V3,\n IOREDIS,\n getRedisName,\n}\n"],"mappings":";;AAAA,MAAMA,QAAQ,GAAG,UAAU;AAC3B,MAAMC,QAAQ,GAAG,UAAU;AAC3B,MAAMC,OAAO,GAAG,SAAS;AAEzB,MAAMC,IAAI,GAAGC,OAAO,CAACC,GAAG,CAACC,uBAAuB,IAAI,gBAAgB;AACpE,MAAMC,cAAc,GAAGH,OAAO,CAACC,GAAG,CAACG,cAAc;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAY,GAAGA,CAAC;EAAEC,IAAI,GAAG,gBAAgB;EAAEC,OAAO;EAAEC;AAAY,CAAC,KAAK;EAC1E,OAAO,GAAGD,OAAO,IAAIJ,cAAc,IAAI,eAAe,IACpDK,WAAW,IAAIT,IAAI,IACjBO,IAAI,EAAE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