kuzzle 2.48.0 → 2.49.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.
@@ -593,10 +593,12 @@ class DocumentController extends NativeController {
593
593
  if (source) {
594
594
  return updatedDocument;
595
595
  }
596
-
597
596
  return {
598
597
  _id: updatedDocument._id,
599
- _source: content,
598
+ _source: {
599
+ ...content,
600
+ _kuzzle_info: updatedDocument._source._kuzzle_info,
601
+ },
600
602
  _version: updatedDocument._version,
601
603
  };
602
604
  }
@@ -988,7 +990,7 @@ class DocumentController extends NativeController {
988
990
  if (lang === "koncorde") {
989
991
  query = await this.translateKoncorde(query);
990
992
  }
991
-
993
+ delete changes._kuzzle_info;
992
994
  const result = await this.ask(
993
995
  "core:storage:public:document:updateByQuery",
994
996
  index,
@@ -1082,6 +1084,9 @@ class DocumentController extends NativeController {
1082
1084
  `documents[${i}].body`,
1083
1085
  );
1084
1086
  }
1087
+ if (documents[i].body?._kuzzle_info !== undefined) {
1088
+ delete documents[i].body._kuzzle_info;
1089
+ }
1085
1090
  }
1086
1091
 
1087
1092
  const response = await this.ask(
@@ -30,9 +30,7 @@ const {
30
30
  workerData,
31
31
  } = require("worker_threads");
32
32
 
33
- const winston = require("winston");
34
- const WinstonElasticsearch = require("winston-elasticsearch");
35
- const WinstonSyslog = require("winston-syslog");
33
+ const pino = require("pino");
36
34
  const moment = require("moment");
37
35
 
38
36
  const { KuzzleRequest } = require("../../api/request");
@@ -66,12 +64,11 @@ class AccessLogger {
66
64
  const anonymous = await global.kuzzle.ask(
67
65
  "core:security:user:anonymous:get",
68
66
  );
69
-
70
67
  this.worker = new Worker(__filename, {
71
68
  workerData: {
72
69
  anonymousUserId: anonymous._id,
73
70
  config,
74
- kuzzleId: global.kuzzle.id,
71
+ kuzzleId: global.nodeId,
75
72
  },
76
73
  });
77
74
  }
@@ -131,91 +128,58 @@ class AccessLoggerWorker {
131
128
  }
132
129
 
133
130
  initTransport() {
134
- const transports = [];
131
+ const transports = { targets: [] };
135
132
 
136
133
  for (const conf of this.config.logs.transports) {
137
- const opts = {
138
- colorize: conf.colorize === true ? winston.format.colorize() : false,
139
- depth: conf.depth || false,
140
- format: conf.format
141
- ? winston.format[conf.format]()
142
- : winston.format.json(),
143
- level: conf.level || "info",
144
- prettyPrint:
145
- conf.prettyPrint === true ? winston.format.prettyPrint() : false,
146
- silent: conf.silent || false,
147
- timestamp: conf.timestamp === true ? winston.format.timestamp() : false,
148
- };
149
-
150
- switch (conf.transport || "console") {
134
+ if (conf.silent === true) {
135
+ continue;
136
+ }
137
+
138
+ // Guarantee default transport is 'console' and retro compatibility with winston options
139
+ switch (conf.transport || conf.preset || "console") {
151
140
  case "console":
152
- transports.push(
153
- new winston.transports.Console(
154
- Object.assign(opts, {
155
- humanReadableUnhandledException:
156
- conf.humanReadableUnhandledException || true,
157
- stderrLevels: conf.stderrLevels || ["error", "debug"],
158
- }),
159
- ),
160
- );
141
+ transports.targets.push({
142
+ level: conf.level || "info",
143
+ options: {
144
+ destination: 1,
145
+ },
146
+ target: "pino/file",
147
+ });
161
148
  break;
162
149
  case "elasticsearch":
163
- transports.push(
164
- new WinstonElasticsearch(
165
- Object.assign(opts, {
166
- clientOpts: conf.clientOpts || {},
167
- ensureMappingTemplate: conf.ensureMappingTemplate !== false,
168
- flushInterval: conf.flushInterval || 2000,
169
- index: conf.index,
170
- indexPrefix: conf.indexPrefix || "kuzzle-access",
171
- indexSuffixPattern: conf.indexSuffixPattern || "YYYY.MM",
172
- mappingTemplate:
173
- conf.mappingTemplate || "access.log.mapping.json",
174
- messageType: conf.messageType || "access",
175
- }),
176
- ),
177
- );
150
+ transports.targets.push({
151
+ level: conf.level || "info",
152
+ options: Object.assign({}, conf.options),
153
+ target: "pino-elasticsearch",
154
+ });
178
155
  break;
179
156
  case "file":
180
- transports.push(
181
- new winston.transports.File(
182
- Object.assign(opts, {
183
- eol: conf.eol || "\n",
184
- filename: conf.filename || "kuzzle.access.log",
185
- logstash: conf.logstash || false,
186
- maxFiles: conf.maxFiles,
187
- maxRetries: conf.maxRetries || 2,
188
- maxSize: conf.maxSize,
189
- tailable: conf.tailable,
190
- zippedArchive: conf.zippedArchive || false,
191
- }),
192
- ),
193
- );
194
- break;
195
- case "syslog":
196
- transports.push(
197
- new WinstonSyslog(
198
- Object.assign(opts, {
199
- app_name: conf.app_name || process.title,
200
- eol: conf.eol,
201
- facility: conf.facility || "local0",
202
- host: conf.host || "localhost",
203
- localhost: conf.localhost || "localhost",
204
- path: conf.path || "/dev/log",
205
- pid: conf.pid || process.pid,
206
- port: conf.port || 514,
207
- protocol: conf.protocol || "udp4",
208
- type: conf.type || "BSD",
209
- }),
210
- ),
211
- );
157
+ transports.targets.push({
158
+ level: conf.level || "info",
159
+ options: {
160
+ append: conf.options.append ?? true,
161
+ destination: conf.options.destination ?? "./kuzzle.access.log",
162
+ mkdir: conf.options.mkdir ?? true,
163
+ },
164
+ target: "pino/file",
165
+ });
212
166
  break;
213
167
  default:
214
168
  // do nothing
215
169
  }
170
+
171
+ // If a pino transport configuration is used, we'll try to use it as-is and
172
+ // assume the user installed the necessary dependencies in his Kuzzle application
173
+ if (typeof conf.target === "string" && conf.target !== "") {
174
+ transports.targets.push({
175
+ level: conf.level || "info",
176
+ options: conf.options || {},
177
+ target: conf.target,
178
+ });
179
+ }
216
180
  }
217
181
 
218
- this.logger = winston.createLogger({ transports });
182
+ this.logger = pino.pino(pino.transport(transports));
219
183
  }
220
184
 
221
185
  /**
@@ -231,6 +195,8 @@ class AccessLoggerWorker {
231
195
  connection,
232
196
  error: request.error,
233
197
  extra,
198
+ namespace: "kuzzle:accessLogs",
199
+ nodeId: global.kuzzle.id,
234
200
  request: request.input,
235
201
  status: request.status,
236
202
  });
@@ -313,6 +279,7 @@ class AccessLoggerWorker {
313
279
  : "-";
314
280
 
315
281
  this.logger.info(
282
+ { namespace: "kuzzle:accessLogs", nodeId: global.kuzzle.id },
316
283
  `${ip} - ${user} [${when}] "${verb} ${url} ${protocol}" ${status} ${size} ${referer} ${agent}`,
317
284
  );
318
285
  }
@@ -141,7 +141,7 @@ class PluginContext {
141
141
  this.accessors = {
142
142
  cluster: new backend_1.BackendCluster(),
143
143
  execute: (request, callback) => execute(request, callback),
144
- nodeId: global.kuzzle.id,
144
+ nodeId: global.nodeId,
145
145
  sdk: new embeddedSdk_1.EmbeddedSDK(),
146
146
  storage: {
147
147
  bootstrap: (collections) => pluginStore.init(collections),
@@ -2341,9 +2341,6 @@ class ES7 {
2341
2341
  };
2342
2342
  }
2343
2343
  else {
2344
- if (document.body !== undefined && document.body !== null) {
2345
- delete document.body._kuzzle_info;
2346
- }
2347
2344
  extractedDocument = {
2348
2345
  // Do not use destructuring, it's 10x slower
2349
2346
  _source: Object.assign({}, metadata, document.body),
@@ -765,7 +765,7 @@ export declare class ES8 {
765
765
  * Extracts, injects metadata and validates documents contained
766
766
  * in a Request
767
767
  *
768
- * Used by mCreate, mUpdate, mUpsert, mReplace and mCreateOrReplace
768
+ * Used by mCreate, mUpdate, mUpsert, mReplace, mCreateOrReplace and mWrite
769
769
  *
770
770
  * @param {Object[]} documents - Documents
771
771
  * @param {Object} metadata - Kuzzle metadata
@@ -2259,7 +2259,7 @@ class ES8 {
2259
2259
  * Extracts, injects metadata and validates documents contained
2260
2260
  * in a Request
2261
2261
  *
2262
- * Used by mCreate, mUpdate, mUpsert, mReplace and mCreateOrReplace
2262
+ * Used by mCreate, mUpdate, mUpsert, mReplace, mCreateOrReplace and mWrite
2263
2263
  *
2264
2264
  * @param {Object[]} documents - Documents
2265
2265
  * @param {Object} metadata - Kuzzle metadata
@@ -2334,9 +2334,6 @@ class ES8 {
2334
2334
  };
2335
2335
  }
2336
2336
  else {
2337
- if (document.body !== undefined && document.body !== null) {
2338
- delete document.body._kuzzle_info;
2339
- }
2340
2337
  extractedDocument = {
2341
2338
  // Do not use destructuring, it's 10x slower
2342
2339
  _source: Object.assign({}, metadata, document.body),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kuzzle",
3
3
  "author": "The Kuzzle Team <support@kuzzle.io>",
4
- "version": "2.48.0",
4
+ "version": "2.49.0-beta.1",
5
5
  "description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
6
6
  "bin": "bin/start-kuzzle-server",
7
7
  "scripts": {
@@ -70,10 +70,6 @@
70
70
  "uuid": "11.1.0",
71
71
  "uWebSockets.js": "https://github.com/uNetworking/uWebSockets.js/archive/refs/tags/v20.51.0.tar.gz",
72
72
  "validator": "13.15.15",
73
- "winston": "3.17.0",
74
- "winston-elasticsearch": "0.19.0",
75
- "winston-syslog": "2.7.1",
76
- "winston-transport": "4.9.0",
77
73
  "yargs": "18.0.0",
78
74
  "zeromq": "6.5.0"
79
75
  },