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

Migrates search telemetry usage collector es client from legacy to new #86597

Merged
Merged
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
39 changes: 21 additions & 18 deletions src/plugins/data/server/search/collectors/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,34 @@
import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import { SharedGlobalConfig } from 'kibana/server';
import { SearchResponse } from 'elasticsearch';
import { CollectorFetchContext } from 'src/plugins/usage_collection/server';
import { Usage } from './register';

interface SearchTelemetrySavedObject {
interface SearchTelemetry {
'search-telemetry': Usage;
}
type ESResponse = SearchResponse<SearchTelemetry>;

export function fetchProvider(config$: Observable<SharedGlobalConfig>) {
return async ({ callCluster }: CollectorFetchContext): Promise<Usage> => {
return async ({ esClient }: CollectorFetchContext): Promise<Usage> => {
const config = await config$.pipe(first()).toPromise();

const response = await callCluster<SearchTelemetrySavedObject>('search', {
index: config.kibana.index,
body: {
query: { term: { type: { value: 'search-telemetry' } } },
const { body: esResponse } = await esClient.search<ESResponse>(
{
index: config.kibana.index,
body: {
query: { term: { type: { value: 'search-telemetry' } } },
},
},
ignore: [404],
});

return response.hits.hits.length
? response.hits.hits[0]._source['search-telemetry']
: {
successCount: 0,
errorCount: 0,
averageDuration: null,
};
{ ignore: [404] }
);
const size = esResponse?.hits?.hits?.length ?? 0;
if (!size) {
return {
successCount: 0,
errorCount: 0,
averageDuration: null,
};
}
return esResponse.hits.hits[0]._source['search-telemetry'];
};
}