From 08c9583971cf48ece8cb505fa7c9c0510ba8be95 Mon Sep 17 00:00:00 2001 From: Russ <8377044+rdubrock@users.noreply.github.com> Date: Wed, 28 Apr 2021 06:34:13 -0800 Subject: [PATCH 1/6] feat: add compression algo picker to http checks --- src/components/constants.ts | 10 ++++++++++ src/components/http/HttpSettings.tsx | 16 +++++++++++++++- src/types.ts | 8 ++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/components/constants.ts b/src/components/constants.ts index 3ec4435cf..1bfef56a9 100644 --- a/src/components/constants.ts +++ b/src/components/constants.ts @@ -14,6 +14,7 @@ import { CheckSort, CheckEnabledStatus, CheckListViewType, + HTTPCompressionAlgo, } from 'types'; export const DNS_RESPONSE_CODES = enumToStringArray(DnsResponseCodes).map((responseCode) => ({ @@ -270,6 +271,7 @@ export const CHECK_LIST_VIEW_TYPE_OPTIONS = [ { description: 'Card view', value: CheckListViewType.Card, icon: 'check-square' }, { description: 'List view', value: CheckListViewType.List, icon: 'list-ul' }, ]; + export const PEM_HEADER = '-----BEGIN CERTIFICATE-----'; export const PEM_FOOTER = '-----END CERTIFICATE-----'; @@ -277,3 +279,11 @@ export const PEM_FOOTER = '-----END CERTIFICATE-----'; export const CHECK_LIST_VIEW_TYPE_LS_KEY = 'grafana.sm.checklist.viewType'; export const INVALID_WEB_URL_MESSAGE = 'Target must be a valid web URL'; + +export const HTTP_COMPRESSION_ALGO_OPTIONS = [ + { label: 'None', value: HTTPCompressionAlgo.None }, + { label: 'Identity', value: HTTPCompressionAlgo.Identity }, + { label: 'BR', value: HTTPCompressionAlgo.Br }, + { label: 'GZIP', value: HTTPCompressionAlgo.Gzip }, + { label: 'Deflate', value: HTTPCompressionAlgo.Deflate }, +]; diff --git a/src/components/http/HttpSettings.tsx b/src/components/http/HttpSettings.tsx index 08c8fe872..e1fa3fee8 100644 --- a/src/components/http/HttpSettings.tsx +++ b/src/components/http/HttpSettings.tsx @@ -19,7 +19,12 @@ import { css } from 'emotion'; import { useFormContext, Controller, useFieldArray } from 'react-hook-form'; import { HttpMethod, HttpVersion, CheckType, HttpRegexValidationType } from 'types'; import { Collapse } from 'components/Collapse'; -import { HTTP_REGEX_VALIDATION_OPTIONS, HTTP_SSL_OPTIONS, IP_OPTIONS } from '../constants'; +import { + HTTP_COMPRESSION_ALGO_OPTIONS, + HTTP_REGEX_VALIDATION_OPTIONS, + HTTP_SSL_OPTIONS, + IP_OPTIONS, +} from '../constants'; import { LabelField } from 'components/LabelField'; import { TLSConfig } from 'components/TLSConfig'; import { NameValueInput } from 'components/NameValueInput'; @@ -234,6 +239,15 @@ export const HttpSettingsForm = ({ isEditor }: Props) => { /> + + + + + Date: Wed, 5 May 2021 10:29:26 -0800 Subject: [PATCH 2/6] chore: add tests for compression --- __mocks__/@grafana/ui.tsx | 14 ++++++++++---- src/components/CheckEditor/CheckEditor.test.tsx | 8 ++++++++ .../CheckEditor/checkFormTransformations.ts | 5 +++-- src/components/CheckList.test.tsx | 2 +- src/components/constants.ts | 10 +++++----- src/components/http/HttpSettings.tsx | 12 +++++++++--- src/types.ts | 8 ++++---- src/validation.test.ts | 12 +++++++++++- 8 files changed, 51 insertions(+), 20 deletions(-) diff --git a/__mocks__/@grafana/ui.tsx b/__mocks__/@grafana/ui.tsx index 3c57ca9bc..43613941f 100644 --- a/__mocks__/@grafana/ui.tsx +++ b/__mocks__/@grafana/ui.tsx @@ -1,7 +1,7 @@ import * as ui from '@grafana/ui'; import React from 'react'; -const Select = ({ options, value, onChange, multiple = false, prefix, ...rest }: any) => { +const Select = ({ options, value, onChange, multiple = false, prefix, id, ...rest }: any) => { function handleChange(event) { const option = options.find((option) => { return String(option.value) === event.currentTarget.value; @@ -16,9 +16,15 @@ const Select = ({ options, value, onChange, multiple = false, prefix, ...rest }: return (
{prefix} - + {options.map(({ label, value }, index) => ( + ))} diff --git a/src/components/CheckEditor/CheckEditor.test.tsx b/src/components/CheckEditor/CheckEditor.test.tsx index 2898ca381..082b5e253 100644 --- a/src/components/CheckEditor/CheckEditor.test.tsx +++ b/src/components/CheckEditor/CheckEditor.test.tsx @@ -10,6 +10,7 @@ import { HttpVersion, GlobalSettings, AlertSensitivity, + HTTPCompressionAlgo, } from 'types'; import { CheckEditor } from './CheckEditor'; import { getInstanceMock } from '../../datasource/__mocks__/DataSource'; @@ -288,6 +289,7 @@ describe('HTTP', () => { settings: { http: { method: HttpMethod.GET, + compression: HTTPCompressionAlgo.gzip, headers: ['headerName:headerValue'], body: 'requestbody', ipVersion: IpVersion.V6, @@ -329,6 +331,7 @@ describe('HTTP', () => { expect(await screen.findByLabelText('Request body', { exact: false })).toHaveValue('requestbody'); expect(await within(httpSection).findByPlaceholderText('name')).toHaveValue('headerName'); expect(await within(httpSection).findByPlaceholderText('value')).toHaveValue('headerValue'); + expect(within(httpSection).getByTestId('http-compression')).toHaveValue('gzip'); await toggleSection('TLS config'); expect(await screen.findByLabelText('Disable target certificate validation')).toBeChecked(); @@ -391,6 +394,10 @@ describe('HTTP', () => { await userEvent.click(await screen.findByRole('button', { name: 'Add header' })); await act(async () => await userEvent.type(await screen.findByPlaceholderText('name'), 'headerName')); await act(async () => await userEvent.type(await screen.findByPlaceholderText('value'), 'headerValue')); + const compression = await screen.findByLabelText('The compression algorithm to expect in the response body', { + exact: false, + }); + userEvent.selectOptions(compression, 'deflate'); await toggleSection('HTTP settings'); // TLS Config @@ -466,6 +473,7 @@ describe('HTTP', () => { method: 'GET', headers: ['headerName:headerValue'], body: 'requestbody', + compression: 'deflate', ipVersion: 'V4', noFollowRedirects: false, tlsConfig: { diff --git a/src/components/CheckEditor/checkFormTransformations.ts b/src/components/CheckEditor/checkFormTransformations.ts index 413cfbd3c..8e1897117 100644 --- a/src/components/CheckEditor/checkFormTransformations.ts +++ b/src/components/CheckEditor/checkFormTransformations.ts @@ -40,6 +40,7 @@ import { HTTP_REGEX_VALIDATION_OPTIONS, fallbackCheck, ALERT_SENSITIVITY_OPTIONS, + HTTP_COMPRESSION_ALGO_OPTIONS, } from 'components/constants'; import { checkType, fromBase64, toBase64 } from 'utils'; import isBase64 from 'is-base64'; @@ -59,7 +60,7 @@ export function fallbackSettings(t: CheckType): Settings { method: HttpMethod.GET, ipVersion: IpVersion.V4, noFollowRedirects: false, - compression: undefined, + compression: HTTPCompressionAlgo.None, }, }; } @@ -221,7 +222,7 @@ const getHttpSettingsFormValues = (settings: Settings): HttpSettingsFormValues = ipVersion: selectableValueFrom(httpSettings.ipVersion), headers: headersToLabels(httpSettings.headers), regexValidations, - compression: compression ? selectableValueFrom(compression) : selectableValueFrom(HTTPCompressionAlgo.None), + compression: compression ? selectableValueFrom(compression) : HTTP_COMPRESSION_ALGO_OPTIONS[0], }; }; diff --git a/src/components/CheckList.test.tsx b/src/components/CheckList.test.tsx index 674dfe69c..d8254e937 100644 --- a/src/components/CheckList.test.tsx +++ b/src/components/CheckList.test.tsx @@ -216,7 +216,7 @@ test('clicking status chiclet adds it to filter', async () => { userEvent.click(disabledChiclet[1]); const statusFilter = await screen.findByTestId('check-status-filter'); const checks = await screen.findAllByLabelText('check-card'); - expect(statusFilter).toHaveValue('0'); + expect(statusFilter).toHaveValue('2'); expect(checks.length).toBe(1); }); diff --git a/src/components/constants.ts b/src/components/constants.ts index e65177c71..221387ca0 100644 --- a/src/components/constants.ts +++ b/src/components/constants.ts @@ -285,9 +285,9 @@ export const CHECK_LIST_VIEW_TYPE_LS_KEY = 'grafana.sm.checklist.viewType'; export const INVALID_WEB_URL_MESSAGE = 'Target must be a valid web URL'; export const HTTP_COMPRESSION_ALGO_OPTIONS = [ - { label: 'None', value: HTTPCompressionAlgo.None }, - { label: 'Identity', value: HTTPCompressionAlgo.Identity }, - { label: 'BR', value: HTTPCompressionAlgo.Br }, - { label: 'GZIP', value: HTTPCompressionAlgo.Gzip }, - { label: 'Deflate', value: HTTPCompressionAlgo.Deflate }, + { label: 'none', value: HTTPCompressionAlgo.None }, + { label: 'identity', value: HTTPCompressionAlgo.identity }, + { label: 'br', value: HTTPCompressionAlgo.br }, + { label: 'gzip', value: HTTPCompressionAlgo.gzip }, + { label: 'deflate', value: HTTPCompressionAlgo.deflate }, ]; diff --git a/src/components/http/HttpSettings.tsx b/src/components/http/HttpSettings.tsx index e1fa3fee8..ee652e844 100644 --- a/src/components/http/HttpSettings.tsx +++ b/src/components/http/HttpSettings.tsx @@ -239,15 +239,21 @@ export const HttpSettingsForm = ({ isEditor }: Props) => { /> - + - + - + { @@ -24,6 +33,7 @@ describe('trivial cases', () => { basicMetricsOnly: true, settings: { http: { + compression: HTTPCompressionAlgo.None, method: HttpMethod.GET, ipVersion: IpVersion.V4, noFollowRedirects: false, From 326db1b44d61c268815eabfb94270f38cf019c0f Mon Sep 17 00:00:00 2001 From: Russ <8377044+rdubrock@users.noreply.github.com> Date: Thu, 6 May 2021 07:41:29 -0800 Subject: [PATCH 3/6] Update src/types.ts Co-authored-by: Suraj Nath --- src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 6786573c3..3b56d4209 100644 --- a/src/types.ts +++ b/src/types.ts @@ -449,7 +449,7 @@ export enum CheckListViewType { } export enum HTTPCompressionAlgo { - None = '', + none = '', identity = 'identity', br = 'br', gzip = 'gzip', From 934f52fad160920c936fc015b0e01711232d27d1 Mon Sep 17 00:00:00 2001 From: Russ <8377044+rdubrock@users.noreply.github.com> Date: Thu, 6 May 2021 07:41:37 -0800 Subject: [PATCH 4/6] Update src/validation.test.ts Co-authored-by: Suraj Nath --- src/validation.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation.test.ts b/src/validation.test.ts index 7dfdebebd..222599790 100644 --- a/src/validation.test.ts +++ b/src/validation.test.ts @@ -33,7 +33,7 @@ describe('trivial cases', () => { basicMetricsOnly: true, settings: { http: { - compression: HTTPCompressionAlgo.None, + compression: HTTPCompressionAlgo.none, method: HttpMethod.GET, ipVersion: IpVersion.V4, noFollowRedirects: false, From 6e1dd979d50559ae394ecb3fab413ed2856662f4 Mon Sep 17 00:00:00 2001 From: Russ <8377044+rdubrock@users.noreply.github.com> Date: Thu, 6 May 2021 07:41:41 -0800 Subject: [PATCH 5/6] Update src/components/CheckEditor/checkFormTransformations.ts Co-authored-by: Suraj Nath --- src/components/CheckEditor/checkFormTransformations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/CheckEditor/checkFormTransformations.ts b/src/components/CheckEditor/checkFormTransformations.ts index 8e1897117..c924111bf 100644 --- a/src/components/CheckEditor/checkFormTransformations.ts +++ b/src/components/CheckEditor/checkFormTransformations.ts @@ -60,7 +60,7 @@ export function fallbackSettings(t: CheckType): Settings { method: HttpMethod.GET, ipVersion: IpVersion.V4, noFollowRedirects: false, - compression: HTTPCompressionAlgo.None, + compression: HTTPCompressionAlgo.none, }, }; } From 7b0a9a0e42cd6f4ebab5a7e5c9b75805deba088f Mon Sep 17 00:00:00 2001 From: Russ <8377044+rdubrock@users.noreply.github.com> Date: Thu, 6 May 2021 07:41:46 -0800 Subject: [PATCH 6/6] Update src/components/constants.ts Co-authored-by: Suraj Nath --- src/components/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/constants.ts b/src/components/constants.ts index 221387ca0..57c68adb2 100644 --- a/src/components/constants.ts +++ b/src/components/constants.ts @@ -285,7 +285,7 @@ export const CHECK_LIST_VIEW_TYPE_LS_KEY = 'grafana.sm.checklist.viewType'; export const INVALID_WEB_URL_MESSAGE = 'Target must be a valid web URL'; export const HTTP_COMPRESSION_ALGO_OPTIONS = [ - { label: 'none', value: HTTPCompressionAlgo.None }, + { label: 'none', value: HTTPCompressionAlgo.none }, { label: 'identity', value: HTTPCompressionAlgo.identity }, { label: 'br', value: HTTPCompressionAlgo.br }, { label: 'gzip', value: HTTPCompressionAlgo.gzip },