Skip to content

Commit

Permalink
[7.x] Fix returned payload by "search" usage collector (#75340) (#75677)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
afharo and elasticmachine authored Aug 21, 2020
1 parent 139f135 commit 7c4ba9f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/plugins/data/server/search/collectors/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@

import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import { LegacyAPICaller, SharedGlobalConfig } from '../../../../../core/server';
import { LegacyAPICaller, SharedGlobalConfig } from 'kibana/server';
import { Usage } from './register';

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

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

const response = await callCluster('search', {
const response = await callCluster<SearchTelemetrySavedObject>('search', {
index: config.kibana.index,
body: {
query: { term: { type: { value: 'search-telemetry' } } },
Expand All @@ -35,7 +39,7 @@ export function fetchProvider(config$: Observable<SharedGlobalConfig>) {
});

return response.hits.hits.length
? (response.hits.hits[0]._source as Usage)
? response.hits.hits[0]._source['search-telemetry']
: {
successCount: 0,
errorCount: 0,
Expand Down

0 comments on commit 7c4ba9f

Please sign in to comment.