From 84682fb8c2051174363a8ae725797dce49362a2f Mon Sep 17 00:00:00 2001 From: Leodau Date: Sun, 7 Mar 2021 19:54:05 +0100 Subject: [PATCH 1/8] feat(stats): implement base index:stats boilerplate --- src/controllers/Index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/controllers/Index.ts b/src/controllers/Index.ts index 61fc13c10..d01cafcfe 100644 --- a/src/controllers/Index.ts +++ b/src/controllers/Index.ts @@ -99,4 +99,19 @@ export class IndexController extends BaseController { return this.query(request, options) .then(response => response.result.deleted); } + + /** + * Returns detailed storage usage statistics. + * + * @see https://docs.kuzzle.io/sdk/js/7/controllers/index/stats/ + * + * @param options Additional options + * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again + */ + stats (options: { queuable?: boolean } = {}): Promise { + return this.query({ + action: 'stats' + }, options) + .then(response => response.result); + } } From 1e7064eaedcf2e44a4feaa67c670c57fbe5242b0 Mon Sep 17 00:00:00 2001 From: Michele Date: Wed, 10 Mar 2021 10:47:20 +0100 Subject: [PATCH 2/8] doc(index): create a stat doc page & nippet + test --- doc/7/controllers/index/stats/index.md | 41 +++++++++++++++++++ .../controllers/index/stats/snippets/stats.js | 3 ++ .../index/stats/snippets/stats.test.yml | 10 +++++ 3 files changed, 54 insertions(+) create mode 100644 doc/7/controllers/index/stats/index.md create mode 100644 doc/7/controllers/index/stats/snippets/stats.js create mode 100644 doc/7/controllers/index/stats/snippets/stats.test.yml diff --git a/doc/7/controllers/index/stats/index.md b/doc/7/controllers/index/stats/index.md new file mode 100644 index 000000000..b28888954 --- /dev/null +++ b/doc/7/controllers/index/stats/index.md @@ -0,0 +1,41 @@ +--- +code: true +type: page +title: stats +description: Gets detailed storage statistics +--- + +# stats + + + + +Gets detailed storage usage statistics. + +
+ +```js +stats([options]); +``` + +
+ +| Arguments | Type | Description | +| --------- | ----------------- | ------------- | +| `options` |
object
| Query options | + +### options + +Additional query options + +| Property | Type
(default) | Description | +| ---------- | ------------------------------- | ---------------------------------------------------------------------------- | +| `queuable` |
boolean

