From 35a193d8d65fd3e0da702ba793a7704b3cafb096 Mon Sep 17 00:00:00 2001 From: Tre Date: Wed, 26 May 2021 12:00:21 -0600 Subject: [PATCH] [QA] Add saved objects info svc (#96364) (#100700) Add svc and fn to return saved object types in a given index, defaulted to ".kibana" index. --- test/common/services/index.ts | 2 + test/common/services/saved_object_info.ts | 53 ++++++++++++++++++++++ test/functional/apps/discover/_discover.ts | 4 ++ 3 files changed, 59 insertions(+) create mode 100644 test/common/services/saved_object_info.ts diff --git a/test/common/services/index.ts b/test/common/services/index.ts index 8003d84ff97459..d1f63d6fb87465 100644 --- a/test/common/services/index.ts +++ b/test/common/services/index.ts @@ -15,6 +15,7 @@ import { RetryService } from './retry'; import { RandomnessService } from './randomness'; import { SecurityServiceProvider } from './security'; import { EsDeleteAllIndicesProvider } from './es_delete_all_indices'; +import { SavedObjectInfoProvider } from './saved_object_info'; export const services = { deployment: DeploymentService, @@ -26,4 +27,5 @@ export const services = { randomness: RandomnessService, security: SecurityServiceProvider, esDeleteAllIndices: EsDeleteAllIndicesProvider, + savedObjectInfo: SavedObjectInfoProvider, }; diff --git a/test/common/services/saved_object_info.ts b/test/common/services/saved_object_info.ts new file mode 100644 index 00000000000000..02ab38d4ecb1db --- /dev/null +++ b/test/common/services/saved_object_info.ts @@ -0,0 +1,53 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { Client } from '@elastic/elasticsearch'; +import url from 'url'; +import { Either, fromNullable, chain, getOrElse } from 'fp-ts/Either'; +import { flow } from 'fp-ts/function'; +import { FtrProviderContext } from '../ftr_provider_context'; + +const pluck = (key: string) => (obj: any): Either => + fromNullable(new Error(`Missing ${key}`))(obj[key]); + +const types = (node: string) => async (index: string = '.kibana') => { + let res: unknown; + try { + const { body } = await new Client({ node }).search({ + index, + body: { + aggs: { + savedobjs: { + terms: { + field: 'type', + }, + }, + }, + }, + }); + + res = flow( + pluck('aggregations'), + chain(pluck('savedobjs')), + chain(pluck('buckets')), + getOrElse((err) => `${err.message}`) + )(body); + } catch (err) { + throw new Error(`Error while searching for saved object types: ${err}`); + } + + return res; +}; + +export const SavedObjectInfoProvider: any = ({ getService }: FtrProviderContext) => { + const config = getService('config'); + + return { + types: types(url.format(config.get('servers.elasticsearch'))), + }; +}; diff --git a/test/functional/apps/discover/_discover.ts b/test/functional/apps/discover/_discover.ts index 2eaf9f2bb9ec71..c464928c742961 100644 --- a/test/functional/apps/discover/_discover.ts +++ b/test/functional/apps/discover/_discover.ts @@ -11,6 +11,7 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ getService, getPageObjects }: FtrProviderContext) { + const savedObjectInfo = getService('savedObjectInfo'); const browser = getService('browser'); const log = getService('log'); const retry = getService('retry'); @@ -30,6 +31,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { log.debug('load kibana index with default index pattern'); await kibanaServer.importExport.load('discover'); + log.info( + `\n### SAVED OBJECT TYPES IN index: [.kibana]: \n\t${await savedObjectInfo.types()}` + ); // and load a set of makelogs data await esArchiver.loadIfNeeded('logstash_functional');