From d6eda39ceca02eb0cd8f9e83fef9425af4503d8a Mon Sep 17 00:00:00 2001 From: "Christiane (Tina) Heiligers" Date: Mon, 4 Jan 2021 11:32:14 -0700 Subject: [PATCH] Switches rollup usage collector's fetch es client to the new client (#86684) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../rollup/server/collectors/register.ts | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/rollup/server/collectors/register.ts b/x-pack/plugins/rollup/server/collectors/register.ts index 33bb430aefe5e..ea7be9e76c9f2 100644 --- a/x-pack/plugins/rollup/server/collectors/register.ts +++ b/x-pack/plugins/rollup/server/collectors/register.ts @@ -6,7 +6,7 @@ import { get } from 'lodash'; import { UsageCollectionSetup, CollectorFetchContext } from 'src/plugins/usage_collection/server'; -import { LegacyAPICaller } from 'kibana/server'; +import { ElasticsearchClient } from 'kibana/server'; interface IdToFlagMap { [key: string]: boolean; @@ -27,7 +27,7 @@ function createIdToFlagMap(ids: string[]) { }, {} as any); } -async function fetchRollupIndexPatterns(kibanaIndex: string, callCluster: LegacyAPICaller) { +async function fetchRollupIndexPatterns(kibanaIndex: string, esClient: ElasticsearchClient) { const searchParams = { size: ES_MAX_RESULT_WINDOW_DEFAULT_VALUE, index: kibanaIndex, @@ -46,7 +46,7 @@ async function fetchRollupIndexPatterns(kibanaIndex: string, callCluster: Legacy }, }; - const esResponse = await callCluster('search', searchParams); + const { body: esResponse } = await esClient.search(searchParams); return get(esResponse, 'hits.hits', []).map((indexPattern: any) => { const { _id: savedObjectId } = indexPattern; @@ -56,7 +56,7 @@ async function fetchRollupIndexPatterns(kibanaIndex: string, callCluster: Legacy async function fetchRollupSavedSearches( kibanaIndex: string, - callCluster: LegacyAPICaller, + esClient: ElasticsearchClient, rollupIndexPatternToFlagMap: IdToFlagMap ) { const searchParams = { @@ -77,7 +77,7 @@ async function fetchRollupSavedSearches( }, }; - const esResponse = await callCluster('search', searchParams); + const { body: esResponse } = await esClient.search(searchParams); const savedSearches = get(esResponse, 'hits.hits', []); // Filter for ones with rollup index patterns. @@ -104,7 +104,7 @@ async function fetchRollupSavedSearches( async function fetchRollupVisualizations( kibanaIndex: string, - callCluster: LegacyAPICaller, + esClient: ElasticsearchClient, rollupIndexPatternToFlagMap: IdToFlagMap, rollupSavedSearchesToFlagMap: IdToFlagMap ) { @@ -130,7 +130,7 @@ async function fetchRollupVisualizations( }, }; - const esResponse = await callCluster('search', searchParams); + const { body: esResponse } = await esClient.search(searchParams); const visualizations = get(esResponse, 'hits.hits', []); let rollupVisualizations = 0; @@ -211,13 +211,13 @@ export function registerRollupUsageCollector( total: { type: 'long' }, }, }, - fetch: async ({ callCluster }: CollectorFetchContext) => { - const rollupIndexPatterns = await fetchRollupIndexPatterns(kibanaIndex, callCluster); + fetch: async ({ esClient }: CollectorFetchContext) => { + const rollupIndexPatterns = await fetchRollupIndexPatterns(kibanaIndex, esClient); const rollupIndexPatternToFlagMap = createIdToFlagMap(rollupIndexPatterns); const rollupSavedSearches = await fetchRollupSavedSearches( kibanaIndex, - callCluster, + esClient, rollupIndexPatternToFlagMap ); const rollupSavedSearchesToFlagMap = createIdToFlagMap(rollupSavedSearches); @@ -227,7 +227,7 @@ export function registerRollupUsageCollector( rollupVisualizationsFromSavedSearches, } = await fetchRollupVisualizations( kibanaIndex, - callCluster, + esClient, rollupIndexPatternToFlagMap, rollupSavedSearchesToFlagMap );