kuzzle 2.19.2 → 2.19.5
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/lib/api/controllers/adminController.js +94 -80
- package/lib/api/controllers/authController.js +239 -212
- package/lib/api/controllers/baseController.js +89 -51
- package/lib/api/controllers/bulkController.js +62 -49
- package/lib/api/controllers/clusterController.js +6 -8
- package/lib/api/controllers/collectionController.js +140 -129
- package/lib/api/controllers/debugController.d.ts +2 -2
- package/lib/api/controllers/debugController.js +33 -31
- package/lib/api/controllers/documentController.js +365 -274
- package/lib/api/controllers/index.js +13 -13
- package/lib/api/controllers/indexController.js +46 -50
- package/lib/api/controllers/memoryStorageController.js +410 -360
- package/lib/api/controllers/realtimeController.js +37 -36
- package/lib/api/controllers/securityController.js +553 -412
- package/lib/api/controllers/serverController.js +111 -104
- package/lib/api/documentExtractor.js +75 -68
- package/lib/api/funnel.js +411 -312
- package/lib/api/httpRoutes.js +1493 -324
- package/lib/api/openapi/OpenApiManager.d.ts +1 -1
- package/lib/api/openapi/OpenApiManager.js +22 -22
- package/lib/api/openapi/components/document/count.yaml +1 -1
- package/lib/api/openapi/components/document/create.yaml +2 -2
- package/lib/api/openapi/components/document/delete.yaml +1 -1
- package/lib/api/openapi/components/document/deleteByQuery.yaml +1 -1
- package/lib/api/openapi/components/document/exists.yaml +1 -1
- package/lib/api/openapi/components/document/get.yaml +2 -2
- package/lib/api/openapi/components/document/index.js +12 -12
- package/lib/api/openapi/components/document/replace.yaml +1 -1
- package/lib/api/openapi/components/document/scroll.yaml +1 -1
- package/lib/api/openapi/components/document/validate.yaml +1 -1
- package/lib/api/openapi/components/index.d.ts +2 -2
- package/lib/api/openapi/components/index.js +1 -1
- package/lib/api/openapi/components/security/index.js +1 -1
- package/lib/api/openapi/components/security/upsertUser.yaml +2 -3
- package/lib/api/openapi/index.d.ts +1 -1
- package/lib/api/openapi/openApiGenerator.d.ts +1 -1
- package/lib/api/openapi/openApiGenerator.js +7 -7
- package/lib/api/rateLimiter.js +12 -13
- package/lib/api/request/index.d.ts +4 -4
- package/lib/api/request/kuzzleRequest.d.ts +9 -9
- package/lib/api/request/kuzzleRequest.js +91 -90
- package/lib/api/request/requestContext.d.ts +2 -2
- package/lib/api/request/requestContext.js +17 -17
- package/lib/api/request/requestInput.d.ts +1 -1
- package/lib/api/request/requestInput.js +19 -19
- package/lib/api/request/requestResponse.d.ts +4 -4
- package/lib/api/request/requestResponse.js +31 -33
- package/lib/cluster/command.js +48 -44
- package/lib/cluster/idCardHandler.d.ts +1 -1
- package/lib/cluster/idCardHandler.js +15 -15
- package/lib/cluster/index.js +2 -2
- package/lib/cluster/node.js +301 -269
- package/lib/cluster/publisher.js +45 -46
- package/lib/cluster/state.d.ts +5 -5
- package/lib/cluster/state.js +8 -8
- package/lib/cluster/subscriber.js +163 -113
- package/lib/cluster/workers/IDCardRenewer.js +33 -32
- package/lib/config/default.config.d.ts +1 -1
- package/lib/config/default.config.js +212 -171
- package/lib/config/documentEventAliases.js +6 -6
- package/lib/config/index.js +161 -98
- package/lib/config/sdkCompatibility.json +8 -8
- package/lib/core/auth/formatProcessing.js +7 -7
- package/lib/core/auth/passportResponse.js +7 -7
- package/lib/core/auth/passportWrapper.js +34 -30
- package/lib/core/auth/tokenManager.d.ts +2 -2
- package/lib/core/auth/tokenManager.js +11 -10
- package/lib/core/backend/applicationManager.d.ts +1 -1
- package/lib/core/backend/applicationManager.js +2 -2
- package/lib/core/backend/backend.d.ts +4 -4
- package/lib/core/backend/backend.js +34 -31
- package/lib/core/backend/backendCluster.d.ts +8 -9
- package/lib/core/backend/backendCluster.js +8 -8
- package/lib/core/backend/backendConfig.d.ts +2 -2
- package/lib/core/backend/backendConfig.js +3 -3
- package/lib/core/backend/backendController.d.ts +2 -2
- package/lib/core/backend/backendController.js +9 -10
- package/lib/core/backend/backendErrors.d.ts +3 -3
- package/lib/core/backend/backendErrors.js +2 -1
- package/lib/core/backend/backendHook.d.ts +3 -3
- package/lib/core/backend/backendHook.js +5 -5
- package/lib/core/backend/backendImport.d.ts +3 -3
- package/lib/core/backend/backendImport.js +23 -23
- package/lib/core/backend/backendOpenApi.d.ts +2 -2
- package/lib/core/backend/backendOpenApi.js +16 -16
- package/lib/core/backend/backendPipe.d.ts +3 -3
- package/lib/core/backend/backendPipe.js +6 -6
- package/lib/core/backend/backendPlugin.d.ts +4 -4
- package/lib/core/backend/backendPlugin.js +14 -14
- package/lib/core/backend/backendStorage.d.ts +2 -2
- package/lib/core/backend/backendStorage.js +1 -2
- package/lib/core/backend/backendVault.d.ts +2 -2
- package/lib/core/backend/backendVault.js +3 -3
- package/lib/core/backend/index.d.ts +14 -14
- package/lib/core/backend/internalLogger.d.ts +1 -1
- package/lib/core/backend/internalLogger.js +5 -5
- package/lib/core/cache/cacheDbEnum.js +4 -4
- package/lib/core/cache/cacheEngine.js +79 -85
- package/lib/core/network/accessLogger.js +126 -120
- package/lib/core/network/clientConnection.js +5 -5
- package/lib/core/network/context.js +8 -8
- package/lib/core/network/entryPoint.js +100 -85
- package/lib/core/network/httpRouter/index.js +63 -60
- package/lib/core/network/httpRouter/routeHandler.js +18 -19
- package/lib/core/network/httpRouter/routePart.js +23 -19
- package/lib/core/network/protocolManifest.js +3 -3
- package/lib/core/network/protocols/httpMessage.js +8 -10
- package/lib/core/network/protocols/httpwsProtocol.js +305 -250
- package/lib/core/network/protocols/internalProtocol.js +27 -24
- package/lib/core/network/protocols/mqttProtocol.js +106 -96
- package/lib/core/network/protocols/protocol.js +20 -17
- package/lib/core/network/router.js +56 -46
- package/lib/core/plugin/plugin.js +151 -120
- package/lib/core/plugin/pluginContext.d.ts +7 -7
- package/lib/core/plugin/pluginContext.js +48 -44
- package/lib/core/plugin/pluginManifest.js +13 -12
- package/lib/core/plugin/pluginRepository.js +26 -27
- package/lib/core/plugin/pluginsManager.js +425 -304
- package/lib/core/plugin/privilegedContext.js +3 -3
- package/lib/core/realtime/actionEnum.js +1 -1
- package/lib/core/realtime/channel.d.ts +1 -1
- package/lib/core/realtime/channel.js +22 -22
- package/lib/core/realtime/connectionRooms.d.ts +1 -1
- package/lib/core/realtime/hotelClerk.d.ts +2 -2
- package/lib/core/realtime/hotelClerk.js +53 -50
- package/lib/core/realtime/index.js +5 -5
- package/lib/core/realtime/notification/document.js +25 -25
- package/lib/core/realtime/notification/index.js +4 -4
- package/lib/core/realtime/notification/server.js +3 -3
- package/lib/core/realtime/notification/user.js +4 -4
- package/lib/core/realtime/notifier.js +113 -75
- package/lib/core/realtime/room.d.ts +1 -1
- package/lib/core/realtime/subscription.d.ts +1 -1
- package/lib/core/realtime/subscription.js +1 -1
- package/lib/core/security/index.js +8 -8
- package/lib/core/security/profileRepository.d.ts +6 -6
- package/lib/core/security/profileRepository.js +48 -45
- package/lib/core/security/roleRepository.js +127 -115
- package/lib/core/security/securityLoader.js +70 -63
- package/lib/core/security/tokenRepository.js +132 -118
- package/lib/core/security/userRepository.js +104 -88
- package/lib/core/shared/KoncordeWrapper.d.ts +1 -1
- package/lib/core/shared/KoncordeWrapper.js +3 -1
- package/lib/core/shared/abstractManifest.js +22 -23
- package/lib/core/shared/repository.js +69 -67
- package/lib/core/shared/sdk/embeddedSdk.d.ts +2 -2
- package/lib/core/shared/sdk/embeddedSdk.js +36 -32
- package/lib/core/shared/sdk/funnelProtocol.d.ts +1 -1
- package/lib/core/shared/sdk/funnelProtocol.js +11 -11
- package/lib/core/shared/sdk/impersonatedSdk.js +19 -18
- package/lib/core/shared/store.js +127 -32
- package/lib/core/statistics/index.js +2 -2
- package/lib/core/statistics/statistics.js +99 -85
- package/lib/core/storage/clientAdapter.js +219 -136
- package/lib/core/storage/indexCache.js +3 -3
- package/lib/core/storage/storageEngine.js +10 -13
- package/lib/core/storage/storeScopeEnum.js +3 -3
- package/lib/core/validation/baseType.js +12 -10
- package/lib/core/validation/index.js +2 -2
- package/lib/core/validation/types/anything.js +4 -4
- package/lib/core/validation/types/boolean.js +7 -7
- package/lib/core/validation/types/date.js +165 -131
- package/lib/core/validation/types/email.js +18 -21
- package/lib/core/validation/types/enum.js +34 -21
- package/lib/core/validation/types/geoPoint.js +7 -7
- package/lib/core/validation/types/geoShape.js +148 -125
- package/lib/core/validation/types/integer.js +9 -9
- package/lib/core/validation/types/ipAddress.js +17 -19
- package/lib/core/validation/types/numeric.js +36 -29
- package/lib/core/validation/types/object.js +19 -19
- package/lib/core/validation/types/string.js +36 -29
- package/lib/core/validation/types/url.js +17 -19
- package/lib/core/validation/validation.js +422 -378
- package/lib/kerror/codes/1-services.json +7 -1
- package/lib/kerror/codes/4-plugin.json +2 -2
- package/lib/kerror/codes/index.js +85 -63
- package/lib/kerror/errors/badRequestError.d.ts +1 -1
- package/lib/kerror/errors/externalServiceError.d.ts +1 -1
- package/lib/kerror/errors/forbiddenError.d.ts +1 -1
- package/lib/kerror/errors/gatewayTimeoutError.d.ts +1 -1
- package/lib/kerror/errors/index.d.ts +15 -15
- package/lib/kerror/errors/internalError.d.ts +1 -1
- package/lib/kerror/errors/kuzzleError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.js +1 -1
- package/lib/kerror/errors/notFoundError.d.ts +1 -1
- package/lib/kerror/errors/partialError.d.ts +1 -1
- package/lib/kerror/errors/partialError.js +1 -1
- package/lib/kerror/errors/pluginImplementationError.d.ts +1 -1
- package/lib/kerror/errors/pluginImplementationError.js +2 -1
- package/lib/kerror/errors/preconditionError.d.ts +1 -1
- package/lib/kerror/errors/serviceUnavailableError.d.ts +1 -1
- package/lib/kerror/errors/sizeLimitError.d.ts +1 -1
- package/lib/kerror/errors/tooManyRequestsError.d.ts +1 -1
- package/lib/kerror/errors/unauthorizedError.d.ts +1 -1
- package/lib/kerror/index.d.ts +3 -3
- package/lib/kerror/index.js +17 -16
- package/lib/kuzzle/dumpGenerator.js +130 -114
- package/lib/kuzzle/event/kuzzleEventEmitter.js +96 -70
- package/lib/kuzzle/event/pipeRunner.js +26 -25
- package/lib/kuzzle/event/waterfall.js +13 -15
- package/lib/kuzzle/index.js +2 -2
- package/lib/kuzzle/internalIndexHandler.js +80 -59
- package/lib/kuzzle/kuzzle.js +99 -99
- package/lib/kuzzle/kuzzleStateEnum.js +1 -1
- package/lib/kuzzle/log.js +23 -18
- package/lib/kuzzle/vault.js +34 -19
- package/lib/model/security/profile.d.ts +3 -3
- package/lib/model/security/profile.js +38 -37
- package/lib/model/security/rights.js +5 -5
- package/lib/model/security/role.d.ts +3 -3
- package/lib/model/security/role.js +25 -26
- package/lib/model/security/token.d.ts +1 -1
- package/lib/model/security/token.js +4 -4
- package/lib/model/security/user.d.ts +2 -2
- package/lib/model/security/user.js +9 -9
- package/lib/model/storage/apiKey.js +43 -33
- package/lib/model/storage/baseModel.js +49 -45
- package/lib/service/cache/redis.js +60 -55
- package/lib/service/service.js +17 -17
- package/lib/service/storage/elasticsearch.js +839 -755
- package/lib/service/storage/esWrapper.js +103 -86
- package/lib/service/storage/queryTranslator.js +52 -59
- package/lib/types/Controller.d.ts +3 -3
- package/lib/types/ControllerDefinition.d.ts +3 -3
- package/lib/types/DebugModule.d.ts +3 -2
- package/lib/types/DebugModule.js +1 -1
- package/lib/types/EventHandler.d.ts +31 -1
- package/lib/types/Global.d.ts +1 -1
- package/lib/types/HttpStream.d.ts +2 -1
- package/lib/types/HttpStream.js +7 -5
- package/lib/types/Kuzzle.d.ts +1 -1
- package/lib/types/KuzzleDocument.d.ts +1 -1
- package/lib/types/OpenApiDefinition.d.ts +1 -1
- package/lib/types/PasswordPolicy.d.ts +1 -1
- package/lib/types/Plugin.d.ts +8 -8
- package/lib/types/Plugin.js +2 -2
- package/lib/types/Policy.d.ts +1 -1
- package/lib/types/RequestPayload.d.ts +1 -1
- package/lib/types/ResponsePayload.d.ts +1 -1
- package/lib/types/Token.d.ts +1 -1
- package/lib/types/User.d.ts +1 -1
- package/lib/types/config/DumpConfiguration.d.ts +8 -8
- package/lib/types/config/HttpConfiguration.d.ts +1 -1
- package/lib/types/config/KuzzleConfiguration.d.ts +1 -1
- package/lib/types/config/LimitsConfiguration.d.ts +8 -8
- package/lib/types/config/PluginsConfiguration.d.ts +4 -4
- package/lib/types/config/SecurityConfiguration.d.ts +62 -62
- package/lib/types/config/ServerConfiguration.d.ts +55 -55
- package/lib/types/config/ServicesConfiguration.d.ts +2 -2
- package/lib/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +10 -10
- package/lib/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +3 -3
- package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +194 -110
- package/lib/types/errors/ErrorDefinition.d.ts +1 -1
- package/lib/types/errors/ErrorDomains.d.ts +1 -1
- package/lib/types/events/EventGenericDocument.d.ts +26 -0
- package/lib/types/events/EventGenericDocument.js +3 -0
- package/lib/types/index.d.ts +39 -38
- package/lib/types/index.js +1 -0
- package/lib/types/realtime/RealtimeScope.d.ts +1 -1
- package/lib/types/realtime/RealtimeUsers.d.ts +1 -1
- package/lib/util/assertType.js +13 -11
- package/lib/util/async.d.ts +1 -0
- package/lib/util/async.js +61 -0
- package/lib/util/asyncStore.js +19 -21
- package/lib/util/bufferedPassThrough.d.ts +3 -2
- package/lib/util/bufferedPassThrough.js +4 -4
- package/lib/util/bytes.js +9 -13
- package/lib/util/crypto.js +1 -1
- package/lib/util/debug.js +5 -5
- package/lib/util/deprecate.js +24 -21
- package/lib/util/didYouMean.js +7 -7
- package/lib/util/dump-collection.d.ts +2 -2
- package/lib/util/dump-collection.js +26 -26
- package/lib/util/esRequest.d.ts +1 -0
- package/lib/util/esRequest.js +62 -0
- package/lib/util/extractFields.js +24 -25
- package/lib/util/inflector.js +5 -5
- package/lib/util/koncordeCompat.d.ts +2 -2
- package/lib/util/koncordeCompat.js +5 -5
- package/lib/util/memoize.js +3 -5
- package/lib/util/mutex.d.ts +19 -1
- package/lib/util/mutex.js +39 -12
- package/lib/util/name-generator.js +1331 -1331
- package/lib/util/promback.js +8 -10
- package/lib/util/readYamlFile.d.ts +1 -1
- package/lib/util/readYamlFile.js +1 -1
- package/lib/util/requestAssertions.js +34 -34
- package/lib/util/safeObject.js +5 -5
- package/lib/util/stackTrace.js +20 -22
- package/lib/util/wildcard.js +15 -15
- package/package.json +28 -29
- package/npm-shrinkwrap.json +0 -19422
package/lib/core/shared/store.js
CHANGED
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const
|
|
24
|
+
const { Mutex } = require("../../util/mutex");
|
|
25
|
+
const { promiseAllN } = require("../../util/async");
|
|
26
|
+
const kerror = require("../../kerror");
|
|
27
|
+
const { getESIndexDynamicSettings } = require("../../util/esRequest");
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Wrapper around the document store.
|
|
@@ -36,7 +37,7 @@ class Store {
|
|
|
36
37
|
* @param {String} index
|
|
37
38
|
* @param {storeScopeEnum} scope
|
|
38
39
|
*/
|
|
39
|
-
constructor
|
|
40
|
+
constructor(index, scope) {
|
|
40
41
|
this.index = index;
|
|
41
42
|
this.scope = scope;
|
|
42
43
|
|
|
@@ -53,6 +54,7 @@ class Store {
|
|
|
53
54
|
exists: `core:storage:${scope}:document:exist`,
|
|
54
55
|
get: `core:storage:${scope}:document:get`,
|
|
55
56
|
getMapping: `core:storage:${scope}:mappings:get`,
|
|
57
|
+
getSettings: `core:storage:${scope}:collection:settings:get`,
|
|
56
58
|
mExecute: `core:storage:${scope}:document:mExecute`,
|
|
57
59
|
mGet: `core:storage:${scope}:document:mGet`,
|
|
58
60
|
refreshCollection: `core:storage:${scope}:collection:refresh`,
|
|
@@ -71,17 +73,20 @@ class Store {
|
|
|
71
73
|
|
|
72
74
|
// the scroll and multiSearch method are special: they doesn't need an index parameter
|
|
73
75
|
// we keep them for ease of use
|
|
74
|
-
this.scroll = (scrollId, opts) =>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
76
|
+
this.scroll = (scrollId, opts) =>
|
|
77
|
+
global.kuzzle.ask(
|
|
78
|
+
`core:storage:${scope}:document:scroll`,
|
|
79
|
+
scrollId,
|
|
80
|
+
opts
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
this.multiSearch = (targets, searchBody, opts) =>
|
|
84
|
+
global.kuzzle.ask(
|
|
85
|
+
`core:storage:${scope}:document:multiSearch`,
|
|
86
|
+
targets,
|
|
87
|
+
searchBody,
|
|
88
|
+
opts
|
|
89
|
+
);
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
/**
|
|
@@ -91,19 +96,26 @@ class Store {
|
|
|
91
96
|
*
|
|
92
97
|
* @returns {Promise}
|
|
93
98
|
*/
|
|
94
|
-
async init
|
|
95
|
-
const
|
|
96
|
-
timeout:
|
|
99
|
+
async init(collections = {}) {
|
|
100
|
+
const creatingMutex = new Mutex(`Store.init(${this.index})`, {
|
|
101
|
+
timeout: 0,
|
|
97
102
|
ttl: 30000,
|
|
98
103
|
});
|
|
99
104
|
|
|
100
|
-
await
|
|
105
|
+
if (await creatingMutex.lock()) {
|
|
106
|
+
try {
|
|
107
|
+
await this.createCollections(collections, {
|
|
108
|
+
indexCacheOnly: false,
|
|
109
|
+
});
|
|
110
|
+
} finally {
|
|
111
|
+
await creatingMutex.unlock();
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
await creatingMutex.wait({ timeout: -1 });
|
|
101
115
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
finally {
|
|
106
|
-
await mutex.unlock();
|
|
116
|
+
await this.createCollections(collections, {
|
|
117
|
+
indexCacheOnly: true,
|
|
118
|
+
});
|
|
107
119
|
}
|
|
108
120
|
}
|
|
109
121
|
|
|
@@ -114,17 +126,100 @@ class Store {
|
|
|
114
126
|
*
|
|
115
127
|
* @returns {Promise}
|
|
116
128
|
*/
|
|
117
|
-
createCollections
|
|
118
|
-
return
|
|
119
|
-
Object.entries(collections),
|
|
120
|
-
|
|
129
|
+
createCollections(collections, { indexCacheOnly = false } = {}) {
|
|
130
|
+
return promiseAllN(
|
|
131
|
+
Object.entries(collections).map(([collection, config]) => async () => {
|
|
132
|
+
// @deprecated
|
|
133
|
+
if (!(config.mappings !== undefined && config.settings !== undefined)) {
|
|
134
|
+
// @deprecated
|
|
135
|
+
return global.kuzzle.ask(
|
|
136
|
+
`core:storage:${this.scope}:collection:create`,
|
|
137
|
+
this.index,
|
|
138
|
+
collection,
|
|
139
|
+
{ mappings: config },
|
|
140
|
+
{ indexCacheOnly }
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// @deprecated
|
|
145
|
+
const isConfigDeprecated =
|
|
146
|
+
config.settings.number_of_shards === undefined &&
|
|
147
|
+
config.settings.number_of_replicas === undefined;
|
|
148
|
+
|
|
149
|
+
if (indexCacheOnly) {
|
|
150
|
+
return global.kuzzle.ask(
|
|
151
|
+
`core:storage:${this.scope}:collection:create`,
|
|
152
|
+
this.index,
|
|
153
|
+
collection,
|
|
154
|
+
// @deprecated
|
|
155
|
+
isConfigDeprecated ? { mappings: config.mappings } : config,
|
|
156
|
+
{ indexCacheOnly }
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const exist = await global.kuzzle.ask(
|
|
161
|
+
`core:storage:${this.scope}:collection:exist`,
|
|
162
|
+
this.index,
|
|
163
|
+
collection
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
if (exist) {
|
|
167
|
+
// @deprecated
|
|
168
|
+
const dynamicSettings = isConfigDeprecated
|
|
169
|
+
? null
|
|
170
|
+
: getESIndexDynamicSettings(config.settings);
|
|
171
|
+
|
|
172
|
+
const existingSettings = await global.kuzzle.ask(
|
|
173
|
+
`core:storage:${this.scope}:collection:settings:get`,
|
|
174
|
+
this.index,
|
|
175
|
+
collection
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
if (
|
|
179
|
+
!isConfigDeprecated &&
|
|
180
|
+
parseInt(existingSettings.number_of_shards) !==
|
|
181
|
+
config.settings.number_of_shards
|
|
182
|
+
) {
|
|
183
|
+
if (global.NODE_ENV === "development") {
|
|
184
|
+
throw kerror.get(
|
|
185
|
+
"storage",
|
|
186
|
+
"wrong_collection_number_of_shards",
|
|
187
|
+
collection,
|
|
188
|
+
this.index,
|
|
189
|
+
this.scope,
|
|
190
|
+
"number_of_shards",
|
|
191
|
+
config.settings.number_of_shards,
|
|
192
|
+
existingSettings.number_of_shards
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
global.kuzzle.log.warn(
|
|
196
|
+
`Attempt to recreate an existing collection ${collection} of index ${this.index} of scope ${this.scope} with non matching static setting : number_of_shards at ${config.settings.number_of_shards} while existing one is at ${existingSettings.number_of_shards}`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return global.kuzzle.ask(
|
|
201
|
+
`core:storage:${this.scope}:collection:create`,
|
|
202
|
+
this.index,
|
|
203
|
+
collection,
|
|
204
|
+
// @deprecated
|
|
205
|
+
isConfigDeprecated
|
|
206
|
+
? { mappings: config.mappings }
|
|
207
|
+
: { mappings: config.mappings, settings: dynamicSettings },
|
|
208
|
+
{ indexCacheOnly: true }
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
121
212
|
return global.kuzzle.ask(
|
|
122
213
|
`core:storage:${this.scope}:collection:create`,
|
|
123
214
|
this.index,
|
|
124
215
|
collection,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
216
|
+
// @deprecated
|
|
217
|
+
isConfigDeprecated ? { mappings: config.mappings } : config,
|
|
218
|
+
{ indexCacheOnly }
|
|
219
|
+
);
|
|
220
|
+
}),
|
|
221
|
+
10
|
|
222
|
+
);
|
|
128
223
|
}
|
|
129
224
|
}
|
|
130
225
|
|
|
@@ -19,21 +19,21 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
|
-
const errorApiAssert = require(
|
|
25
|
-
const errorStats = require(
|
|
24
|
+
const errorApiAssert = require("../../kerror").wrap("api", "assert");
|
|
25
|
+
const errorStats = require("../../kerror").wrap("services", "stats");
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @class Statistics
|
|
29
29
|
* @param {Kuzzle} kuzzle
|
|
30
30
|
*/
|
|
31
31
|
class Statistics {
|
|
32
|
-
constructor
|
|
32
|
+
constructor() {
|
|
33
33
|
// uses '{' and '}' to force all statistics frames to be stored on 1 redis
|
|
34
34
|
// node
|
|
35
35
|
// (see https://redis.io/topics/cluster-spec#keys-distribution-model)
|
|
36
|
-
this.cacheKeyPrefix =
|
|
36
|
+
this.cacheKeyPrefix = "{stats/}";
|
|
37
37
|
|
|
38
38
|
this.enabled = global.kuzzle.config.stats.enabled;
|
|
39
39
|
this.ttl = global.kuzzle.config.stats.ttl * 1000;
|
|
@@ -45,7 +45,7 @@ class Statistics {
|
|
|
45
45
|
completedRequests: new Map(),
|
|
46
46
|
connections: new Map(),
|
|
47
47
|
failedRequests: new Map(),
|
|
48
|
-
ongoingRequests: new Map()
|
|
48
|
+
ongoingRequests: new Map(),
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -54,24 +54,24 @@ class Statistics {
|
|
|
54
54
|
*
|
|
55
55
|
* @param {Request} request
|
|
56
56
|
*/
|
|
57
|
-
startRequest
|
|
58
|
-
if (!
|
|
57
|
+
startRequest(request) {
|
|
58
|
+
if (!this.enabled) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
const protocol = request && request.context.connection.protocol;
|
|
63
63
|
|
|
64
|
-
if (!
|
|
64
|
+
if (!protocol) {
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
if (!
|
|
68
|
+
if (!this.currentStats.ongoingRequests.has(protocol)) {
|
|
69
69
|
this.currentStats.ongoingRequests.set(protocol, 1);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
70
|
+
} else {
|
|
72
71
|
this.currentStats.ongoingRequests.set(
|
|
73
72
|
protocol,
|
|
74
|
-
this.currentStats.ongoingRequests.get(protocol) + 1
|
|
73
|
+
this.currentStats.ongoingRequests.get(protocol) + 1
|
|
74
|
+
);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -80,28 +80,29 @@ class Statistics {
|
|
|
80
80
|
*
|
|
81
81
|
* @param {Request} request
|
|
82
82
|
*/
|
|
83
|
-
completedRequest
|
|
84
|
-
if (!
|
|
83
|
+
completedRequest(request) {
|
|
84
|
+
if (!this.enabled) {
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
const protocol = request && request.context.connection.protocol;
|
|
89
89
|
|
|
90
|
-
if (!
|
|
90
|
+
if (!protocol) {
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
this.currentStats.ongoingRequests.set(
|
|
95
95
|
protocol,
|
|
96
|
-
this.currentStats.ongoingRequests.get(protocol) - 1
|
|
96
|
+
this.currentStats.ongoingRequests.get(protocol) - 1
|
|
97
|
+
);
|
|
97
98
|
|
|
98
|
-
if (!
|
|
99
|
+
if (!this.currentStats.completedRequests.has(protocol)) {
|
|
99
100
|
this.currentStats.completedRequests.set(protocol, 1);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
101
|
+
} else {
|
|
102
102
|
this.currentStats.completedRequests.set(
|
|
103
103
|
protocol,
|
|
104
|
-
this.currentStats.completedRequests.get(protocol) + 1
|
|
104
|
+
this.currentStats.completedRequests.get(protocol) + 1
|
|
105
|
+
);
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
|
|
@@ -110,28 +111,29 @@ class Statistics {
|
|
|
110
111
|
*
|
|
111
112
|
* @param {Request} request
|
|
112
113
|
*/
|
|
113
|
-
failedRequest
|
|
114
|
-
if (!
|
|
114
|
+
failedRequest(request) {
|
|
115
|
+
if (!this.enabled) {
|
|
115
116
|
return;
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
const protocol = request && request.context.connection.protocol;
|
|
119
120
|
|
|
120
|
-
if (!
|
|
121
|
+
if (!protocol) {
|
|
121
122
|
return;
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
this.currentStats.ongoingRequests.set(
|
|
125
126
|
protocol,
|
|
126
|
-
this.currentStats.ongoingRequests.get(protocol) - 1
|
|
127
|
+
this.currentStats.ongoingRequests.get(protocol) - 1
|
|
128
|
+
);
|
|
127
129
|
|
|
128
|
-
if (!
|
|
130
|
+
if (!this.currentStats.failedRequests.has(protocol)) {
|
|
129
131
|
this.currentStats.failedRequests.set(protocol, 1);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
+
} else {
|
|
132
133
|
this.currentStats.failedRequests.set(
|
|
133
134
|
protocol,
|
|
134
|
-
this.currentStats.failedRequests.get(protocol) + 1
|
|
135
|
+
this.currentStats.failedRequests.get(protocol) + 1
|
|
136
|
+
);
|
|
135
137
|
}
|
|
136
138
|
}
|
|
137
139
|
|
|
@@ -140,22 +142,25 @@ class Statistics {
|
|
|
140
142
|
*
|
|
141
143
|
* @param {RequestContext} requestContext
|
|
142
144
|
*/
|
|
143
|
-
newConnection
|
|
144
|
-
if (!
|
|
145
|
+
newConnection(requestContext) {
|
|
146
|
+
if (!this.enabled) {
|
|
145
147
|
return;
|
|
146
148
|
}
|
|
147
149
|
|
|
148
|
-
if (!
|
|
150
|
+
if (!requestContext.connection.protocol) {
|
|
149
151
|
return;
|
|
150
152
|
}
|
|
151
153
|
|
|
152
|
-
if (
|
|
154
|
+
if (
|
|
155
|
+
!this.currentStats.connections.has(requestContext.connection.protocol)
|
|
156
|
+
) {
|
|
153
157
|
this.currentStats.connections.set(requestContext.connection.protocol, 1);
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
158
|
+
} else {
|
|
156
159
|
this.currentStats.connections.set(
|
|
157
160
|
requestContext.connection.protocol,
|
|
158
|
-
this.currentStats.connections.get(requestContext.connection.protocol) +
|
|
161
|
+
this.currentStats.connections.get(requestContext.connection.protocol) +
|
|
162
|
+
1
|
|
163
|
+
);
|
|
159
164
|
}
|
|
160
165
|
}
|
|
161
166
|
|
|
@@ -164,22 +169,26 @@ class Statistics {
|
|
|
164
169
|
*
|
|
165
170
|
* @param {RequestContext} requestContext
|
|
166
171
|
*/
|
|
167
|
-
dropConnection
|
|
168
|
-
if (!
|
|
172
|
+
dropConnection(requestContext) {
|
|
173
|
+
if (!this.enabled) {
|
|
169
174
|
return;
|
|
170
175
|
}
|
|
171
176
|
|
|
172
|
-
if (!
|
|
177
|
+
if (!requestContext.connection.protocol) {
|
|
173
178
|
return;
|
|
174
179
|
}
|
|
175
180
|
|
|
176
|
-
if (
|
|
181
|
+
if (
|
|
182
|
+
this.currentStats.connections.get(requestContext.connection.protocol) ===
|
|
183
|
+
1
|
|
184
|
+
) {
|
|
177
185
|
this.currentStats.connections.delete(requestContext.connection.protocol);
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
186
|
+
} else {
|
|
180
187
|
this.currentStats.connections.set(
|
|
181
188
|
requestContext.connection.protocol,
|
|
182
|
-
this.currentStats.connections.get(requestContext.connection.protocol) -
|
|
189
|
+
this.currentStats.connections.get(requestContext.connection.protocol) -
|
|
190
|
+
1
|
|
191
|
+
);
|
|
183
192
|
}
|
|
184
193
|
}
|
|
185
194
|
|
|
@@ -188,22 +197,24 @@ class Statistics {
|
|
|
188
197
|
*
|
|
189
198
|
* @returns {Promise}
|
|
190
199
|
*/
|
|
191
|
-
async getLastStats
|
|
192
|
-
if (!
|
|
193
|
-
throw errorStats.get(
|
|
200
|
+
async getLastStats() {
|
|
201
|
+
if (!this.enabled) {
|
|
202
|
+
throw errorStats.get("not_available");
|
|
194
203
|
}
|
|
195
204
|
|
|
196
205
|
const frame = Object.assign(
|
|
197
|
-
{ timestamp:
|
|
198
|
-
this.currentStats
|
|
206
|
+
{ timestamp: new Date().getTime() },
|
|
207
|
+
this.currentStats
|
|
208
|
+
);
|
|
199
209
|
|
|
200
|
-
if (!
|
|
210
|
+
if (!this.lastFrame) {
|
|
201
211
|
return frame;
|
|
202
212
|
}
|
|
203
213
|
|
|
204
214
|
const last = await global.kuzzle.ask(
|
|
205
|
-
|
|
206
|
-
this.cacheKeyPrefix + this.lastFrame
|
|
215
|
+
"core:cache:internal:get",
|
|
216
|
+
this.cacheKeyPrefix + this.lastFrame
|
|
217
|
+
);
|
|
207
218
|
|
|
208
219
|
return Object.assign(frame, JSON.parse(last));
|
|
209
220
|
}
|
|
@@ -214,20 +225,19 @@ class Statistics {
|
|
|
214
225
|
* @param {Request} request
|
|
215
226
|
* @returns {Promise<Object>}
|
|
216
227
|
*/
|
|
217
|
-
async getStats
|
|
218
|
-
if (!
|
|
219
|
-
throw errorStats.get(
|
|
228
|
+
async getStats(request) {
|
|
229
|
+
if (!this.enabled) {
|
|
230
|
+
throw errorStats.get("not_available");
|
|
220
231
|
}
|
|
221
232
|
|
|
222
233
|
const response = {
|
|
223
234
|
hits: [],
|
|
224
|
-
total: null
|
|
235
|
+
total: null,
|
|
225
236
|
};
|
|
226
237
|
const currentDate = new Date().getTime();
|
|
227
238
|
let startTime;
|
|
228
239
|
let stopTime;
|
|
229
240
|
|
|
230
|
-
|
|
231
241
|
if (request && request.input.args && request.input.args.startTime) {
|
|
232
242
|
startTime = isNaN(request.input.args.startTime)
|
|
233
243
|
? new Date(request.input.args.startTime).getTime()
|
|
@@ -241,11 +251,11 @@ class Statistics {
|
|
|
241
251
|
}
|
|
242
252
|
|
|
243
253
|
if (startTime !== undefined && isNaN(startTime)) {
|
|
244
|
-
throw errorApiAssert.get(
|
|
254
|
+
throw errorApiAssert.get("invalid_argument", "startTime", "number");
|
|
245
255
|
}
|
|
246
256
|
|
|
247
257
|
if (stopTime !== undefined && isNaN(stopTime)) {
|
|
248
|
-
throw errorApiAssert.get(
|
|
258
|
+
throw errorApiAssert.get("invalid_argument", "stopTime", "number");
|
|
249
259
|
}
|
|
250
260
|
|
|
251
261
|
if (startTime !== undefined && startTime >= currentDate) {
|
|
@@ -254,18 +264,19 @@ class Statistics {
|
|
|
254
264
|
}
|
|
255
265
|
|
|
256
266
|
const stats = {
|
|
257
|
-
completedRequests: Object.fromEntries(
|
|
267
|
+
completedRequests: Object.fromEntries(
|
|
268
|
+
this.currentStats.completedRequests
|
|
269
|
+
),
|
|
258
270
|
connections: Object.fromEntries(this.currentStats.connections),
|
|
259
271
|
failedRequests: Object.fromEntries(this.currentStats.failedRequests),
|
|
260
272
|
ongoingRequests: Object.fromEntries(this.currentStats.ongoingRequests),
|
|
261
273
|
};
|
|
262
274
|
|
|
263
|
-
if (!
|
|
264
|
-
if (!
|
|
275
|
+
if (!this.lastFrame) {
|
|
276
|
+
if (!stopTime || stopTime >= currentDate) {
|
|
265
277
|
response.hits.push(
|
|
266
|
-
Object.assign(
|
|
267
|
-
|
|
268
|
-
stats));
|
|
278
|
+
Object.assign({ timestamp: new Date(currentDate).getTime() }, stats)
|
|
279
|
+
);
|
|
269
280
|
}
|
|
270
281
|
|
|
271
282
|
response.total = response.hits.length;
|
|
@@ -274,27 +285,31 @@ class Statistics {
|
|
|
274
285
|
}
|
|
275
286
|
|
|
276
287
|
const frames = await global.kuzzle.ask(
|
|
277
|
-
|
|
278
|
-
`${this.cacheKeyPrefix}*`
|
|
288
|
+
"core:cache:internal:searchKeys",
|
|
289
|
+
`${this.cacheKeyPrefix}*`
|
|
290
|
+
);
|
|
279
291
|
|
|
280
292
|
// Statistics keys are timestamp.
|
|
281
293
|
// Ordering them guarantees stats frames to be returned in the right order
|
|
282
294
|
const values = await global.kuzzle.ask(
|
|
283
|
-
|
|
284
|
-
frames.sort()
|
|
295
|
+
"core:cache:internal:mget",
|
|
296
|
+
frames.sort()
|
|
297
|
+
);
|
|
285
298
|
|
|
286
299
|
values.forEach((v, idx) => {
|
|
287
300
|
const regex = new RegExp(`^${this.cacheKeyPrefix}`);
|
|
288
|
-
const frameDate = new Date(Number(frames[idx].replace(regex,
|
|
301
|
+
const frameDate = new Date(Number(frames[idx].replace(regex, "")));
|
|
289
302
|
const frameDateTime = frameDate.getTime();
|
|
290
303
|
|
|
291
|
-
if (
|
|
292
|
-
|
|
304
|
+
if (
|
|
305
|
+
(!startTime || startTime <= frameDateTime) &&
|
|
306
|
+
(!stopTime || stopTime >= frameDateTime)
|
|
293
307
|
) {
|
|
294
308
|
response.hits.push(
|
|
295
|
-
Object.assign(
|
|
296
|
-
|
|
297
|
-
|
|
309
|
+
Object.assign(JSON.parse(v), {
|
|
310
|
+
timestamp: new Date(frameDateTime).getTime(),
|
|
311
|
+
})
|
|
312
|
+
);
|
|
298
313
|
}
|
|
299
314
|
});
|
|
300
315
|
|
|
@@ -308,34 +323,33 @@ class Statistics {
|
|
|
308
323
|
*
|
|
309
324
|
* @returns {Promise<Object>}
|
|
310
325
|
*/
|
|
311
|
-
getAllStats
|
|
326
|
+
getAllStats() {
|
|
312
327
|
return this.getStats();
|
|
313
328
|
}
|
|
314
329
|
|
|
315
330
|
/**
|
|
316
331
|
* Init statistics component
|
|
317
332
|
*/
|
|
318
|
-
init
|
|
319
|
-
if (!
|
|
333
|
+
init() {
|
|
334
|
+
if (!this.enabled) {
|
|
320
335
|
return;
|
|
321
336
|
}
|
|
322
337
|
|
|
323
338
|
this.timer = setInterval(async () => {
|
|
324
339
|
try {
|
|
325
340
|
await this.writeStats();
|
|
326
|
-
}
|
|
327
|
-
catch (error) {
|
|
341
|
+
} catch (error) {
|
|
328
342
|
global.kuzzle.log.error(`Cannot write stats frame: ${error}`);
|
|
329
343
|
}
|
|
330
344
|
}, this.interval);
|
|
331
345
|
|
|
332
|
-
global.kuzzle.on(
|
|
346
|
+
global.kuzzle.on("core:cache:internal:flushdb", () => {
|
|
333
347
|
this.lastFrame = null;
|
|
334
348
|
});
|
|
335
349
|
}
|
|
336
350
|
|
|
337
|
-
async writeStats
|
|
338
|
-
if (!
|
|
351
|
+
async writeStats() {
|
|
352
|
+
if (!this.enabled) {
|
|
339
353
|
return;
|
|
340
354
|
}
|
|
341
355
|
|
|
@@ -346,12 +360,12 @@ class Statistics {
|
|
|
346
360
|
this.currentStats.failedRequests = new Map();
|
|
347
361
|
|
|
348
362
|
await global.kuzzle.ask(
|
|
349
|
-
|
|
363
|
+
"core:cache:internal:store",
|
|
350
364
|
this.cacheKeyPrefix + this.lastFrame,
|
|
351
365
|
stats,
|
|
352
|
-
{ ttl: this.ttl }
|
|
366
|
+
{ ttl: this.ttl }
|
|
367
|
+
);
|
|
353
368
|
}
|
|
354
369
|
}
|
|
355
370
|
|
|
356
|
-
|
|
357
371
|
module.exports = Statistics;
|