Skip to content

Commit

Permalink
Migrates search telemetry usage collector es client from legacy to new
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers committed Dec 20, 2020
1 parent e8b21bc commit 43b09c2
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/plugins/data/server/search/collectors/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,20 @@ import { SharedGlobalConfig } from 'kibana/server';
import { CollectorFetchContext } from 'src/plugins/usage_collection/server';
import { Usage } from './register';

interface SearchTelemetrySavedObject {
'search-telemetry': Usage;
}

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 } = await esClient.search(
{
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']
{ ignore: [404] }
);
return body.hits?.hits?.length > 0
? body.hits.hits[0]._source['search-telemetry']
: {
successCount: 0,
errorCount: 0,
Expand Down

0 comments on commit 43b09c2

Please sign in to comment.