kuzzle 2.44.0 → 2.46.0-beta.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 (45) hide show
  1. package/check-node-version.js +1 -0
  2. package/lib/api/controllers/adminController.js +2 -1
  3. package/lib/api/controllers/authController.d.ts +1 -0
  4. package/lib/api/controllers/authController.js +2 -1
  5. package/lib/api/controllers/securityController.js +22 -20
  6. package/lib/api/funnel.js +30 -10
  7. package/lib/cluster/command.js +3 -2
  8. package/lib/cluster/idCardHandler.d.ts +1 -0
  9. package/lib/cluster/idCardHandler.js +2 -1
  10. package/lib/cluster/node.js +18 -19
  11. package/lib/cluster/subscriber.js +5 -3
  12. package/lib/core/backend/backend.d.ts +4 -6
  13. package/lib/core/backend/backend.js +25 -23
  14. package/lib/core/cache/cacheEngine.js +3 -1
  15. package/lib/core/network/accessLogger.js +3 -2
  16. package/lib/core/network/entryPoint.js +7 -7
  17. package/lib/core/network/protocols/httpwsProtocol.js +7 -7
  18. package/lib/core/network/protocols/mqttProtocol.js +3 -2
  19. package/lib/core/network/router.js +4 -3
  20. package/lib/core/plugin/pluginContext.d.ts +5 -0
  21. package/lib/core/plugin/pluginContext.js +8 -6
  22. package/lib/core/plugin/pluginsManager.js +13 -5
  23. package/lib/core/realtime/hotelClerk.d.ts +1 -0
  24. package/lib/core/realtime/hotelClerk.js +4 -3
  25. package/lib/core/realtime/notifier.js +2 -1
  26. package/lib/core/security/roleRepository.js +3 -2
  27. package/lib/core/security/securityLoader.js +5 -7
  28. package/lib/core/shared/store.d.ts +1 -0
  29. package/lib/core/shared/store.js +2 -1
  30. package/lib/core/statistics/statistics.js +3 -1
  31. package/lib/core/storage/storageEngine.js +6 -1
  32. package/lib/core/validation/validation.js +6 -5
  33. package/lib/kuzzle/Logger.d.ts +1 -1
  34. package/lib/kuzzle/Logger.js +7 -7
  35. package/lib/kuzzle/dumpGenerator.js +17 -16
  36. package/lib/kuzzle/internalIndexHandler.js +3 -1
  37. package/lib/kuzzle/kuzzle.js +6 -8
  38. package/lib/service/cache/redis.js +4 -0
  39. package/lib/service/storage/7/elasticsearch.d.ts +1 -0
  40. package/lib/service/storage/7/elasticsearch.js +11 -4
  41. package/lib/service/storage/8/elasticsearch.d.ts +1 -0
  42. package/lib/service/storage/8/elasticsearch.js +11 -4
  43. package/lib/service/storage/Elasticsearch.d.ts +1 -0
  44. package/lib/service/storage/Elasticsearch.js +1 -1
  45. package/package.json +19 -19
@@ -13,5 +13,6 @@ if (!semver.satisfies(nodeVersion, version)) {
13
13
  "\x1b[31m%s\x1b[0m",
14
14
  `Required node version ${version} not satisfied with current version ${nodeVersion}`,
15
15
  );
16
+
16
17
  process.exit(1);
17
18
  }
@@ -45,6 +45,7 @@ class AdminController extends NativeController {
45
45
  ]);
46
46
 
47
47
  this.shuttingDown = false;
48
+ this.logger = global.kuzzle.log.child("api:controllers:admin");
48
49
  }
49
50
 
