Skip to content

Commit

Permalink
Uses new esClient to fetch sample data telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers committed Dec 21, 2020
1 parent 513138b commit 3b36890
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { SearchResponse } from 'elasticsearch';
import { get } from 'lodash';
import moment from 'moment';
import { CollectorFetchContext } from '../../../../../usage_collection/server';
Expand All @@ -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,
Expand Down

0 comments on commit 3b36890

Please sign in to comment.