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

Uses the new es client in canvas usage collector's fetch methods #86668

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions x-pack/plugins/canvas/server/collectors/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export function registerCanvasUsageCollector(
const canvasCollector = usageCollection.makeUsageCollector<CanvasUsage>({
type: 'canvas',
isReady: () => true,
fetch: async ({ callCluster }: CollectorFetchContext) => {
fetch: async ({ esClient }: CollectorFetchContext) => {
const collectorResults = await Promise.all(
collectors.map((collector) => collector(kibanaIndex, callCluster))
collectors.map((collector) => collector(kibanaIndex, esClient))
);

return collectorResults.reduce((reduction, usage) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SearchParams } from 'elasticsearch';
import { SearchResponse } from 'elasticsearch';
import { get } from 'lodash';
import { MakeSchemaFrom } from 'src/plugins/usage_collection/server';
import { collectFns } from './collector_helpers';
Expand Down Expand Up @@ -114,17 +114,19 @@ export function summarizeCustomElements(

const customElementCollector: TelemetryCollector = async function customElementCollector(
kibanaIndex,
callCluster
esClient
) {
const customElementParams: SearchParams = {
const customElementParams = {
size: 10000,
index: kibanaIndex,
ignoreUnavailable: true,
filterPath: [`hits.hits._source.${CUSTOM_ELEMENT_TYPE}.content`],
body: { query: { bool: { filter: { term: { type: CUSTOM_ELEMENT_TYPE } } } } },
};

const esResponse = await callCluster<CustomElementSearch>('search', customElementParams);
const { body: esResponse } = await esClient.search<SearchResponse<CustomElementSearch>>(
customElementParams
);

if (get(esResponse, 'hits.hits.length') > 0) {
const customElements = esResponse.hits.hits.map((hit) => hit._source[CUSTOM_ELEMENT_TYPE]);
Expand Down
9 changes: 5 additions & 4 deletions x-pack/plugins/canvas/server/collectors/workpad_collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

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

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

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

if (get(esResponse, 'hits.hits.length') > 0) {
const workpads = esResponse.hits.hits.map((hit) => hit._source[CANVAS_TYPE]);
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/canvas/types/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { LegacyAPICaller } from 'kibana/server';
import { ElasticsearchClient } from 'kibana/server';

/**
Function for collecting information about canvas usage
Expand All @@ -13,7 +13,7 @@ export type TelemetryCollector = (
/** The server instance */
kibanaIndex: string,
/** Function for calling elasticsearch */
callCluster: LegacyAPICaller
esClient: ElasticsearchClient
) => Record<string, any>;

export interface TelemetryCustomElementDocument {
Expand Down