Skip to content

Commit

Permalink
[7.x] Sample data usage collector es client migration (elastic#86657) (
Browse files Browse the repository at this point in the history
…elastic#86856)

* Uses new esClient to fetch sample data telemetry

* Import SearchResponse from core
  • Loading branch information
TinaHeiligers authored Dec 23, 2020
1 parent fe37337 commit ce0c66a
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 @@ -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 {
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 ce0c66a

Please sign in to comment.