(`true`) | If true, queues the request during downtime, until connected to Kuzzle again | + +## Resolves + +Returns detailed storage usage statistics: overall index/collection sizes and the number of documents per collection. + +## Usage + +<<< ./snippets/stats.js diff --git a/doc/7/controllers/index/stats/snippets/stats.js b/doc/7/controllers/index/stats/snippets/stats.js new file mode 100644 index 000000000..1e3c4b234 --- /dev/null +++ b/doc/7/controllers/index/stats/snippets/stats.js @@ -0,0 +1,3 @@ +const stats = await kuzzle.index.stats(); + +console.log(JSON.stringify(stats)); diff --git a/doc/7/controllers/index/stats/snippets/stats.test.yml b/doc/7/controllers/index/stats/snippets/stats.test.yml new file mode 100644 index 000000000..abf725fa9 --- /dev/null +++ b/doc/7/controllers/index/stats/snippets/stats.test.yml @@ -0,0 +1,10 @@ +--- +name: index#stats +description: Gets detailed storage statistics +hooks: + before: | + curl -X POST kuzzle:7512/nyc-open-data/_create + curl -XPUT kuzzle:7512/nyc-open-data/yellow-taxi + after: curl -X DELETE kuzzle:7512/nyc-open-data +template: catch +expected: ["documentCount":0] From 33bfcb0018908b502423f0cc3cbfc5f1246f028e Mon Sep 17 00:00:00 2001 From: Michele Date: Wed, 10 Mar 2021 18:45:05 +0100 Subject: [PATCH 3/8] test(index): implement unit test for index:stats action --- test/controllers/index.test.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/controllers/index.test.js b/test/controllers/index.test.js index 8bd2e901a..1f5d3846f 100644 --- a/test/controllers/index.test.js +++ b/test/controllers/index.test.js @@ -120,4 +120,37 @@ describe('Index Controller', () => { }); }); }); + + describe.only('stats', () => { + it('should call index/stats query and return a Promise which resolves to an object containing detailed storage statistics', () => { + const result = { + indexes: [ + { + name: 'nyc-open-data', + size: 42, + collections: [ + { + name: 'yellow-taxi', + documentCount: 42, + size: 42, + } + ] + } + ] + }; + kuzzle.query.resolves({result}); + + return kuzzle.index.stats(options) + .then(res => { + should(kuzzle.query) + .be.calledOnce() + .be.calledWith({ + controller: 'index', + action: 'stats' + }, options); + + should(res).be.equal(result); + }); + }); + }); }); From 4155c9ae064d7a6a74e53a990c977cd1d5fcd42b Mon Sep 17 00:00:00 2001 From: Michele Date: Wed, 10 Mar 2021 18:53:43 +0100 Subject: [PATCH 4/8] fix(index): remove forgotten unit .only --- test/controllers/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/controllers/index.test.js b/test/controllers/index.test.js index 1f5d3846f..a76c45f0d 100644 --- a/test/controllers/index.test.js +++ b/test/controllers/index.test.js @@ -121,7 +121,7 @@ describe('Index Controller', () => { }); }); - describe.only('stats', () => { + describe('stats', () => { it('should call index/stats query and return a Promise which resolves to an object containing detailed storage statistics', () => { const result = { indexes: [ From f8777e7046218a584de2adaf215f1125d26e1bc0 Mon Sep 17 00:00:00 2001 From: Michele Date: Thu, 11 Mar 2021 13:55:38 +0100 Subject: [PATCH 5/8] docs(index): add stats result example in snippet --- doc/7/controllers/index/stats/snippets/stats.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/7/controllers/index/stats/snippets/stats.js b/doc/7/controllers/index/stats/snippets/stats.js index 1e3c4b234..a366db9cd 100644 --- a/doc/7/controllers/index/stats/snippets/stats.js +++ b/doc/7/controllers/index/stats/snippets/stats.js @@ -1,3 +1,19 @@ const stats = await kuzzle.index.stats(); console.log(JSON.stringify(stats)); +/* + indexes: [ + { + name: 'nyc-open-data', + size: 42, + collections: [ + { + name: 'yellow-taxi', + documentCount: 42, + size: 42, + } + ] + } + ], + size: 42 +*/ From 48838aae4e4d72e1d78c38af1bca22c49cbe7400 Mon Sep 17 00:00:00 2001 From: Michele Date: Thu, 11 Mar 2021 13:58:34 +0100 Subject: [PATCH 6/8] doc(index): stats result in snippet as JSON instead --- .../controllers/index/stats/snippets/stats.js | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/doc/7/controllers/index/stats/snippets/stats.js b/doc/7/controllers/index/stats/snippets/stats.js index a366db9cd..ca75ccb33 100644 --- a/doc/7/controllers/index/stats/snippets/stats.js +++ b/doc/7/controllers/index/stats/snippets/stats.js @@ -2,18 +2,20 @@ const stats = await kuzzle.index.stats(); console.log(JSON.stringify(stats)); /* - indexes: [ - { - name: 'nyc-open-data', - size: 42, - collections: [ - { - name: 'yellow-taxi', - documentCount: 42, - size: 42, - } - ] - } - ], - size: 42 + { + "indexes":[ + { + "name":"nyc-open-data", + "size":42, + "collections":[ + { + "name":"yellow-taxi", + "documentCount":42, + "size":42 + } + ] + } + ], + "size":42 + } */ From 9f4e5f1d80e8cea2909065abb7ab09ea4325b803 Mon Sep 17 00:00:00 2001 From: Michele Leo Date: Thu, 11 Mar 2021 16:36:15 +0100 Subject: [PATCH 7/8] Update src/controllers/Index.ts Co-authored-by: Adrien Maret --- src/controllers/Index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/Index.ts b/src/controllers/Index.ts index d01cafcfe..bc1490a35 100644 --- a/src/controllers/Index.ts +++ b/src/controllers/Index.ts @@ -108,7 +108,7 @@ export class IndexController extends BaseController { * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again */ - stats (options: { queuable?: boolean } = {}): Promise { + stats (options: { queuable?: boolean } = {}): Promise { return this.query({ action: 'stats' }, options) From 5f3684c4e14c089d4ea00d11cff7775396fa1bdf Mon Sep 17 00:00:00 2001 From: Leodau Date: Sat, 13 Mar 2021 16:07:33 +0100 Subject: [PATCH 8/8] fix(index): import jsonobject type --- src/controllers/Index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/Index.ts b/src/controllers/Index.ts index bc1490a35..e2fabafef 100644 --- a/src/controllers/Index.ts +++ b/src/controllers/Index.ts @@ -1,4 +1,5 @@ import { BaseController } from './Base'; +import { JSONObject } from '../types'; export class IndexController extends BaseController {