From f775297ea6471cc13c30e6b3b2a4de454e10be97 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Mon, 21 Dec 2020 11:58:05 -0700 Subject: [PATCH 1/2] Switches rollup usage collector's fetch es client to the client --- .../plugins/rollup/server/collectors/register.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/rollup/server/collectors/register.ts b/x-pack/plugins/rollup/server/collectors/register.ts index 33bb430aefe5e2..cf040d1a6113a5 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; @@ -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) => { + fetch: async ({ esClient }: CollectorFetchContext) => { const rollupIndexPatterns = await fetchRollupIndexPatterns(kibanaIndex, callCluster); 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 ); From 0abf9783ae338708014b2689cf2d992b9662bc47 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Mon, 21 Dec 2020 12:40:17 -0700 Subject: [PATCH 2/2] Refactors remaining search request --- x-pack/plugins/rollup/server/collectors/register.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/rollup/server/collectors/register.ts b/x-pack/plugins/rollup/server/collectors/register.ts index cf040d1a6113a5..ea7be9e76c9f2e 100644 --- a/x-pack/plugins/rollup/server/collectors/register.ts +++ b/x-pack/plugins/rollup/server/collectors/register.ts @@ -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; @@ -212,7 +212,7 @@ export function registerRollupUsageCollector( }, }, fetch: async ({ esClient }: CollectorFetchContext) => { - const rollupIndexPatterns = await fetchRollupIndexPatterns(kibanaIndex, callCluster); + const rollupIndexPatterns = await fetchRollupIndexPatterns(kibanaIndex, esClient); const rollupIndexPatternToFlagMap = createIdToFlagMap(rollupIndexPatterns); const rollupSavedSearches = await fetchRollupSavedSearches(