Skip to content

Commit c47a610

Browse files
[7.x] Uses the new es client in canvas usage collector's fetch methods (#86668) (#86692)
1 parent 4c3868e commit c47a610

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

x-pack/plugins/canvas/server/collectors/collector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export function registerCanvasUsageCollector(
3737
const canvasCollector = usageCollection.makeUsageCollector<CanvasUsage>({
3838
type: 'canvas',
3939
isReady: () => true,
40-
fetch: async ({ callCluster }: CollectorFetchContext) => {
40+
fetch: async ({ esClient }: CollectorFetchContext) => {
4141
const collectorResults = await Promise.all(
42-
collectors.map((collector) => collector(kibanaIndex, callCluster))
42+
collectors.map((collector) => collector(kibanaIndex, esClient))
4343
);
4444

4545
return collectorResults.reduce((reduction, usage) => {

x-pack/plugins/canvas/server/collectors/custom_element_collector.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { SearchParams } from 'elasticsearch';
7+
import { SearchResponse } from 'elasticsearch';
88
import { get } from 'lodash';
99
import { MakeSchemaFrom } from 'src/plugins/usage_collection/server';
1010
import { collectFns } from './collector_helpers';
@@ -114,17 +114,19 @@ export function summarizeCustomElements(
114114

115115
const customElementCollector: TelemetryCollector = async function customElementCollector(
116116
kibanaIndex,
117-
callCluster
117+
esClient
118118
) {
119-
const customElementParams: SearchParams = {
119+
const customElementParams = {
120120
size: 10000,
121121
index: kibanaIndex,
122122
ignoreUnavailable: true,
123123
filterPath: [`hits.hits._source.${CUSTOM_ELEMENT_TYPE}.content`],
124124
body: { query: { bool: { filter: { term: { type: CUSTOM_ELEMENT_TYPE } } } } },
125125
};
126126

127-
const esResponse = await callCluster<CustomElementSearch>('search', customElementParams);
127+
const { body: esResponse } = await esClient.search<SearchResponse<CustomElementSearch>>(
128+
customElementParams
129+
);
128130

129131
if (get(esResponse, 'hits.hits.length') > 0) {
130132
const customElements = esResponse.hits.hits.map((hit) => hit._source[CUSTOM_ELEMENT_TYPE]);

x-pack/plugins/canvas/server/collectors/workpad_collector.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { SearchParams } from 'elasticsearch';
7+
import { SearchResponse } from 'elasticsearch';
88
import { sum as arraySum, min as arrayMin, max as arrayMax, get } from 'lodash';
99
import { MakeSchemaFrom } from 'src/plugins/usage_collection/server';
1010
import { CANVAS_TYPE } from '../../common/lib/constants';
@@ -229,17 +229,18 @@ export function summarizeWorkpads(workpadDocs: CanvasWorkpad[]): WorkpadTelemetr
229229
variables: variableInfo,
230230
};
231231
}
232+
type ESResponse = SearchResponse<WorkpadSearch>;
232233

233-
const workpadCollector: TelemetryCollector = async function (kibanaIndex, callCluster) {
234-
const searchParams: SearchParams = {
234+
const workpadCollector: TelemetryCollector = async function (kibanaIndex, esClient) {
235+
const searchParams = {
235236
size: 10000, // elasticsearch index.max_result_window default value
236237
index: kibanaIndex,
237238
ignoreUnavailable: true,
238239
filterPath: ['hits.hits._source.canvas-workpad', '-hits.hits._source.canvas-workpad.assets'],
239240
body: { query: { bool: { filter: { term: { type: CANVAS_TYPE } } } } },
240241
};
241242

242-
const esResponse = await callCluster<WorkpadSearch>('search', searchParams);
243+
const { body: esResponse } = await esClient.search<ESResponse>(searchParams);
243244

244245
if (get(esResponse, 'hits.hits.length') > 0) {
245246
const workpads = esResponse.hits.hits.map((hit) => hit._source[CANVAS_TYPE]);

x-pack/plugins/canvas/types/telemetry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { LegacyAPICaller } from 'kibana/server';
7+
import { ElasticsearchClient } from 'kibana/server';
88

99
/**
1010
Function for collecting information about canvas usage
@@ -13,7 +13,7 @@ export type TelemetryCollector = (
1313
/** The server instance */
1414
kibanaIndex: string,
1515
/** Function for calling elasticsearch */
16-
callCluster: LegacyAPICaller
16+
esClient: ElasticsearchClient
1717
) => Record<string, any>;
1818

1919
export interface TelemetryCustomElementDocument {

0 commit comments

Comments
 (0)