Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Local uri input monitor support #250

Open
wants to merge 5 commits into
base: local-uri-input-monitor-support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import React, { Fragment } from 'react';
import { EuiSpacer, EuiFlexItem, EuiFlexGroup, EuiCodeEditor, EuiFormRow } from '@elastic/eui';
import { hasError, isInvalid } from '../../../../utils/validate';
import { FormikFieldText } from '../../../../components/FormControls';

const LocalUriInput = ({ isDarkMode, response, values }) => (
<Fragment>
<EuiFlexGroup alignItems="flexStart">
<EuiFlexItem>
<EuiSpacer size="m" />
<FormikFieldText
name={`${values.searchType}.path`}
formRow
rowProps={{
label: 'Path',
helpText:
'The path associated with the REST API the monitor should call (e.g., "/_cluster/health").',
style: { paddingLeft: '10px' },
isInvalid,
error: hasError,
}}
inputProps={{
isInvalid,
onChange: (e, field, form) => {
form.setFieldValue('uri.path', e.target.value);
},
}}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiFormRow label="Response" fullWidth>
<EuiCodeEditor
mode="json"
theme={isDarkMode ? 'sense-dark' : 'github'}
width="100%"
height="500px"
value={response}
readOnly
/>
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
</Fragment>
);

export default LocalUriInput;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import React from 'react';
import { render } from 'enzyme';
import { Formik } from 'formik';

import LocalUriInput from './LocalUriInput';

describe('LocalUriInput', () => {
test('renders', () => {
const component = (
<Formik>
<LocalUriInput values={{ searchType: 'localUri' }} />
</Formik>
);
expect(render(component)).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`LocalUriInput renders 1`] = `
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsFlexStart euiFlexGroup--directionRow euiFlexGroup--responsive"
>
<div
class="euiFlexItem"
>
<div
class="euiSpacer euiSpacer--m"
/>
<div
class="euiFormRow"
id="localUri.path-form-row-row"
style="padding-left:10px"
>
<div
class="euiFormRow__labelWrapper"
>
<label
aria-invalid="false"
class="euiFormLabel euiFormRow__label"
for="localUri.path-form-row"
>
Path
</label>
</div>
<div
class="euiFormRow__fieldWrapper"
>
<div
class="euiFormControlLayout"
>
<div
class="euiFormControlLayout__childrenWrapper"
>
<input
class="euiFieldText"
name="localUri.path"
type="text"
/>
</div>
</div>
<div
class="euiFormHelpText euiFormRow__text"
id="localUri.path-form-row-help"
>
The path associated with the REST API the monitor should call (e.g., "/_cluster/health").
</div>
</div>
</div>
</div>
<div
class="euiFlexItem"
>
<div
class="euiFormRow euiFormRow--fullWidth"
id="generated-id-row"
>
<div
class="euiFormRow__labelWrapper"
>
<label
class="euiFormLabel euiFormRow__label"
for="generated-id"
>
Response
</label>
</div>
<div
class="euiFormRow__fieldWrapper"
>
<div
class="euiCodeEditorWrapper"
data-test-subj="codeEditorContainer"
style="width:100%;height:500px"
>
<div
class="euiCodeEditorKeyboardHint"
data-test-subj="codeEditorHint"
id="generated-id"
role="button"
tabindex="0"
>
<p
class="euiText"
>
Press Enter to start editing.
</p>
<p
class="euiText"
>
When you're done, press Escape to stop editing.
</p>
</div>
<div
id="generated-id"
style="width:100%;height:500px"
/>
</div>
</div>
</div>
</div>
</div>
`;
18 changes: 18 additions & 0 deletions public/pages/CreateMonitor/components/LocalUriInput/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import LocalUriImport from './LocalUriInput';

export default LocalUriImport;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@ import { ES_AD_PLUGIN } from '../../../../utils/constants';
const defaultSelectDefinitions = [
{ value: 'graph', text: 'Define using visual graph' },
{ value: 'query', text: 'Define using extraction query' },
{ value: 'localUri', text: 'Define using Local URI endpoint' },
];

const onChangeDefinition = (e, form, resetResponse) => {
Expand All @@ -28,7 +29,7 @@ const onChangeDefinition = (e, form, resetResponse) => {
form.setFieldValue('searchType', type);
};

const selectDefinitions = plugins => {
const selectDefinitions = (plugins) => {
return plugins === undefined || plugins.indexOf(ES_AD_PLUGIN) == -1
? defaultSelectDefinitions
: [...defaultSelectDefinitions, { value: 'ad', text: 'Define using anomaly detector' }];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ exports[`MonitorDefinition renders 1`] = `
>
Define using extraction query
</option>
<option
value="localUri"
>
Define using Local URI endpoint
</option>
</select>
<div
class="euiFormControlLayoutIcons euiFormControlLayoutIcons--right"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ exports[`AnomalyDetectors renders 1`] = `
"searchType": "graph",
"timeField": "",
"timezone": Array [],
"uri": Object {
"host": "localhost",
"path": "",
"port": "9200",
"scheme": "http",
"url": "",
},
"weekly": Object {
"fri": false,
"mon": false,
Expand Down Expand Up @@ -89,6 +96,13 @@ exports[`AnomalyDetectors renders 1`] = `
"searchType": "graph",
"timeField": "",
"timezone": Array [],
"uri": Object {
"host": "localhost",
"path": "",
"port": "9200",
"scheme": "http",
"url": "",
},
"weekly": Object {
"fri": false,
"mon": false,
Expand Down Expand Up @@ -204,6 +218,13 @@ exports[`AnomalyDetectors renders 1`] = `
"searchType": "graph",
"timeField": "",
"timezone": Array [],
"uri": Object {
"host": "localhost",
"path": "",
"port": "9200",
"scheme": "http",
"url": "",
},
"weekly": Object {
"fri": false,
"mon": false,
Expand Down Expand Up @@ -277,6 +298,13 @@ exports[`AnomalyDetectors renders 1`] = `
"searchType": "graph",
"timeField": "",
"timezone": Array [],
"uri": Object {
"host": "localhost",
"path": "",
"port": "9200",
"scheme": "http",
"url": "",
},
"weekly": Object {
"fri": false,
"mon": false,
Expand Down Expand Up @@ -398,6 +426,13 @@ exports[`AnomalyDetectors renders 1`] = `
"searchType": "graph",
"timeField": "",
"timezone": Array [],
"uri": Object {
"host": "localhost",
"path": "",
"port": "9200",
"scheme": "http",
"url": "",
},
"weekly": Object {
"fri": false,
"mon": false,
Expand Down Expand Up @@ -471,6 +506,13 @@ exports[`AnomalyDetectors renders 1`] = `
"searchType": "graph",
"timeField": "",
"timezone": Array [],
"uri": Object {
"host": "localhost",
"path": "",
"port": "9200",
"scheme": "http",
"url": "",
},
"weekly": Object {
"fri": false,
"mon": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ exports[`CreateMonitor renders 1`] = `
"searchType": "graph",
"timeField": "",
"timezone": Array [],
"uri": Object {
"host": "localhost",
"path": "",
"port": "9200",
"scheme": "http",
"url": "",
},
"weekly": Object {
"fri": false,
"mon": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ Array [
]
`;

exports[`formikToInputs can call formikToLocalUri 1`] = `
Object {
"uri": Object {
"host": "localhost",
"path": "",
"port": "9200",
"scheme": "http",
},
}
`;

exports[`formikToLocalUri can build a LocalUriInput request 1`] = `
Object {
"uri": Object {
"host": "localhost",
"path": "",
"port": "9200",
"scheme": "http",
},
}
`;

exports[`formikToMonitor can build monitor 1`] = `
Object {
"enabled": false,
Expand Down
Loading