diff --git a/src/plugins/visualizations/server/usage_collector/get_usage_collector.test.ts b/src/plugins/visualizations/server/usage_collector/get_usage_collector.test.ts index fd363b3505186..970948fad52cb 100644 --- a/src/plugins/visualizations/server/usage_collector/get_usage_collector.test.ts +++ b/src/plugins/visualizations/server/usage_collector/get_usage_collector.test.ts @@ -18,7 +18,7 @@ */ import moment from 'moment'; -import { LegacyAPICaller } from 'src/core/server'; +import { ElasticsearchClient } from 'src/core/server'; import { getStats } from './get_usage_collector'; const defaultMockSavedObjects = [ @@ -120,8 +120,11 @@ const enlargedMockSavedObjects = [ describe('Visualizations usage collector', () => { const mockIndex = ''; + const getMockCallCluster = (hits: unknown[]) => - (() => Promise.resolve({ hits: { hits } }) as unknown) as LegacyAPICaller; + ({ + search: () => Promise.resolve({ body: { hits: { hits } } }) as unknown, + } as ElasticsearchClient); test('Returns undefined when no results found (undefined)', async () => { const result = await getStats(getMockCallCluster(undefined as any), mockIndex); diff --git a/src/plugins/visualizations/server/usage_collector/get_usage_collector.ts b/src/plugins/visualizations/server/usage_collector/get_usage_collector.ts index aed9a54dcf01a..83ae67347e915 100644 --- a/src/plugins/visualizations/server/usage_collector/get_usage_collector.ts +++ b/src/plugins/visualizations/server/usage_collector/get_usage_collector.ts @@ -18,11 +18,10 @@ */ import { countBy, get, groupBy, mapValues, max, min, values } from 'lodash'; +import { ElasticsearchClient } from 'kibana/server'; import { SearchResponse } from 'elasticsearch'; -import { LegacyAPICaller } from 'src/core/server'; import { getPastDays } from './get_past_days'; - type ESResponse = SearchResponse<{ visualization: { visState: string } }>; interface VisSummary { @@ -47,7 +46,7 @@ export interface VisualizationUsage { * Parse the response data into telemetry payload */ export async function getStats( - callCluster: LegacyAPICaller, + esClient: ElasticsearchClient, index: string ): Promise { const searchParams = { @@ -65,7 +64,7 @@ export async function getStats( }, }, }; - const esResponse: ESResponse = await callCluster('search', searchParams); + const { body: esResponse } = await esClient.search(searchParams); const size = get(esResponse, 'hits.hits.length', 0); if (size < 1) { return; diff --git a/src/plugins/visualizations/server/usage_collector/register_visualizations_collector.test.ts b/src/plugins/visualizations/server/usage_collector/register_visualizations_collector.test.ts index 380a86e15aa51..5d65666da544d 100644 --- a/src/plugins/visualizations/server/usage_collector/register_visualizations_collector.test.ts +++ b/src/plugins/visualizations/server/usage_collector/register_visualizations_collector.test.ts @@ -62,7 +62,7 @@ describe('registerVisualizationsCollector', () => { const mockCollectorFetchContext = createCollectorFetchContextMock(); const fetchResult = await usageCollector.fetch(mockCollectorFetchContext); expect(mockGetStats).toBeCalledTimes(1); - expect(mockGetStats).toBeCalledWith(mockCollectorFetchContext.callCluster, mockIndex); + expect(mockGetStats).toBeCalledWith(mockCollectorFetchContext.esClient, mockIndex); expect(fetchResult).toBe(mockStats); }); }); diff --git a/src/plugins/visualizations/server/usage_collector/register_visualizations_collector.ts b/src/plugins/visualizations/server/usage_collector/register_visualizations_collector.ts index 4188f564ed5fd..11c562f764ce8 100644 --- a/src/plugins/visualizations/server/usage_collector/register_visualizations_collector.ts +++ b/src/plugins/visualizations/server/usage_collector/register_visualizations_collector.ts @@ -41,9 +41,9 @@ export function registerVisualizationsCollector( saved_90_days_total: { type: 'long' }, }, }, - fetch: async ({ callCluster }) => { + fetch: async ({ esClient }) => { const index = (await config.pipe(first()).toPromise()).kibana.index; - return await getStats(callCluster, index); + return await getStats(esClient, index); }, }); collectorSet.registerCollector(collector);