Skip to content

Commit df9c5d9

Browse files
authored
Feat: increase check timeout to scripted, browser and multihttp checks (#1049)
* fix: define min and max timeout values in constants file - for multihttp, browser and scripted, the max limit is raised to 90 * fix: add valiadation to make sure frequency is greater than timeout * chore: add tests
1 parent 006bc43 commit df9c5d9

File tree

16 files changed

+179
-31
lines changed

16 files changed

+179
-31
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { CheckType } from 'types';
2+
3+
const CheckTimeoutValues = {
4+
[CheckType.PING]: { min: 1, max: 60 },
5+
[CheckType.TCP]: { min: 1, max: 60 },
6+
[CheckType.Traceroute]: { min: 30, max: 30 },
7+
[CheckType.DNS]: { min: 1, max: 60 },
8+
[CheckType.GRPC]: { min: 1, max: 60 },
9+
[CheckType.HTTP]: { min: 1, max: 60 },
10+
[CheckType.MULTI_HTTP]: { min: 5, max: 90 },
11+
[CheckType.Scripted]: { min: 5, max: 90 },
12+
[CheckType.Browser]: { min: 5, max: 90 },
13+
};
14+
15+
export { CheckTimeoutValues };

‎src/components/CheckForm/FormLayouts/CheckBrowserLayout.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import React from 'react';
22
import { Stack, TextLink } from '@grafana/ui';
33

44
import { LayoutSection, Section } from './Layout.types';
5-
import { CheckFormValuesBrowser } from 'types';
5+
import { CheckFormValuesBrowser, CheckType } from 'types';
66
import { BrowserFields } from 'components/CheckEditor/CheckEditor.types';
77
import { BrowserCheckInstance } from 'components/CheckEditor/FormComponents/BrowserCheckInstance';
88
import { BrowserCheckScript } from 'components/CheckEditor/FormComponents/BrowserCheckScript';
99
import { Timeout } from 'components/CheckEditor/FormComponents/Timeout';
1010

11+
import { CheckTimeoutValues } from '../CheckForm.constants';
12+
1113
export const BROWSER_CHECK_FIELDS: BrowserFields = {
1214
script: {
1315
name: `settings.browser.script`,
@@ -37,7 +39,7 @@ export const BrowserCheckLayout: Partial<Record<LayoutSection, Section<CheckForm
3739
running checks in a k6 script.
3840
</TextLink>
3941
</div>
40-
<Timeout min={5.0} />
42+
<Timeout min={CheckTimeoutValues[CheckType.Browser].min} max={CheckTimeoutValues[CheckType.Browser].max} />
4143
</Stack>
4244
),
4345
},

‎src/components/CheckForm/FormLayouts/CheckDNSLayout.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useCallback } from 'react';
22

33
import { LayoutSection, Section } from './Layout.types';
4-
import { CheckFormValuesDns } from 'types';
4+
import { CheckFormValuesDns, CheckType } from 'types';
55
import { useNestedRequestErrors } from 'hooks/useNestedRequestErrors';
66
import { DNSRequestFields } from 'components/CheckEditor/CheckEditor.types';
77
import { CheckPublishedAdvanceMetrics } from 'components/CheckEditor/FormComponents/CheckPublishedAdvanceMetrics';
@@ -10,6 +10,7 @@ import { DNSCheckValidResponseCodes } from 'components/CheckEditor/FormComponent
1010
import { DNSRequest } from 'components/CheckEditor/FormComponents/DNSRequest';
1111
import { Timeout } from 'components/CheckEditor/FormComponents/Timeout';
1212

13+
import { CheckTimeoutValues } from '../CheckForm.constants';
1314
import { useCheckFormContext } from '../CheckFormContext/CheckFormContext';
1415

1516
export const DNS_REQUEST_FIELDS: DNSRequestFields = {
@@ -65,7 +66,7 @@ export const DNSCheckLayout: Partial<Record<LayoutSection, Section<CheckFormValu
6566
<>
6667
<DNSCheckValidResponseCodes />
6768
<DNSCheckResponseMatches />
68-
<Timeout />
69+
<Timeout min={CheckTimeoutValues[CheckType.DNS].min} max={CheckTimeoutValues[CheckType.DNS].max} />
6970
</>
7071
),
7172
},

