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 21, 2020
1 parent 7c7dc5f commit 25afd05
Showing 1 changed file with 21 additions and 18 deletions.
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'];
};
}

0 comments on commit 25afd05

Please sign in to comment.