50
51
  async refreshIndexCache() {
@@ -216,7 +217,7 @@ class AdminController extends NativeController {
216
217
  if (waitForRefresh === "false") {
217
218
  // Attaching an error handler to the provided promise to prevent
218
219
  // uncaught rejections
219
- promise.catch((err) => global.kuzzle.log.error(err));
220
+ promise.catch((err) => this.logger.error(err));
220
221
 
221
222
  return Bluebird.resolve(result);
222
223
  }
@@ -3,6 +3,7 @@ import { KuzzleRequest } from "../request";
3
3
  import { NativeController } from "./baseController";
4
4
  export declare class AuthController extends NativeController {
5
5
  private anonymousId;
6
+ private readonly logger;
6
7
  /**
7
8
  * @param {Kuzzle} kuzzle
8
9
  * @constructor
@@ -87,6 +87,7 @@ class AuthController extends baseController_1.NativeController {
87
87
  "updateSelf",
88
88
  "validateMyCredentials",
89
89
  ]);
90
+ this.logger = global.kuzzle.log.child("api:controllers:auth");
90
91
  this.anonymousId = null;
91
92
  }
92
93
  /**
@@ -404,7 +405,7 @@ class AuthController extends baseController_1.NativeController {
404
405
  retryOnConflict: request.getInteger("retryOnConflict", 10),
405
406
  userId,
406
407
  });
407
- global.kuzzle.log.info(`[SECURITY] ${securityController_1.default.userOrSdk(userId)} applied action "${request.input.action}" on user "${userId}."`);
408
+ this.logger.info(`[SECURITY] ${securityController_1.default.userOrSdk(userId)} applied action "${request.input.action}" on user "${userId}."`);
408
409
  return formatProcessing_1.default.serializeUser(user);
409
410
  }
410
411
  /**
@@ -109,6 +109,8 @@ class SecurityController extends NativeController {
109
109
  global.kuzzle.pluginsManager.getStrategyMethod.bind(
110
110
  global.kuzzle.pluginsManager,
111
111
  );
112
+
113
+ this.logger = global.kuzzle.log.child("api:controllers:security");
112
114
  }
113
115
 
114
116
  /**
@@ -154,7 +156,7 @@ class SecurityController extends NativeController {
154
156
  refresh,
155
157
  });
156
158
 
157
- global.kuzzle.log.info(
159
+ this.logger.info(
158
160
  `[SECURITY] ${SecurityController.userOrSdk(creatorId)} applied action "${
159
161
  request.input.action
160
162
  }" on user "${userId}."`,
@@ -394,7 +396,7 @@ class SecurityController extends NativeController {
394
396
  },
395
397
  );
396
398
 
397
- global.kuzzle.log.info(
399
+ this.logger.info(
398
400
  `[SECURITY] ${SecurityController.userOrSdk(userId)} applied action "${
399
401
  request.input.action
400
402
  }" on role "${role._id}."`,
@@ -419,7 +421,7 @@ class SecurityController extends NativeController {
419
421
  userId,
420
422
  });
421
423
 
422
- global.kuzzle.log.info(
424
+ this.logger.info(
423
425
  `[SECURITY] ${SecurityController.userOrSdk(userId)} applied action "${
424
426
  request.input.action
425
427
  }" on role "${role._id}."`,
@@ -440,7 +442,7 @@ class SecurityController extends NativeController {
440
442
  refresh: request.getRefresh("wait_for"),
441
443
  });
442
444
 
443
- global.kuzzle.log.info(
445
+ this.logger.info(
444
446
  `[SECURITY] ${SecurityController.userOrSdk(
445
447
  request.getKuid(),
446
448
  )} applied action "${request.input.action} on role "${id}."`,
@@ -510,7 +512,7 @@ class SecurityController extends NativeController {
510
512
  },
511
513
  );
512
514
 
513
- global.kuzzle.log.info(
515
+ this.logger.info(
514
516
  `[SECURITY] ${SecurityController.userOrSdk(userId)} applied action "${
515
517
  request.input.action
516
518
  }" on profile "${profile._id}."`,
@@ -544,7 +546,7 @@ class SecurityController extends NativeController {
544
546
  },
545
547
  );
546
548
 
547
- global.kuzzle.log.info(
549
+ this.logger.info(
548
550
  `[SECURITY] ${SecurityController.userOrSdk(userId)} applied action "${
549
551
  request.input.action
550
552
  }" on profile "${profile._id}."`,
@@ -570,7 +572,7 @@ class SecurityController extends NativeController {
570
572
 
571
573
  await this.ask("core:security:profile:delete", id, options);
572
574
 
573
- global.kuzzle.log.info(
575
+ this.logger.info(
574
576
  `[SECURITY] ${SecurityController.userOrSdk(userId)} applied action "${
575
577
  request.input.action
576
578
  }" on profile "${id}."`,
@@ -828,7 +830,7 @@ class SecurityController extends NativeController {
828
830
 
829
831
  await this.ask("core:security:user:delete", id, options);
830
832
 
831
- global.kuzzle.log.info(
833
+ this.logger.info(
832
834
  `[SECURITY] ${SecurityController.userOrSdk(
833
835
  request.getKuid(),
834
836
  )} applied action "${request.input.action}" on user "${id}."`,
@@ -945,7 +947,7 @@ class SecurityController extends NativeController {
945
947
  { refresh: request.getRefresh("wait_for"), userId },
946
948
  );
947
949
 
948
- global.kuzzle.log.info(
950
+ this.logger.info(
949
951
  `[SECURITY] ${SecurityController.userOrSdk(userId)} applied action "${
950
952
  request.input.action
951
953
  }" on user "${id}."`,
@@ -972,7 +974,7 @@ class SecurityController extends NativeController {
972
974
  userId,
973
975
  });
974
976
 
975
- global.kuzzle.log.info(
977
+ this.logger.info(
976
978
  `[SECURITY] ${SecurityController.userOrSdk(userId)} applied action "${
977
979
  request.input.action
978
980
  }" on profile "${id}."`,
@@ -998,7 +1000,7 @@ class SecurityController extends NativeController {
998
1000
  userId,
999
1001
  });
1000
1002
 
1001
- global.kuzzle.log.info(
1003
+ this.logger.info(
1002
1004
  `[SECURITY] ${SecurityController.userOrSdk(userId)} applied action "${
1003
1005
  request.input.action
1004
1006
  }" on role "${id}."`,
@@ -1053,7 +1055,7 @@ class SecurityController extends NativeController {
1053
1055
  }
1054
1056
  }
1055
1057
 
1056
- global.kuzzle.log.info(
1058
+ this.logger.info(
1057
1059
  `[SECURITY] ${SecurityController.userOrSdk(userId)} applied action "${
1058
1060
  request.input.action
1059
1061
  }".`,
@@ -1146,7 +1148,7 @@ class SecurityController extends NativeController {
1146
1148
 
1147
1149
  const createMethod = this.getStrategyMethod(strategy, "create");
1148
1150
 
1149
- global.kuzzle.log.info(
1151
+ this.logger.info(
1150
1152
  `[SECURITY] ${SecurityController.userOrSdk(
1151
1153
  request.getKuid(),
1152
1154
  )} applied action "${request.input.action}" on user "${id}."`,
@@ -1174,7 +1176,7 @@ class SecurityController extends NativeController {
1174
1176
 
1175
1177
  const updateMethod = this.getStrategyMethod(strategy, "update");
1176
1178
 
1177
- global.kuzzle.log.info(
1179
+ this.logger.info(
1178
1180
  `[SECURITY] ${SecurityController.userOrSdk(
1179
1181
  request.getKuid(),
1180
1182
  )} applied action "${request.input.action}" on user "${id}."`,
@@ -1232,7 +1234,7 @@ class SecurityController extends NativeController {
1232
1234
 
1233
1235
  await deleteMethod(request, id, strategy);
1234
1236
 
1235
- global.kuzzle.log.info(
1237
+ this.logger.info(
1236
1238
  `[SECURITY] ${SecurityController.userOrSdk(
1237
1239
  request.getKuid(),
1238
1240
  )} applied action "${request.input.action}" on user "${id}."`,
@@ -1347,7 +1349,7 @@ class SecurityController extends NativeController {
1347
1349
  }
1348
1350
 
1349
1351
  if (successes.length > 1000) {
1350
- global.kuzzle.log.info(
1352
+ this.logger.info(
1351
1353
  `[SECURITY] ${SecurityController.userOrSdk(
1352
1354
  request.getKuid(),
1353
1355
  )} deleted the following ${type}s: ${successes
@@ -1355,7 +1357,7 @@ class SecurityController extends NativeController {
1355
1357
  .join(", ")}... (${successes.length - 1000} more users deleted)."`,
1356
1358
  );
1357
1359
  } else {
1358
- global.kuzzle.log.info(
1360
+ this.logger.info(
1359
1361
  `[SECURITY] ${SecurityController.userOrSdk(
1360
1362
  request.getKuid(),
1361
1363
  )} deleted the following ${type}s: ${successes.join(", ")}."`,
@@ -1382,7 +1384,7 @@ class SecurityController extends NativeController {
1382
1384
  },
1383
1385
  );
1384
1386
 
1385
- global.kuzzle.log.info(
1387
+ this.logger.info(
1386
1388
  `[SECURITY] ${SecurityController.userOrSdk(userId)} applied action "${
1387
1389
  request.input.action
1388
1390
  }" on user "${id}."`,
@@ -1485,7 +1487,7 @@ class SecurityController extends NativeController {
1485
1487
  }
1486
1488
 
1487
1489
  if (creationFailure === null) {
1488
- global.kuzzle.log.info(
1490
+ this.logger.info(
1489
1491
  `[SECURITY] ${SecurityController.userOrSdk(
1490
1492
  request.getKuid(),
1491
1493
  )} applied action "${request.input.action}" on user "${id}."`,
@@ -1509,7 +1511,7 @@ class SecurityController extends NativeController {
1509
1511
  try {
1510
1512
  this.ask("core:security:user:delete", id, { refresh: "false" });
1511
1513
  } catch (e) {
1512
- global.kuzzle.log.error(`User rollback error: ${e}`);
1514
+ this.logger.error(`User rollback error: ${e}`);
1513
1515
  }
1514
1516
 
1515
1517
  if (deletionErrors.length > 0) {
package/lib/api/funnel.js CHANGED
@@ -90,6 +90,8 @@ class Funnel {
90
90
  this.loadDocumentEventAliases();
91
91
 
92
92
  this.sdkCompatibility = sdkCompatibility;
93
+
94
+ this.logger = global.kuzzle.log.child("api:funnel");
93
95
  }
94
96
 
95
97
  init() {
@@ -200,7 +202,7 @@ class Funnel {
200
202
  global.kuzzle.config.limits.requestsBufferSize,
201
203
  ) / 100;
202
204
  global.kuzzle.emit("core:overload", overloadPercentage);
203
- global.kuzzle.log.warn(
205
+ this.logger.warn(
204
206
  `[!WARNING!] Kuzzle overloaded: ${overloadPercentage}%. Delaying requests...`,
205
207
  );
206
208
 
@@ -238,7 +240,7 @@ class Funnel {
238
240
  ) {
239
241
  const error = processError.get("overloaded");
240
242
  global.kuzzle.emit("log:error", error);
241
- global.kuzzle.log.error(error);
243
+ this.logger.error(error);
242
244
  throw error;
243
245
  }
244
246
 
@@ -486,7 +488,7 @@ class Funnel {
486
488
 
487
489
  // JSON.stringify(new NativeError()) === '{}'
488
490
  // i.e. Error, SyntaxError, TypeError, ReferenceError, etc.
489
- global.kuzzle.log.error(
491
+ this.logger.error(
490
492
  err instanceof Error && !(err instanceof KuzzleError)
491
493
  ? `${err.message}\n${err.stack}`
492
494
  : err,
@@ -753,11 +755,31 @@ class Funnel {
753
755
  * @returns {Promise}
754
756
  */
755
757
  async executePluginRequest(request) {
756
- try {
757
- if (request.input.triggerEvents) {
758
- const response = await this.processRequest(request);
759
- return { ...response.result };
758
+ if (request.input.triggerEvents) {
759
+ let error;
760
+ let res;
761
+ try {
762
+ const { result } = await this.processRequest(request);
763
+ debug(
764
+ "Request %s successfully executed. Result: %a",
765
+ request.id,
766
+ result,
767
+ );
768
+ res = result;
769
+ return { ...result };
770
+ } catch (e) {
771
+ error = e;
772
+ debug("Error processing request %s: %a", request.id, error);
773
+ } finally {
774
+ global.kuzzle.pipe("request:afterExecution", {
775
+ error: error,
776
+ request: request,
777
+ result: res,
778
+ success: error === undefined ? true : false,
779
+ });
760
780
  }
781
+ }
782
+ try {
761
783
  return await doAction(this.getController(request), request);
762
784
  } catch (e) {
763
785
  this.handleErrorDump(e);
@@ -1004,9 +1026,7 @@ class Funnel {
1004
1026
  (this.lastOverloadTime === 0 || this.lastOverloadTime < now - 500)
1005
1027
  ) {
1006
1028
  this.overloadWarned = false;
1007
- global.kuzzle.log.info(
1008
- "End of overloaded state. Resuming normal activity.",
1009
- );
1029
+ this.logger.info("End of overloaded state. Resuming normal activity.");
1010
1030
  this.lastOverloadTime = now;
1011
1031
  }
1012
1032
  }
@@ -51,6 +51,7 @@ class ClusterCommand {
51
51
  this.protoroot = null;
52
52
 
53
53
  this.state = stateEnum.INITIALIZING;
54
+ this.logger = global.kuzzle.log.child("cluster:command");
54
55
  }
55
56
 
56
57
  async init() {
@@ -188,7 +189,7 @@ class ClusterCommand {
188
189
  } catch (e) {
189
190
  // no response from the remote node in a timely fashion... retrying
190
191
  // with another one
191
- global.kuzzle.log.warn(
192
+ this.logger.warn(
192
193
  `Unable to fetch a full state from node ${id} (no response received)`,
193
194
  );
194
195
  idx = (idx + 1) % nodes.length;
@@ -269,7 +270,7 @@ class ClusterCommand {
269
270
  try {
270
271
  [, response] = await req.receive();
271
272
  } catch (e) {
272
- global.kuzzle.log.warn(
273
+ this.logger.warn(
273
274
  `Couldn't complete handshake with node ${id}: no response received`,
274
275
  );
275
276
  } finally {
@@ -81,6 +81,7 @@ export declare class ClusterIdCardHandler {
81
81
  * cluster
82
82
  */
83
83
  private disposed;
84
+ private readonly logger;
84
85
  constructor(node: any);
85
86
  /**
86
87
  * Generates and reserves a unique ID for this node instance.
@@ -87,6 +87,7 @@ class ClusterIdCardHandler {
87
87
  * cluster
88
88
  */
89
89
  this.disposed = false;
90
+ this.logger = global.kuzzle.log.child("cluster:id-card");
90
91
  this.node = node;
91
92
  this.ip = node.ip;
92
93
  this.refreshDelay = node.heartbeatDelay;
@@ -171,7 +172,7 @@ class ClusterIdCardHandler {
171
172
  await this.save();
172
173
  }
173
174
  catch (error) {
174
- global.kuzzle.log.error(`An error occurred while refreshing the ID card during WorkerThread startup: ${error}`);
175
+ this.logger.error(`An error occurred while refreshing the ID card during WorkerThread startup: ${error}`);
175
176
  }
176
177
  }, this.refreshDelay * this.refreshMultiplier);
177
178
  this.refreshWorker.on("message", ({ initialized }) => {
@@ -157,6 +157,7 @@ const nodeActivityEnum = Object.freeze({
157
157
  class ClusterNode {
158
158
  constructor() {
159
159
  this.config = global.kuzzle.config.cluster;
160
+ this.logger = global.kuzzle.log.child("cluster:node");
160
161
  this.heartbeatDelay = this.config.heartbeat;
161
162
 
162
163
  const family = this.config.ipv6 ? "IPv6" : "IPv4";
@@ -219,7 +220,7 @@ class ClusterNode {
219
220
  this.registerAskEvents();
220
221
 
221
222
  if (this.countActiveNodes() < this.config.minimumNodes) {
222
- global.kuzzle.log.info(
223
+ this.logger.info(
223
224
  "[CLUSTER] Not enough nodes active. Waiting for other nodes to join the cluster...",
224
225
  );
225
226
 
@@ -286,7 +287,7 @@ class ClusterNode {
286
287
  await subscriber.sync(lastMessageId);
287
288
  await this.idCardHandler.addNode(id);
288
289
 
289
- global.kuzzle.log.info(`[CLUSTER] Node "${id}" joined the cluster`);
290
+ this.logger.info(`[CLUSTER] Node "${id}" joined the cluster`);
290
291
  this.trackActivity(id, ip, nodeActivityEnum.ADDED);
291
292
 
292
293
  if (
@@ -294,7 +295,7 @@ class ClusterNode {
294
295
  this.countActiveNodes() >= this.config.minimumNodes
295
296
  ) {
296
297
  global.kuzzle.state = kuzzleStateEnum.RUNNING;
297
- global.kuzzle.log.warn(
298
+ this.logger.warn(
298
299
  `[CLUSTER] Minimum number of nodes reached (${this.countActiveNodes()}). This node is now accepting requests again.`,
299
300
  );
300
301
  }
@@ -310,10 +311,10 @@ class ClusterNode {
310
311
  * @return {void}
311
312
  */
312
313
  async evictSelf(reason, error = null) {
313
- global.kuzzle.log.error(`[CLUSTER] ${reason}`);
314
+ this.logger.error(`[CLUSTER] ${reason}`);
314
315
 
315
316
  if (error) {
316
- global.kuzzle.log.error(error.stack);
317
+ this.logger.error(error.stack);
317
318
  }
318
319
 
319
320
  this.publisher.sendNodeEvicted(this.nodeId, this.nodeId, reason);
@@ -330,15 +331,13 @@ class ClusterNode {
330
331
  const subscriber = this.remoteNodes.get(nodeId);
331
332
 
332
333
  if (!subscriber) {
333
- global.kuzzle.log.warn(
334
+ this.logger.warn(
334
335
  `[CLUSTER] Node "${nodeId}" with no subscriber evicted. Reason: ${reason}`,
335
336
  );
336
337
  return;
337
338
  }
338
339
 
339
- global.kuzzle.log.warn(
340
- `[CLUSTER] Node "${nodeId}" evicted. Reason: ${reason}`,
341
- );
340
+ this.logger.warn(`[CLUSTER] Node "${nodeId}" evicted. Reason: ${reason}`);
342
341
 
343
342
  this.trackActivity(
344
343
  nodeId,
@@ -358,7 +357,7 @@ class ClusterNode {
358
357
 
359
358
  if (this.countActiveNodes() < this.config.minimumNodes) {
360
359
  global.kuzzle.state = kuzzleStateEnum.NOT_ENOUGH_NODES;
361
- global.kuzzle.log.warn(
360
+ this.logger.warn(
362
361
  `[CLUSTER] Not enough nodes active (expected: ${
363
362
  this.config.minimumNodes
364
363
  }, active: ${this.countActiveNodes()}). Deactivating node until new ones are added.`,
@@ -471,17 +470,17 @@ class ClusterNode {
471
470
  }
472
471
 
473
472
  if (candidates.includes(this.nodeId)) {
474
- global.kuzzle.log.error(
473
+ this.logger.error(
475
474
  "[CLUSTER] Network split detected. This node is outside the cluster: shutting down.",
476
475
  );
477
476
  global.kuzzle.shutdown();
478
477
  return;
479
478
  }
480
479
  } catch (err) {
481
- global.kuzzle.log.error(
480
+ this.logger.error(
482
481
  "[CLUSTER] Unexpected exception caught during a cluster consistency check. Shutting down...",
483
482
  );
484
- global.kuzzle.log.error(err.stack);
483
+ this.logger.error(err.stack);
485
484
  global.kuzzle.shutdown();
486
485
  }
487
486
  }
@@ -495,7 +494,7 @@ class ClusterNode {
495
494
  */
496
495
  async handshake() {
497
496
  const handshakeTimeout = setTimeout(() => {
498
- global.kuzzle.log.error(
497
+ this.logger.error(
499
498
  `[CLUSTER] Failed to join the cluster: timed out (joinTimeout: ${this.config.joinTimeout}ms)`,
500
499
  );
501
500
  global.kuzzle.shutdown();
@@ -538,7 +537,7 @@ class ClusterNode {
538
537
  const duplicate = nodes.filter((node) => node.ip === this.ip);
539
538
 
540
539
  if (duplicate.length > 0) {
541
- global.kuzzle.log.error(
540
+ this.logger.error(
542
541
  `[CLUSTER] Another node share the same IP address as this one (${this.ip}): ${duplicate[0].id}. Shutting down.`,
543
542
  );
544
543
  global.kuzzle.shutdown();
@@ -562,7 +561,7 @@ class ClusterNode {
562
561
  // down.
563
562
  if (fullState === null) {
564
563
  if (retried) {
565
- global.kuzzle.log.error(
564
+ this.logger.error(
566
565
  "[CLUSTER] Could not connect to discovered cluster nodes (network split detected). Shutting down.",
567
566
  );
568
567
  global.kuzzle.shutdown();
@@ -578,7 +577,7 @@ class ClusterNode {
578
577
  // Waits for a redis heartbeat round
579
578
  retried = true;
580
579
  const retryDelay = this.heartbeatDelay * 1.5;
581
- global.kuzzle.log.warn(
580
+ this.logger.warn(
582
581
  `[CLUSTER] Unable to connect to discovered cluster nodes. Retrying in ${retryDelay}ms...`,
583
582
  );
584
583
  await Bluebird.delay(retryDelay);
@@ -611,13 +610,13 @@ class ClusterNode {
611
610
  subscriber.sync(
612
611
  nodeStatus ? nodeStatus.lastMessageId : handshakeData.lastMessageId,
613
612
  );
614
- global.kuzzle.log.info(
613
+ this.logger.info(
615
614
  `[CLUSTER] Successfully completed the handshake with node ${nodeId}`,
616
615
  );
617
616
  }
618
617
  }
619
618
 
620
- global.kuzzle.log.info("[CLUSTER] Successfully joined the cluster.");
619
+ this.logger.info("[CLUSTER] Successfully joined the cluster.");
621
620
  this.trackActivity(this.nodeId, this.ip, nodeActivityEnum.ADDED);
622
621
  } finally {
623
622
  clearTimeout(handshakeTimeout);
@@ -103,6 +103,8 @@ class ClusterSubscriber {
103
103
  Unsubscription: this.handleUnsubscription,
104
104
  UserNotification: this.handleUserNotification,
105
105
  });
106
+
107
+ this.logger = global.kuzzle.log.child("cluster:subscriber");
106
108
  }
107
109
 
108
110
  /**
@@ -253,7 +255,7 @@ class ClusterSubscriber {
253
255
  */
254
256
  async handleNodeEviction(message) {
255
257
  if (message.nodeId === this.localNode.nodeId) {
256
- global.kuzzle.log.error(
258
+ this.logger.error(
257
259
  `[CLUSTER] Node evicted by ${message.evictor}. Reason: ${message.reason}`,
258
260
  );
259
261
  global.kuzzle.shutdown();
@@ -518,7 +520,7 @@ class ClusterSubscriber {
518
520
  "Cluster-wide shutdown request received from node %s",
519
521
  this.remoteNodeId,
520
522
  );
521
- global.kuzzle.log.error(
523
+ this.logger.error(
522
524
  `[CLUSTER] Cluster wide shutdown from ${this.remoteNodeId}`,
523
525
  );
524
526
  global.kuzzle.shutdown();
@@ -729,7 +731,7 @@ class ClusterSubscriber {
729
731
  */
730
732
  async validateMessage(message) {
731
733
  if (!has(message, "messageId")) {
732
- global.kuzzle.log.warn(
734
+ this.logger.warn(
733
735
  `Invalid message received from node ${this.remoteNodeId}. Evicting it.`,
734
736
  );
735
737
 
@@ -1,6 +1,7 @@
1
1
  import { EmbeddedSDK } from "../shared/sdk/embeddedSdk";
2
2
  import { EventDefinition, JSONObject } from "../../../index";
3
- import { BackendCluster, BackendConfig, BackendController, BackendHook, BackendImport, BackendPipe, BackendPlugin, BackendStorage, BackendVault, BackendOpenApi, InternalLogger, BackendErrors, BackendSubscription } from "./index";
3
+ import { BackendCluster, BackendConfig, BackendController, BackendHook, BackendImport, BackendPipe, BackendPlugin, BackendStorage, BackendVault, BackendOpenApi, BackendErrors, BackendSubscription } from "./index";
4
+ import { Logger } from "../../kuzzle/Logger";
4
5
  export declare class Backend {
5
6
  private _kuzzle;
6
7
  private _name;
@@ -94,7 +95,7 @@ export declare class Backend {
94
95
  * @method error
95
96
  * @method verbose
96
97
  */
97
- log: InternalLogger;
98
+ log: Logger;
98
99
  /**
99
100
  * Storage manager
100
101
  */
@@ -132,6 +133,7 @@ export declare class Backend {
132
133
  *
133
134
  */
134
135
  _support: JSONObject;
136
+ private readonly nodeId;
135
137
  /**
136
138
  * Instantiates a new Kuzzle application
137
139
  *
@@ -169,10 +171,6 @@ export declare class Backend {
169
171
  * EmbeddedSDK instance
170
172
  */
171
173
  get sdk(): EmbeddedSDK;
172
- /**
173
- * Cluster node ID
174
- */
175
- get nodeId(): string;
176
174
  private get _instanceProxy();
177
175
  get started(): boolean;
178
176
  protected set started(started: boolean);
@@ -51,7 +51,9 @@ const fs_1 = __importDefault(require("fs"));
51
51
  const kuzzle_1 = __importDefault(require("../../kuzzle"));
52
52
  const embeddedSdk_1 = require("../shared/sdk/embeddedSdk");
53
53
  const kerror = __importStar(require("../../kerror"));
54
- const index_1 = require("./index");
54
+ const index_1 = require("../../../index");
55
+ const index_2 = require("./index");
56
+ const Logger_1 = require("../../kuzzle/Logger");
55
57
  const assertionError = kerror.wrap("plugin", "assert");
56
58
  const runtimeError = kerror.wrap("plugin", "runtime");
57
59
  let _app = null;
@@ -115,12 +117,21 @@ class Backend {
115
117
  throw assertionError.get("invalid_application_name", name);
116
118
  }
117
119
  this._name = name;
120
+ this.nodeId = index_1.NameGenerator.generateRandomName({ prefix: "knode" });
118
121
  Reflect.defineProperty(this, "_kuzzle", {
119
122
  writable: true,
120
123
  });
121
124
  Reflect.defineProperty(this, "_sdk", {
122
125
  writable: true,
123
126
  });
127
+ Reflect.defineProperty(global, "nodeId", {
128
+ get: () => {
129
+ return this.nodeId;
130
+ },
131
+ set: () => {
132
+ throw new Error("nodeId is read-only");
133
+ },
134
+ });
124
135
  /**
125
136
  * Set the "started" property in this event so developers can use runtime
126
137
  * features in pipes/hooks attached to this event.
@@ -138,19 +149,19 @@ class Backend {
138
149
  // Silent if no version can be found
139
150
  }
140
151
  global.app = this;
141
- this.pipe = new index_1.BackendPipe(this);
142
- this.hook = new index_1.BackendHook(this);
143
- this.config = new index_1.BackendConfig(this);
144
- this.vault = new index_1.BackendVault(this);
145
- this.controller = new index_1.BackendController(this);
146
- this.plugin = new index_1.BackendPlugin(this);
147
- this.storage = new index_1.BackendStorage(this);
148
- this.import = new index_1.BackendImport(this);
149
- this.log = new index_1.InternalLogger(this);
150
- this.cluster = new index_1.BackendCluster();
151
- this.openApi = new index_1.BackendOpenApi(this);
152
- this.errors = new index_1.BackendErrors(this);
153
- this.subscription = new index_1.BackendSubscription(this);
152
+ this.pipe = new index_2.BackendPipe(this);
153
+ this.hook = new index_2.BackendHook(this);
154
+ this.config = new index_2.BackendConfig(this);
155
+ this.vault = new index_2.BackendVault(this);
156
+ this.controller = new index_2.BackendController(this);
157
+ this.plugin = new index_2.BackendPlugin(this);
158
+ this.storage = new index_2.BackendStorage(this);
159
+ this.import = new index_2.BackendImport(this);
160
+ this.cluster = new index_2.BackendCluster();
161
+ this.openApi = new index_2.BackendOpenApi(this);
162
+ this.errors = new index_2.BackendErrors(this);
163
+ this.subscription = new index_2.BackendSubscription(this);
164
+ this.log = new Logger_1.Logger(this.config.content, "kuzzle:app");
154
165
  this.kerror = kerror;
155
166
  try {
156
167
  this.commit = this._readCommit();
@@ -246,15 +257,6 @@ class Backend {
246
257
  }
247
258
  return this._sdk;
248
259
  }
249
- /**
250
- * Cluster node ID
251
- */
252
- get nodeId() {
253
- if (!this.started) {
254
- throw runtimeError.get("unavailable_before_start", "nodeId");
255
- }
256
- return this._kuzzle.id;
257
- }
258
260
  get _instanceProxy() {
259
261
  return {
260
262
  api: this._controllers,