‎src/components/CheckForm/FormLayouts/CheckGrpcLayout.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React, { useCallback } from 'react';
22

33
import { LayoutSection, Section } from './Layout.types';
4-
import { CheckFormValuesGRPC } from 'types';
4+
import { CheckFormValuesGRPC, CheckType } from 'types';
55
import { useNestedRequestErrors } from 'hooks/useNestedRequestErrors';
66
import { GRPCRequestFields } from 'components/CheckEditor/CheckEditor.types';
77
import { CheckPublishedAdvanceMetrics } from 'components/CheckEditor/FormComponents/CheckPublishedAdvanceMetrics';
88
import { GRPCRequest } from 'components/CheckEditor/FormComponents/GRPCRequest';
99
import { Timeout } from 'components/CheckEditor/FormComponents/Timeout';
1010

11+
import { CheckTimeoutValues } from '../CheckForm.constants';
1112
import { useCheckFormContext } from '../CheckFormContext/CheckFormContext';
1213

1314
export const GRPC_REQUEST_FIELDS: GRPCRequestFields = {
@@ -73,7 +74,7 @@ export const GRPCCheckLayout: Partial<Record<LayoutSection, Section<CheckFormVal
7374
fields: [`timeout`],
7475
Component: (
7576
<>
76-
<Timeout />
77+
<Timeout min={CheckTimeoutValues[CheckType.GRPC].min} max={CheckTimeoutValues[CheckType.GRPC].max} />
7778
</>
7879
),
7980
},

‎src/components/CheckForm/FormLayouts/CheckHttpLayout.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useCallback } from 'react';
22

33
import { LayoutSection, Section } from './Layout.types';
4-
import { CheckFormValues, CheckFormValuesHttp } from 'types';
4+
import { CheckFormValues, CheckFormValuesHttp, CheckType } from 'types';
55
import { useNestedRequestErrors } from 'hooks/useNestedRequestErrors';
66
import { HttpRequestFields } from 'components/CheckEditor/CheckEditor.types';
77
import { CheckPublishedAdvanceMetrics } from 'components/CheckEditor/FormComponents/CheckPublishedAdvanceMetrics';
@@ -13,6 +13,7 @@ import { HttpCheckValidStatusCodes } from 'components/CheckEditor/FormComponents
1313
import { HttpRequest } from 'components/CheckEditor/FormComponents/HttpRequest';
1414
import { Timeout } from 'components/CheckEditor/FormComponents/Timeout';
1515

16+
import { CheckTimeoutValues } from '../CheckForm.constants';
1617
import { useCheckFormContext } from '../CheckFormContext/CheckFormContext';
1718

1819
export const HTTP_REQUEST_FIELDS: HttpRequestFields<CheckFormValuesHttp> = {
@@ -109,7 +110,7 @@ export const HttpCheckLayout: Partial<Record<LayoutSection, Section<CheckFormVal
109110
<HttpCheckSSLOptions />
110111
<HttpCheckRegExValidation />
111112
<HttpCheckCompressionOption />
112-
<Timeout />
113+
<Timeout min={CheckTimeoutValues[CheckType.HTTP].min} max={CheckTimeoutValues[CheckType.HTTP].max} />
113114
</>
114115
),
115116
},

‎src/components/CheckForm/FormLayouts/CheckMultiHttpLayout.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React from 'react';
22

33
import { LayoutSection, Section } from './Layout.types';
4-
import { CheckFormValuesMultiHttp } from 'types';
4+
import { CheckFormValuesMultiHttp, CheckType } from 'types';
55
import { MultiHttpAssertions } from 'components/CheckEditor/FormComponents/MultiHttpAssertions';
66
import { MultiHttpCheckRequests } from 'components/CheckEditor/FormComponents/MultiHttpCheckRequests';
77
import { Timeout } from 'components/CheckEditor/FormComponents/Timeout';
88

9+
import { CheckTimeoutValues } from '../CheckForm.constants';
910
import { ENTRY_INDEX_CHAR } from '../FormLayout/formlayout.utils';
1011

1112
export const MultiHTTPCheckLayout: Partial<Record<LayoutSection, Section<CheckFormValuesMultiHttp>>> = {
@@ -25,7 +26,10 @@ export const MultiHTTPCheckLayout: Partial<Record<LayoutSection, Section<CheckFo
2526
Component: (
2627
<>
2728
<MultiHttpAssertions />
28-
<Timeout min={5.0} />
29+
<Timeout
30+
min={CheckTimeoutValues[CheckType.MULTI_HTTP].min}
31+
max={CheckTimeoutValues[CheckType.MULTI_HTTP].max}
32+
/>
2933
</>
3034
),
3135
},

‎src/components/CheckForm/FormLayouts/CheckPingLayout.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React, { useCallback } from 'react';
22

33
import { LayoutSection, Section } from './Layout.types';
4-
import { CheckFormValuesPing } from 'types';
4+
import { CheckFormValuesPing, CheckType } from 'types';
55
import { useNestedRequestErrors } from 'hooks/useNestedRequestErrors';
66
import { PingRequestFields } from 'components/CheckEditor/CheckEditor.types';
77
import { CheckPublishedAdvanceMetrics } from 'components/CheckEditor/FormComponents/CheckPublishedAdvanceMetrics';
88
import { PingRequest } from 'components/CheckEditor/FormComponents/PingRequest';
99
import { Timeout } from 'components/CheckEditor/FormComponents/Timeout';
1010

11+
import { CheckTimeoutValues } from '../CheckForm.constants';
1112
import { useCheckFormContext } from '../CheckFormContext/CheckFormContext';
1213

1314
const PING_FIELDS: PingRequestFields = {
@@ -49,7 +50,7 @@ export const PingCheckLayout: Partial<Record<LayoutSection, Section<CheckFormVal
4950
fields: [`timeout`],
5051
Component: (
5152
<>
52-
<Timeout />
53+
<Timeout min={CheckTimeoutValues[CheckType.PING].min} max={CheckTimeoutValues[CheckType.PING].max} />
5354
</>
5455
),
5556
},

‎src/components/CheckForm/FormLayouts/CheckScriptedLayout.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import React from 'react';
22
import { Stack, TextLink } from '@grafana/ui';
33

44
import { LayoutSection, Section } from './Layout.types';
5-
import { CheckFormValuesScripted } from 'types';
5+
import { CheckFormValuesScripted, CheckType } from 'types';
66
import { ScriptedFields } from 'components/CheckEditor/CheckEditor.types';
77
import { ScriptedCheckInstance } from 'components/CheckEditor/FormComponents/ScriptedCheckInstance';
88
import { ScriptedCheckScript } from 'components/CheckEditor/FormComponents/ScriptedCheckScript';
99
import { Timeout } from 'components/CheckEditor/FormComponents/Timeout';
1010

11+
import { CheckTimeoutValues } from '../CheckForm.constants';
12+
1113
export const SCRIPTED_CHECK_FIELDS: ScriptedFields = {
1214
script: {
1315
name: `settings.scripted.script`,
@@ -37,7 +39,7 @@ export const ScriptedCheckLayout: Partial<Record<LayoutSection, Section<CheckFor
3739
running checks in a k6 script.
3840
</TextLink>
3941
</div>
40-
<Timeout min={5.0} />
42+
<Timeout min={CheckTimeoutValues[CheckType.Scripted].min} max={CheckTimeoutValues[CheckType.Scripted].max} />
4143
</Stack>
4244
),
4345
},

‎src/components/CheckForm/FormLayouts/CheckTCPLayout.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React, { useCallback } from 'react';
22

33
import { LayoutSection, Section } from './Layout.types';
4-
import { CheckFormValuesTcp } from 'types';
4+
import { CheckFormValuesTcp, CheckType } from 'types';
55
import { useNestedRequestErrors } from 'hooks/useNestedRequestErrors';
66
import { TCPRequestFields } from 'components/CheckEditor/CheckEditor.types';
77
import { CheckPublishedAdvanceMetrics } from 'components/CheckEditor/FormComponents/CheckPublishedAdvanceMetrics';
88
import { TCPCheckQueryAndResponse } from 'components/CheckEditor/FormComponents/TCPCheckQueryAndResponse';
99
import { TCPRequest } from 'components/CheckEditor/FormComponents/TCPRequest';
1010
import { Timeout } from 'components/CheckEditor/FormComponents/Timeout';
1111

12+
import { CheckTimeoutValues } from '../CheckForm.constants';
1213
import { useCheckFormContext } from '../CheckFormContext/CheckFormContext';
1314

1415
const TCP_REQUEST_FIELDS: TCPRequestFields = {
@@ -71,7 +72,7 @@ export const TCPCheckLayout: Partial<Record<LayoutSection, Section<CheckFormValu
7172
Component: (
7273
<>
7374
<TCPCheckQueryAndResponse />
74-
<Timeout />
75+
<Timeout min={CheckTimeoutValues[CheckType.TCP].min} max={CheckTimeoutValues[CheckType.TCP].max} />
7576
</>
7677
),
7778
},

‎src/components/CheckForm/FormLayouts/CheckTracerouteLayout.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React from 'react';
22

33
import { LayoutSection, Section } from './Layout.types';
4-
import { CheckFormValuesTraceroute } from 'types';
4+
import { CheckFormValuesTraceroute, CheckType } from 'types';
55
import { useNestedRequestErrors } from 'hooks/useNestedRequestErrors';
66
import { TracerouteRequestFields } from 'components/CheckEditor/CheckEditor.types';
77
import { CheckPublishedAdvanceMetrics } from 'components/CheckEditor/FormComponents/CheckPublishedAdvanceMetrics';
88
import { Timeout } from 'components/CheckEditor/FormComponents/Timeout';
99
import { TracerouteRequest } from 'components/CheckEditor/FormComponents/TracerouteRequest';
1010

11+
import { CheckTimeoutValues } from '../CheckForm.constants';
1112
import { useCheckFormContext } from '../CheckFormContext/CheckFormContext';
1213

1314
const TRACEROUTE_FIELDS: TracerouteRequestFields = {
@@ -47,7 +48,10 @@ export const TracerouteCheckLayout: Partial<Record<LayoutSection, Section<CheckF
4748
fields: [`timeout`],
4849
Component: (
4950
<>
50-
<Timeout max={30.0} min={30.0} />
51+
<Timeout
52+
min={CheckTimeoutValues[CheckType.Traceroute].min}
53+
max={CheckTimeoutValues[CheckType.Traceroute].max}
54+
/>
5155
</>
5256
),
5357
},

‎src/components/TimeSlider/styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const getStyles = (theme: GrafanaTheme2, hasMarks = false) => {
9292
sliderInputField: css({
9393
marginLeft: theme.spacing(3),
9494
marginRight: theme.spacing(1),
95-
width: '60px',
95+
maxWidth: '60px',
9696
minWidth: '40px',
9797
input: {
9898
textAlign: 'center',

‎src/page/NewCheck/__tests__/BrowserChecks/Scripted/5-execution.payload.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,27 @@ describe(`BrowserCheck - Section 5 (Execution) payload`, () => {
3838

3939
expect(body.frequency).toBe(ONE_MINUTE_IN_MS);
4040
});
41+
42+
it(`can add timeout up to 90 seconds`, async () => {
43+
const MAX_TIMEOUT_MS = 90000;
44+
45+
const { user, read } = await renderNewForm(checkType);
46+
await fillMandatoryFields({ user, checkType });
47+
48+
await goToSection(user, 2);
49+
50+
const timeoutMinutesInput = screen.getByLabelText('timeout minutes input');
51+
const timeoutSecondsInput = screen.getByLabelText('timeout seconds input');
52+
53+
await user.clear(timeoutMinutesInput);
54+
await user.clear(timeoutSecondsInput);
55+
await user.type(timeoutMinutesInput, `{backspace}1`);
56+
await user.type(timeoutSecondsInput, `30`);
57+
58+
await submitForm(user);
59+
60+
const { body } = await read();
61+
62+
expect(body.timeout).toBe(MAX_TIMEOUT_MS);
63+
});
4164
});

‎src/page/NewCheck/__tests__/MultiStepChecks/MultiHTTP/5-execution.payload.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,27 @@ describe(`MultiHTTPCheck - Section 5 (Execution) payload`, () => {
3838

3939
expect(body.frequency).toBe(ONE_MINUTE_IN_MS);
4040
});
41+
42+
it(`can add timeout up to 90 seconds`, async () => {
43+
const MAX_TIMEOUT_MS = 90000;
44+
45+
const { user, read } = await renderNewForm(checkType);
46+
await fillMandatoryFields({ user, checkType });
47+
48+
await goToSection(user, 2);
49+
50+
const timeoutMinutesInput = screen.getByLabelText('timeout minutes input');
51+
const timeoutSecondsInput = screen.getByLabelText('timeout seconds input');
52+
53+
await user.clear(timeoutMinutesInput);
54+
await user.clear(timeoutSecondsInput);
55+
await user.type(timeoutMinutesInput, `{backspace}1`);
56+
await user.type(timeoutSecondsInput, `30`);
57+
58+
await submitForm(user);
59+
60+
const { body } = await read();
61+
62+
expect(body.timeout).toBe(MAX_TIMEOUT_MS);
63+
});
4164
});

