mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[QA][SO INFO SVC] Add jq filtering (#113302)
This commit is contained in:
parent
33b501c5c7
commit
0b4a8c081c
6 changed files with 687 additions and 54 deletions
|
@ -771,6 +771,7 @@
|
|||
"multimatch": "^4.0.0",
|
||||
"mutation-observer": "^1.0.3",
|
||||
"ncp": "^2.0.0",
|
||||
"node-jq": "2.0.0",
|
||||
"node-sass": "^6.0.1",
|
||||
"null-loader": "^3.0.0",
|
||||
"nyc": "^15.0.1",
|
||||
|
|
|
@ -1,6 +1,70 @@
|
|||
# Tips for using the SO INFO SVC CLI with JQ
|
||||
# Tips for using the SO INFO SVC
|
||||
|
||||
## Myriad ways to use jq to discern discrete info from the svc
|
||||
## From an FTR test
|
||||
```
|
||||
...
|
||||
const soInfo = getService('savedObjectInfo');
|
||||
const log = getService('log');
|
||||
|
||||
describe('some test suite', function () {
|
||||
...
|
||||
|
||||
after(async () => {
|
||||
// "Normal" logging, without JQ
|
||||
await soInfo.logSoTypes(log);
|
||||
// Without a title, using JQ
|
||||
await soInfo.filterSoTypes(log, '.[] | .key');
|
||||
// With a title, using JQ
|
||||
await soInfo.filterSoTypes(
|
||||
log,
|
||||
'reduce .[].doc_count as $item (0; . + $item)',
|
||||
'TOTAL count of ALL Saved Object types'
|
||||
);
|
||||
// With a title, using JQ
|
||||
await soInfo.filterSoTypes(
|
||||
log,
|
||||
'.[] | select(.key =="canvas-workpad-template") | .doc_count',
|
||||
'TOTAL count of canvas-workpad-template'
|
||||
);
|
||||
});
|
||||
```
|
||||
|
||||
## From the CLI
|
||||
|
||||
Run the cli
|
||||
> the **--esUrl** arg is required; tells the svc which elastic search endpoint to use
|
||||
|
||||
```shell
|
||||
λ node scripts/saved_objs_info.js --esUrl http://elastic:changeme@localhost:9220 --soTypes
|
||||
```
|
||||
|
||||
Result
|
||||
|
||||
```shell
|
||||
### types:
|
||||
|
||||
[
|
||||
{
|
||||
doc_count: 5,
|
||||
key: 'canvas-workpad-template'
|
||||
},
|
||||
{
|
||||
doc_count: 1,
|
||||
key: 'apm-telemetry'
|
||||
},
|
||||
{
|
||||
doc_count: 1,
|
||||
key: 'config'
|
||||
},
|
||||
{
|
||||
doc_count: 1,
|
||||
key: 'space'
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
### Myriad ways to use JQ to discern discrete info from the svc
|
||||
Below, I will leave out the so types call, which is:
|
||||
`node scripts/saved_objs_info.js --esUrl http://elastic:changeme@localhost:9220 --soTypes --json`
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ Show information pertaining to the saved objects in the .kibana index
|
|||
|
||||
Examples:
|
||||
|
||||
See 'saved_objects_info_svc.md'
|
||||
See 'README.md'
|
||||
|
||||
`,
|
||||
flags: expectedFlags(),
|
||||
|
|
|
@ -13,6 +13,7 @@ import { flow, pipe } from 'fp-ts/function';
|
|||
import * as TE from 'fp-ts/lib/TaskEither';
|
||||
import * as T from 'fp-ts/lib/Task';
|
||||
import { ToolingLog } from '@kbn/dev-utils';
|
||||
import { run as jq } from 'node-jq';
|
||||
import { FtrService } from '../../ftr_provider_context';
|
||||
import { print } from './utils';
|
||||
|
||||
|
@ -60,8 +61,22 @@ export const types =
|
|||
export class SavedObjectInfoService extends FtrService {
|
||||
private readonly config = this.ctx.getService('config');
|
||||
|
||||
private readonly typesF = async () =>
|
||||
await types(url.format(this.config.get('servers.elasticsearch')))();
|
||||
|
||||
public async logSoTypes(log: ToolingLog, msg: string | null = null) {
|
||||
// @ts-ignore
|
||||
pipe(await types(url.format(this.config.get('servers.elasticsearch'))), print(log)(msg));
|
||||
pipe(await this.typesF(), print(log)(msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* See test/common/services/saved_object_info/README.md for "jq filtering" ideas.
|
||||
*/
|
||||
public async filterSoTypes(log: ToolingLog, jqFilter: string, title: string | null = null) {
|
||||
pipe(await this.typesF(), filterAndLog);
|
||||
|
||||
async function filterAndLog(payload: any) {
|
||||
log.info(`${title ? title + '\n' : ''}${await jq(jqFilter, payload, { input: 'json' })}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
# Saved Objects Info Svc w/ CLI
|
||||
|
||||
## Used via the cli
|
||||
|
||||
Run the cli
|
||||
> the **--esUrl** arg is required; tells the svc which elastic search endpoint to use
|
||||
|
||||
```shell
|
||||
λ node scripts/saved_objs_info.js --esUrl http://elastic:changeme@localhost:9220 --soTypes
|
||||
```
|
||||
|
||||
Result
|
||||
|
||||
```shell
|
||||
### types:
|
||||
|
||||
[
|
||||
{
|
||||
doc_count: 5,
|
||||
key: 'canvas-workpad-template'
|
||||
},
|
||||
{
|
||||
doc_count: 1,
|
||||
key: 'apm-telemetry'
|
||||
},
|
||||
{
|
||||
doc_count: 1,
|
||||
key: 'config'
|
||||
},
|
||||
{
|
||||
doc_count: 1,
|
||||
key: 'space'
|
||||
}
|
||||
]
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue