Sample data usage collector es client migration (#86657)

* Uses new esClient to fetch sample data telemetry

* Import SearchResponse from core
This commit is contained in:
Christiane (Tina) Heiligers 2020-12-22 16:27:05 -07:00 committed by GitHub
parent 39dc4d0237
commit f2105c85fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View file

@ -23,7 +23,7 @@ import { fetchProvider } from './collector_fetch';
const getMockFetchClients = (hits?: unknown[]) => {
const fetchParamsMock = createCollectorFetchContextMock();
fetchParamsMock.callCluster.mockResolvedValue({ hits: { hits } });
fetchParamsMock.esClient.search = jest.fn().mockResolvedValue({ body: { hits: { hits } } });
return fetchParamsMock;
};

View file

@ -19,6 +19,7 @@
import { get } from 'lodash';
import moment from 'moment';
import { SearchResponse } from 'src/core/server';
import { CollectorFetchContext } from '../../../../../usage_collection/server';
interface SearchHit {
@ -41,17 +42,23 @@ export interface TelemetryResponse {
last_uninstall_set: string | null;
}
type ESResponse = SearchResponse<SearchHit>;
export function fetchProvider(index: string) {
return async ({ callCluster }: CollectorFetchContext) => {
const response = await callCluster('search', {
index,
body: {
query: { term: { type: { value: 'sample-data-telemetry' } } },
_source: { includes: ['sample-data-telemetry', 'type', 'updated_at'] },
return async ({ esClient }: CollectorFetchContext) => {
const { body: response } = await esClient.search<ESResponse>(
{
index,
body: {
query: { term: { type: { value: 'sample-data-telemetry' } } },
_source: { includes: ['sample-data-telemetry', 'type', 'updated_at'] },
},
filter_path: 'hits.hits._id,hits.hits._source',
},
filter_path: 'hits.hits._id,hits.hits._source',
ignore: [404],
});
{
ignore: [404],
}
);
const getLast = (
dataSet: string,