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:
parent
39dc4d0237
commit
f2105c85fb
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue