Skip to content

Commit

Permalink
Switches rollup usage collector's fetch es client to the client
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers committed Dec 21, 2020
1 parent 513138b commit f775297
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions x-pack/plugins/rollup/server/collectors/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +56,7 @@ async function fetchRollupIndexPatterns(kibanaIndex: string, callCluster: Legacy

async function fetchRollupSavedSearches(
kibanaIndex: string,
callCluster: LegacyAPICaller,
esClient: ElasticsearchClient,
rollupIndexPatternToFlagMap: IdToFlagMap
) {
const searchParams = {
Expand All @@ -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.
Expand All @@ -104,7 +104,7 @@ async function fetchRollupSavedSearches(

async function fetchRollupVisualizations(
kibanaIndex: string,
callCluster: LegacyAPICaller,
esClient: ElasticsearchClient,
rollupIndexPatternToFlagMap: IdToFlagMap,
rollupSavedSearchesToFlagMap: IdToFlagMap
) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -227,7 +227,7 @@ export function registerRollupUsageCollector(
rollupVisualizationsFromSavedSearches,
} = await fetchRollupVisualizations(
kibanaIndex,
callCluster,
esClient,
rollupIndexPatternToFlagMap,
rollupSavedSearchesToFlagMap
);
Expand Down

0 comments on commit f775297

Please sign in to comment.