[QA][SO INFO SVC] Add jq filtering (#113302)

This commit is contained in:
Tre 2021-10-01 11:52:20 -04:00 committed by GitHub
parent 33b501c5c7
commit 0b4a8c081c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 687 additions and 54 deletions

View file

@ -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",

View file

@ -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`

View file

@ -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(),

View file

@ -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' })}`);
}
}
}

View file

@ -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'
}
]
```

618
yarn.lock

File diff suppressed because it is too large Load diff