‎src/page/NewCheck/__tests__/NewCheck.journey.test.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { screen, waitFor } from '@testing-library/react';
22
import { DataTestIds } from 'test/dataTestIds';
3+
import { PUBLIC_PROBE } from 'test/fixtures/probes';
34
import { apiRoute } from 'test/handlers';
45
import { server } from 'test/server';
56
import { runTestAsHGFreeUserOverLimit, runTestWithoutLogsAccess } from 'test/utils';
@@ -213,6 +214,41 @@ describe(`<NewCheck /> journey`, () => {
213214
expect(submitButton).toBeEnabled();
214215
});
215216

217+
it(`should display an error message when the frequency is less than the timeout`, async () => {
218+
const { user } = await renderNewForm(CheckType.Scripted);
219+
220+
await user.type(screen.getByLabelText('Job name', { exact: false }), `Job`);
221+
await user.type(screen.getByLabelText(`Instance`, { exact: false }), `Instance`);
222+
223+
await goToSection(user, 2);
224+
225+
const timeoutMinutesInput = screen.getByLabelText('timeout minutes input');
226+
const timeoutSecondsInput = screen.getByLabelText('timeout seconds input');
227+
228+
await user.clear(timeoutMinutesInput);
229+
await user.clear(timeoutSecondsInput);
230+
await user.type(timeoutMinutesInput, '1');
231+
await user.type(timeoutSecondsInput, '30');
232+
233+
await goToSection(user, 5);
234+
235+
const minutesInput = screen.getByLabelText('frequency minutes input');
236+
const secondsInput = screen.getByLabelText('frequency seconds input');
237+
await user.clear(minutesInput);
238+
await user.clear(secondsInput);
239+
await user.type(minutesInput, `{backspace}1`);
240+
await user.type(secondsInput, '10');
241+
242+
const probeCheckbox = await screen.findByLabelText(PUBLIC_PROBE.name);
243+
await user.click(probeCheckbox);
244+
245+
await submitForm(user);
246+
247+
const errorMsg = await screen.findByRole('alert');
248+
expect(errorMsg).toBeInTheDocument();
249+
expect(errorMsg).toHaveTextContent(/Frequency must be greater than or equal to timeout \(90 seconds\)/);
250+
});
251+
216252
// jsdom doesn't give us back the submitter of the form, so we can't test this
217253
// https://github.com/jsdom/jsdom/issues/3117
218254
it.skip(`should show an error message when it fails to test a check`, async () => {});

‎src/page/NewCheck/__tests__/ScriptedChecks/Scripted/5-execution.payload.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,27 @@ describe(`ScriptedCheck - Section 5 (Execution) payload`, () => {
3838

3939
expect(body.frequency).toBe(ONE_MINUTE_IN_MS);
4040
});
41+
42+
it(`can add timeout up to 90 seconds`, async () => {
43+
const MAX_TIMEOUT_MS = 90000;
44+
45+
const { user, read } = await renderNewForm(checkType);
46+
await fillMandatoryFields({ user, checkType });
47+
48+
await goToSection(user, 2);
49+
50+
const timeoutMinutesInput = screen.getByLabelText('timeout minutes input');
51+
const timeoutSecondsInput = screen.getByLabelText('timeout seconds input');
52+
53+
await user.clear(timeoutMinutesInput);
54+
await user.clear(timeoutSecondsInput);
55+
await user.type(timeoutMinutesInput, `{backspace}1`);
56+
await user.type(timeoutSecondsInput, `30`);
57+
58+
await submitForm(user);
59+
60+
const { body } = await read();
61+
62+
expect(body.timeout).toBe(MAX_TIMEOUT_MS);
63+
});
4164
});

0 commit comments

Comments
 (0)