mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Synthetics] Simplify journey API query (#162188)
This commit is contained in:
parent
46403f1c1b
commit
73695efac3
4 changed files with 30 additions and 84 deletions
|
@ -21,7 +21,6 @@ import { SYNTHETICS_API_URLS } from '../../../../../common/constants';
|
|||
|
||||
export interface FetchJourneyStepsParams {
|
||||
checkGroup: string;
|
||||
syntheticEventTypes?: string[];
|
||||
}
|
||||
|
||||
export async function fetchScreenshotBlockSet(params: string[]): Promise<ScreenshotBlockDoc[]> {
|
||||
|
@ -35,7 +34,7 @@ export async function fetchBrowserJourney(
|
|||
): Promise<SyntheticsJourneyApiResponse> {
|
||||
return apiService.get(
|
||||
SYNTHETICS_API_URLS.JOURNEY.replace('{checkGroup}', params.checkGroup),
|
||||
{ syntheticEventTypes: params.syntheticEventTypes },
|
||||
undefined,
|
||||
SyntheticsJourneyApiResponseType
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,41 +6,10 @@
|
|||
*/
|
||||
|
||||
import { JourneyStep } from '../../../../common/runtime_types/ping/synthetics';
|
||||
import { getJourneySteps, formatSyntheticEvents } from './get_journey_steps';
|
||||
import { getJourneySteps } from './get_journey_steps';
|
||||
import { getUptimeESMockClient } from './test_helpers';
|
||||
|
||||
describe('getJourneySteps request module', () => {
|
||||
describe('formatStepTypes', () => {
|
||||
it('returns default steps if none are provided', () => {
|
||||
expect(formatSyntheticEvents()).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"cmd/status",
|
||||
"journey/browserconsole",
|
||||
"step/end",
|
||||
"step/screenshot",
|
||||
"step/screenshot_ref",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it('returns provided step array if isArray', () => {
|
||||
expect(formatSyntheticEvents(['step/end', 'stderr'])).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"step/end",
|
||||
"stderr",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it('returns provided step string in an array', () => {
|
||||
expect(formatSyntheticEvents('step/end')).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"step/end",
|
||||
]
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getJourneySteps', () => {
|
||||
let data: any;
|
||||
beforeEach(() => {
|
||||
|
@ -178,7 +147,6 @@ describe('getJourneySteps request module', () => {
|
|||
const result: JourneyStep[] = await getJourneySteps({
|
||||
uptimeEsClient,
|
||||
checkGroup: '2bf952dc-64b5-11eb-8b3b-42010a84000d',
|
||||
syntheticEventTypes: ['stderr', 'step/end'],
|
||||
});
|
||||
|
||||
const call: any = mockEsClient.search.mock.calls[0][0];
|
||||
|
@ -188,8 +156,11 @@ describe('getJourneySteps request module', () => {
|
|||
Object {
|
||||
"terms": Object {
|
||||
"synthetics.type": Array [
|
||||
"stderr",
|
||||
"cmd/status",
|
||||
"journey/browserconsole",
|
||||
"step/end",
|
||||
"step/screenshot",
|
||||
"step/screenshot_ref",
|
||||
],
|
||||
},
|
||||
}
|
||||
|
|
|
@ -12,31 +12,13 @@ import { JourneyStep } from '../../../../common/runtime_types/ping/synthetics';
|
|||
|
||||
export interface GetJourneyStepsParams {
|
||||
checkGroup: string;
|
||||
syntheticEventTypes?: string | string[];
|
||||
}
|
||||
|
||||
const defaultEventTypes = [
|
||||
'cmd/status',
|
||||
'journey/browserconsole',
|
||||
'step/end',
|
||||
'step/screenshot',
|
||||
'step/screenshot_ref',
|
||||
];
|
||||
|
||||
export const formatSyntheticEvents = (eventTypes?: string | string[]) => {
|
||||
if (!eventTypes) {
|
||||
return defaultEventTypes;
|
||||
} else {
|
||||
return Array.isArray(eventTypes) ? eventTypes : [eventTypes];
|
||||
}
|
||||
};
|
||||
|
||||
type ResultType = JourneyStep & { '@timestamp': string };
|
||||
|
||||
export const getJourneySteps = async ({
|
||||
uptimeEsClient,
|
||||
checkGroup,
|
||||
syntheticEventTypes,
|
||||
}: GetJourneyStepsParams & {
|
||||
uptimeEsClient: UptimeEsClient;
|
||||
}): Promise<JourneyStep[]> => {
|
||||
|
@ -46,7 +28,13 @@ export const getJourneySteps = async ({
|
|||
filter: [
|
||||
{
|
||||
terms: {
|
||||
'synthetics.type': formatSyntheticEvents(syntheticEventTypes),
|
||||
'synthetics.type': [
|
||||
'cmd/status',
|
||||
'journey/browserconsole',
|
||||
'step/end',
|
||||
'step/screenshot',
|
||||
'step/screenshot_ref',
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { SyntheticsJourneyApiResponse } from '../../../common/runtime_types';
|
||||
import { getJourneyFailedSteps } from '../../legacy_uptime/lib/requests/get_journey_failed_steps';
|
||||
import { SyntheticsRestApiRouteFactory } from '../types';
|
||||
import { SYNTHETICS_API_URLS } from '../../../common/constants';
|
||||
|
@ -19,39 +20,26 @@ export const createJourneyRoute: SyntheticsRestApiRouteFactory = () => ({
|
|||
params: schema.object({
|
||||
checkGroup: schema.string(),
|
||||
}),
|
||||
query: schema.object({
|
||||
// provides a filter for the types of synthetic events to include
|
||||
// when fetching a journey's data
|
||||
syntheticEventTypes: schema.maybe(
|
||||
schema.oneOf([schema.arrayOf(schema.string()), schema.string()])
|
||||
),
|
||||
}),
|
||||
},
|
||||
handler: async ({ uptimeEsClient, request, response }): Promise<any> => {
|
||||
handler: async ({ uptimeEsClient, request, response }): Promise<SyntheticsJourneyApiResponse> => {
|
||||
const { checkGroup } = request.params;
|
||||
const { syntheticEventTypes } = request.query;
|
||||
|
||||
try {
|
||||
const [result, details] = await Promise.all([
|
||||
await getJourneySteps({
|
||||
uptimeEsClient,
|
||||
checkGroup,
|
||||
syntheticEventTypes,
|
||||
}),
|
||||
await getJourneyDetails({
|
||||
uptimeEsClient,
|
||||
checkGroup,
|
||||
}),
|
||||
]);
|
||||
|
||||
return {
|
||||
const [steps, details] = await Promise.all([
|
||||
getJourneySteps({
|
||||
uptimeEsClient,
|
||||
checkGroup,
|
||||
steps: result,
|
||||
details,
|
||||
};
|
||||
} catch (e: unknown) {
|
||||
return response.custom({ statusCode: 500, body: { message: e } });
|
||||
}
|
||||
}),
|
||||
getJourneyDetails({
|
||||
uptimeEsClient,
|
||||
checkGroup,
|
||||
}),
|
||||
]);
|
||||
|
||||
return {
|
||||
steps,
|
||||
details,
|
||||
checkGroup,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue