Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switches rollup usage collector's fetch es client to the new client #86684

Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 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 All @@ -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,
Expand All @@ -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;
Expand All @@ -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) => {
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);
Expand All @@ -227,7 +227,7 @@ export function registerRollupUsageCollector(
rollupVisualizationsFromSavedSearches,
} = await fetchRollupVisualizations(
kibanaIndex,
callCluster,
esClient,
rollupIndexPatternToFlagMap,
rollupSavedSearchesToFlagMap
);
Expand Down