[Uptime] Remove unused code in monitor list API (#84312)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
58d1df1401
commit
3216fce716
|
@ -92,7 +92,6 @@ exports[`MonitorList component MonitorListPagination component renders a no item
|
|||
"nextPagePagination": null,
|
||||
"prevPagePagination": null,
|
||||
"summaries": Array [],
|
||||
"totalSummaryCount": 0,
|
||||
},
|
||||
"loading": false,
|
||||
}
|
||||
|
@ -299,7 +298,6 @@ exports[`MonitorList component MonitorListPagination component renders the pagin
|
|||
},
|
||||
},
|
||||
],
|
||||
"totalSummaryCount": 2,
|
||||
},
|
||||
"loading": false,
|
||||
}
|
||||
|
@ -403,7 +401,6 @@ exports[`MonitorList component renders a no items message when no data is provid
|
|||
"nextPagePagination": null,
|
||||
"prevPagePagination": null,
|
||||
"summaries": Array [],
|
||||
"totalSummaryCount": 0,
|
||||
},
|
||||
"loading": true,
|
||||
}
|
||||
|
@ -611,7 +608,6 @@ exports[`MonitorList component renders error list 1`] = `
|
|||
},
|
||||
},
|
||||
],
|
||||
"totalSummaryCount": 2,
|
||||
},
|
||||
"loading": false,
|
||||
}
|
||||
|
@ -818,7 +814,6 @@ exports[`MonitorList component renders loading state 1`] = `
|
|||
},
|
||||
},
|
||||
],
|
||||
"totalSummaryCount": 2,
|
||||
},
|
||||
"loading": true,
|
||||
}
|
||||
|
@ -1857,7 +1852,6 @@ exports[`MonitorList component shallow renders the monitor list 1`] = `
|
|||
},
|
||||
},
|
||||
],
|
||||
"totalSummaryCount": 2,
|
||||
},
|
||||
"loading": false,
|
||||
}
|
||||
|
|
|
@ -125,7 +125,6 @@ describe('MonitorList component', () => {
|
|||
nextPagePagination: null,
|
||||
prevPagePagination: null,
|
||||
summaries: [testFooSummary, testBarSummary],
|
||||
totalSummaryCount: 2,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -164,7 +163,6 @@ describe('MonitorList component', () => {
|
|||
summaries: [],
|
||||
nextPagePagination: null,
|
||||
prevPagePagination: null,
|
||||
totalSummaryCount: 0,
|
||||
},
|
||||
loading: true,
|
||||
}}
|
||||
|
@ -236,7 +234,6 @@ describe('MonitorList component', () => {
|
|||
sortOrder: SortOrder.ASC,
|
||||
}),
|
||||
summaries: [testFooSummary, testBarSummary],
|
||||
totalSummaryCount: 2,
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -265,7 +262,6 @@ describe('MonitorList component', () => {
|
|||
summaries: [],
|
||||
nextPagePagination: null,
|
||||
prevPagePagination: null,
|
||||
totalSummaryCount: 0,
|
||||
},
|
||||
loading: false,
|
||||
}}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
"monitorStates": {
|
||||
"prevPagePagination": null,
|
||||
"nextPagePagination": null,
|
||||
"totalSummaryCount": 147428,
|
||||
"summaries": [
|
||||
{
|
||||
"monitor_id": "andrewvc-com",
|
||||
|
|
|
@ -79,7 +79,6 @@ export const mockStore = {
|
|||
prevPagePagination: null,
|
||||
nextPagePagination: null,
|
||||
summaries: [],
|
||||
totalSummaryCount: 0,
|
||||
},
|
||||
loading: false,
|
||||
},
|
||||
|
|
|
@ -20,7 +20,6 @@ export const initialState: MonitorList = {
|
|||
nextPagePagination: null,
|
||||
prevPagePagination: null,
|
||||
summaries: [],
|
||||
totalSummaryCount: 0,
|
||||
},
|
||||
loading: false,
|
||||
};
|
||||
|
|
|
@ -78,7 +78,6 @@ describe('state selectors', () => {
|
|||
prevPagePagination: null,
|
||||
nextPagePagination: null,
|
||||
summaries: [],
|
||||
totalSummaryCount: 0,
|
||||
},
|
||||
loading: false,
|
||||
},
|
||||
|
|
|
@ -8,6 +8,7 @@ import { UMElasticsearchQueryFn } from '../adapters';
|
|||
import { CONTEXT_DEFAULTS } from '../../../common/constants';
|
||||
import { Snapshot } from '../../../common/runtime_types';
|
||||
import { QueryContext } from './search';
|
||||
import { ESFilter } from '../../../../../typings/elasticsearch';
|
||||
|
||||
export interface GetSnapshotCountParams {
|
||||
dateRangeStart: string;
|
||||
|
@ -42,7 +43,7 @@ const statusCount = async (context: QueryContext): Promise<Snapshot> => {
|
|||
});
|
||||
|
||||
return (
|
||||
res.aggregations?.counts?.value ?? {
|
||||
(res.aggregations?.counts?.value as Snapshot) ?? {
|
||||
total: 0,
|
||||
up: 0,
|
||||
down: 0,
|
||||
|
@ -50,7 +51,7 @@ const statusCount = async (context: QueryContext): Promise<Snapshot> => {
|
|||
);
|
||||
};
|
||||
|
||||
const statusCountBody = (filters: any): any => {
|
||||
const statusCountBody = (filters: ESFilter[]) => {
|
||||
return {
|
||||
size: 0,
|
||||
query: {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import { QueryContext } from '../query_context';
|
||||
import { CursorPagination } from '../types';
|
||||
import { CursorDirection, SortOrder } from '../../../../../common/runtime_types';
|
||||
import { getUptimeESMockClient } from '../../__tests__/helper';
|
||||
|
||||
describe(QueryContext, () => {
|
||||
// 10 minute range
|
||||
|
@ -19,7 +20,17 @@ describe(QueryContext, () => {
|
|||
};
|
||||
|
||||
let qc: QueryContext;
|
||||
beforeEach(() => (qc = new QueryContext({}, rangeStart, rangeEnd, pagination, null, 10)));
|
||||
beforeEach(
|
||||
() =>
|
||||
(qc = new QueryContext(
|
||||
getUptimeESMockClient().uptimeEsClient,
|
||||
rangeStart,
|
||||
rangeEnd,
|
||||
pagination,
|
||||
null,
|
||||
10
|
||||
))
|
||||
);
|
||||
|
||||
describe('dateRangeFilter()', () => {
|
||||
const expectedRange = {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import { CursorPagination } from '../types';
|
||||
import { CursorDirection, SortOrder } from '../../../../../common/runtime_types';
|
||||
import { QueryContext } from '../query_context';
|
||||
import { getUptimeESMockClient } from '../../__tests__/helper';
|
||||
|
||||
export const nextPagination = (key: any): CursorPagination => {
|
||||
return {
|
||||
|
@ -16,5 +17,13 @@ export const nextPagination = (key: any): CursorPagination => {
|
|||
};
|
||||
};
|
||||
export const simpleQueryContext = (): QueryContext => {
|
||||
return new QueryContext(undefined, '', '', nextPagination('something'), undefined, 0, '');
|
||||
return new QueryContext(
|
||||
getUptimeESMockClient().uptimeEsClient,
|
||||
'',
|
||||
'',
|
||||
nextPagination('something'),
|
||||
undefined,
|
||||
0,
|
||||
''
|
||||
);
|
||||
};
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
|
||||
import { set } from '@elastic/safer-lodash-set';
|
||||
import { get } from 'lodash';
|
||||
import { QueryContext } from './query_context';
|
||||
|
||||
/**
|
||||
|
@ -21,9 +20,10 @@ export const findPotentialMatches = async (
|
|||
) => {
|
||||
const { body: queryResult } = await query(queryContext, searchAfter, size);
|
||||
const monitorIds: string[] = [];
|
||||
get<any>(queryResult, 'aggregations.monitors.buckets', []).forEach((b: any) => {
|
||||
|
||||
(queryResult.aggregations?.monitors.buckets ?? []).forEach((b) => {
|
||||
const monitorId = b.key.monitor_id;
|
||||
monitorIds.push(monitorId);
|
||||
monitorIds.push(monitorId as string);
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -53,11 +53,6 @@ const queryBody = async (queryContext: QueryContext, searchAfter: any, size: num
|
|||
size: 0,
|
||||
query: { bool: { filter: filters } },
|
||||
aggs: {
|
||||
has_timespan: {
|
||||
filter: {
|
||||
exists: { field: 'monitor.timespan' },
|
||||
},
|
||||
},
|
||||
monitors: {
|
||||
composite: {
|
||||
size,
|
||||
|
|
|
@ -5,13 +5,14 @@
|
|||
*/
|
||||
|
||||
import moment from 'moment';
|
||||
import { ElasticsearchClient } from 'kibana/server';
|
||||
import { CursorPagination } from './types';
|
||||
import { parseRelativeDate } from '../../helper';
|
||||
import { CursorDirection, SortOrder } from '../../../../common/runtime_types';
|
||||
import { UptimeESClient } from '../../lib';
|
||||
import { ESFilter } from '../../../../../../typings/elasticsearch';
|
||||
|
||||
export class QueryContext {
|
||||
callES: ElasticsearchClient;
|
||||
callES: UptimeESClient;
|
||||
dateRangeStart: string;
|
||||
dateRangeEnd: string;
|
||||
pagination: CursorPagination;
|
||||
|
@ -21,7 +22,7 @@ export class QueryContext {
|
|||
hasTimespanCache?: boolean;
|
||||
|
||||
constructor(
|
||||
database: any,
|
||||
database: UptimeESClient,
|
||||
dateRangeStart: string,
|
||||
dateRangeEnd: string,
|
||||
pagination: CursorPagination,
|
||||
|
@ -38,15 +39,16 @@ export class QueryContext {
|
|||
this.statusFilter = statusFilter;
|
||||
}
|
||||
|
||||
async search(params: any): Promise<any> {
|
||||
return this.callES.search({ body: params.body });
|
||||
async search<TParams>(params: TParams) {
|
||||
return this.callES.search(params);
|
||||
}
|
||||
|
||||
async count(params: any): Promise<any> {
|
||||
return this.callES.count(params);
|
||||
const { body } = await this.callES.count(params);
|
||||
return body;
|
||||
}
|
||||
|
||||
async dateAndCustomFilters(): Promise<any[]> {
|
||||
async dateAndCustomFilters(): Promise<ESFilter[]> {
|
||||
const clauses = [await this.dateRangeFilter()];
|
||||
if (this.filterClause) {
|
||||
clauses.push(this.filterClause);
|
||||
|
|
|
@ -38,33 +38,29 @@ export const createMonitorListRoute: UMRestApiRouteFactory = (libs) => ({
|
|||
const decodedPagination = pagination
|
||||
? JSON.parse(decodeURIComponent(pagination))
|
||||
: CONTEXT_DEFAULTS.CURSOR_PAGINATION;
|
||||
const [
|
||||
indexStatus,
|
||||
{ summaries, nextPagePagination, prevPagePagination },
|
||||
] = await Promise.all([
|
||||
libs.requests.getIndexStatus({ uptimeEsClient }),
|
||||
libs.requests.getMonitorStates({
|
||||
uptimeEsClient,
|
||||
dateRangeStart,
|
||||
dateRangeEnd,
|
||||
pagination: decodedPagination,
|
||||
pageSize,
|
||||
filters,
|
||||
// this is added to make typescript happy,
|
||||
// this sort of reassignment used to be further downstream but I've moved it here
|
||||
// because this code is going to be decomissioned soon
|
||||
statusFilter: statusFilter || undefined,
|
||||
}),
|
||||
]);
|
||||
|
||||
const totalSummaryCount = indexStatus?.docCount ?? 0;
|
||||
const {
|
||||
summaries,
|
||||
nextPagePagination,
|
||||
prevPagePagination,
|
||||
} = await libs.requests.getMonitorStates({
|
||||
uptimeEsClient,
|
||||
dateRangeStart,
|
||||
dateRangeEnd,
|
||||
pagination: decodedPagination,
|
||||
pageSize,
|
||||
filters,
|
||||
// this is added to make typescript happy,
|
||||
// this sort of reassignment used to be further downstream but I've moved it here
|
||||
// because this code is going to be decomissioned soon
|
||||
statusFilter: statusFilter || undefined,
|
||||
});
|
||||
|
||||
return response.ok({
|
||||
body: {
|
||||
summaries,
|
||||
nextPagePagination,
|
||||
prevPagePagination,
|
||||
totalSummaryCount,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
|
|
|
@ -17,7 +17,6 @@ interface ExpectedMonitorStatesPage {
|
|||
absFrom: number;
|
||||
absTo: number;
|
||||
size: number;
|
||||
totalCount: number;
|
||||
prevPagination: null | string;
|
||||
nextPagination: null | string;
|
||||
}
|
||||
|
@ -34,14 +33,13 @@ const checkMonitorStatesResponse = ({
|
|||
absFrom,
|
||||
absTo,
|
||||
size,
|
||||
totalCount,
|
||||
prevPagination,
|
||||
nextPagination,
|
||||
}: ExpectedMonitorStatesPage) => {
|
||||
const decoded = MonitorSummariesResultType.decode(response);
|
||||
expect(isRight(decoded)).to.be.ok();
|
||||
if (isRight(decoded)) {
|
||||
const { summaries, prevPagePagination, nextPagePagination, totalSummaryCount } = decoded.right;
|
||||
const { summaries, prevPagePagination, nextPagePagination } = decoded.right;
|
||||
expect(summaries).to.have.length(size);
|
||||
expect(summaries?.map((s) => s.monitor_id)).to.eql(statesIds);
|
||||
expect(
|
||||
|
@ -55,7 +53,6 @@ const checkMonitorStatesResponse = ({
|
|||
expect(point.timestamp).to.be.lessThan(absTo);
|
||||
});
|
||||
});
|
||||
expect(totalSummaryCount).to.be(totalCount);
|
||||
expect(prevPagePagination).to.be(prevPagination);
|
||||
expect(nextPagePagination).to.eql(nextPagination);
|
||||
}
|
||||
|
@ -84,7 +81,6 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
absFrom,
|
||||
absTo,
|
||||
size: 1,
|
||||
totalCount: 2000,
|
||||
prevPagination: null,
|
||||
nextPagination: null,
|
||||
});
|
||||
|
@ -468,7 +464,6 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
},
|
||||
];
|
||||
|
||||
const totalCount = 2000;
|
||||
let pagination: string | null = null;
|
||||
for (let page = 1; page <= expectedPageCount; page++) {
|
||||
const baseUrl = `${API_URLS.MONITOR_LIST}?dateRangeStart=${from}&dateRangeEnd=${to}&pageSize=${size}`;
|
||||
|
@ -482,7 +477,6 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
absFrom,
|
||||
absTo,
|
||||
size,
|
||||
totalCount,
|
||||
});
|
||||
|
||||
// Test to see if the previous page pagination works on every page (other than the first)
|
||||
|
@ -496,7 +490,6 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
absFrom,
|
||||
absTo,
|
||||
size,
|
||||
totalCount,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -525,7 +518,6 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
absFrom,
|
||||
absTo,
|
||||
size: LENGTH,
|
||||
totalCount: 2000,
|
||||
prevPagination: null,
|
||||
nextPagination:
|
||||
'{"cursorDirection":"AFTER","sortOrder":"ASC","cursorKey":{"monitor_id":"0009-up"}}',
|
||||
|
|
Loading…
Reference in a new issue