Skip to content

Commit

Permalink
PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Feb 2, 2021
1 parent 49b1646 commit 60b6d65
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const StepDetailContainer: React.FC<Props> = ({ checkGroup, stepIndex })

useEffect(() => {
if (checkGroup) {
dispatch(getJourneySteps({ checkGroup, stepTypes: ['step/end'] }));
dispatch(getJourneySteps({ checkGroup, syntheticEventTypes: ['step/end'] }));
}
}, [dispatch, checkGroup]);

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/public/state/actions/journey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { SyntheticsJourneyApiResponse } from '../../../common/runtime_types';

export interface FetchJourneyStepsParams {
checkGroup: string;
stepTypes?: string[];
syntheticEventTypes?: string[];
}

export interface GetJourneyFailPayload {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/public/state/api/journey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function fetchJourneySteps(
): Promise<SyntheticsJourneyApiResponse> {
return (await apiService.get(
`/api/uptime/journey/${params.checkGroup}`,
{ stepTypes: params.stepTypes },
{ syntheticEventTypes: params.syntheticEventTypes },
SyntheticsJourneyApiResponseType
)) as SyntheticsJourneyApiResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { getJourneySteps, formatStepTypes } from './get_journey_steps';
import { getJourneySteps, formatSyntheticEvents } from './get_journey_steps';
import { getUptimeESMockClient } from './helper';

describe('getJourneySteps request module', () => {
describe('formatStepTypes', () => {
it('returns default steps if none are provided', () => {
expect(formatStepTypes()).toMatchInlineSnapshot(`
expect(formatSyntheticEvents()).toMatchInlineSnapshot(`
Array [
"step/end",
"stderr",
Expand All @@ -21,7 +21,7 @@ describe('getJourneySteps request module', () => {
});

it('returns provided step array if isArray', () => {
expect(formatStepTypes(['step/end', 'stderr'])).toMatchInlineSnapshot(`
expect(formatSyntheticEvents(['step/end', 'stderr'])).toMatchInlineSnapshot(`
Array [
"step/end",
"stderr",
Expand All @@ -30,7 +30,7 @@ describe('getJourneySteps request module', () => {
});

it('returns provided step string in an array', () => {
expect(formatStepTypes('step/end')).toMatchInlineSnapshot(`
expect(formatSyntheticEvents('step/end')).toMatchInlineSnapshot(`
Array [
"step/end",
]
Expand Down Expand Up @@ -153,9 +153,8 @@ describe('getJourneySteps request module', () => {
]
`);

expect(call.body.size).toBe(500);

expect(result).toHaveLength(2);
// `getJourneySteps` is responsible for formatting these fields, so we need to check them
result.forEach((step: any) => {
expect(['2021-02-01T17:45:19.001Z', '2021-02-01T17:45:49.944Z']).toContain(step.timestamp);
expect(['o6myXncBFt2V8m6r6z-r', 'IjqzXncBn2sjqrYxYoCG']).toContain(step.docId);
Expand All @@ -173,7 +172,7 @@ describe('getJourneySteps request module', () => {
const result: any = await getJourneySteps({
uptimeEsClient,
checkGroup: '2bf952dc-64b5-11eb-8b3b-42010a84000d',
stepTypes: ['stderr', 'step/end'],
syntheticEventTypes: ['stderr', 'step/end'],
});

const call: any = mockEsClient.search.mock.calls[0][0];
Expand Down
16 changes: 8 additions & 8 deletions x-pack/plugins/uptime/server/lib/requests/get_journey_steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ import { Ping } from '../../../common/runtime_types';

interface GetJourneyStepsParams {
checkGroup: string;
stepTypes?: string | string[];
syntheticEventTypes?: string | string[];
}

const defaultStepTypes = ['step/end', 'stderr', 'cmd/status', 'step/screenshot'];
const defaultEventTypes = ['step/end', 'stderr', 'cmd/status', 'step/screenshot'];

export const formatStepTypes = (stepTypes?: string | string[]) => {
if (!stepTypes) {
return defaultStepTypes;
export const formatSyntheticEvents = (eventTypes?: string | string[]) => {
if (!eventTypes) {
return defaultEventTypes;
} else {
return Array.isArray(stepTypes) ? stepTypes : [stepTypes];
return Array.isArray(eventTypes) ? eventTypes : [eventTypes];
}
};

export const getJourneySteps: UMElasticsearchQueryFn<GetJourneyStepsParams, Ping> = async ({
uptimeEsClient,
checkGroup,
stepTypes,
syntheticEventTypes,
}) => {
const params = {
query: {
bool: {
filter: [
{
terms: {
'synthetics.type': formatStepTypes(stepTypes),
'synthetics.type': formatSyntheticEvents(syntheticEventTypes),
},
},
{
Expand Down
10 changes: 7 additions & 3 deletions x-pack/plugins/uptime/server/rest_api/pings/journeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ export const createJourneyRoute: UMRestApiRouteFactory = (libs: UMServerLibs) =>
_debug: schema.maybe(schema.boolean()),
}),
query: schema.object({
stepTypes: schema.maybe(schema.oneOf([schema.arrayOf(schema.string()), schema.string()])),
// 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 }): Promise<any> => {
const { checkGroup } = request.params;
const { stepTypes } = request.query;
const { syntheticEventTypes } = request.query;
const result = await libs.requests.getJourneySteps({
uptimeEsClient,
checkGroup,
stepTypes,
syntheticEventTypes,
});

const details = await libs.requests.getJourneyDetails({
Expand Down

0 comments on commit 60b6d65

Please sign in to comment.