Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented support for action execution configurations for doc level monitors #237

Closed
Closed
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
Expand Up @@ -6,16 +6,13 @@
import _ from 'lodash';
import { formikToClusterMetricsInput } from '../../../containers/CreateMonitor/utils/formikToMonitor';
import {
DEFAULT_CLUSTER_METRICS_SCRIPT,
API_TYPES,
GET_API_TYPE_DEBUG_TEXT,
ILLEGAL_PATH_PARAMETER_CHARACTERS,
NO_PATH_PARAMS_PLACEHOLDER_TEXT,
PATH_PARAMETER_ILLEGAL_CHARACTER_TEXT,
PATH_PARAMETERS_REQUIRED_TEXT,
API_TYPES,
NO_PATH_PARAMS_PLACEHOLDER_TEXT,
GET_API_TYPE_DEBUG_TEXT,
} from './clusterMetricsMonitorConstants';
import { SEARCH_TYPE } from '../../../../../utils/constants';
import { FORMIK_INITIAL_TRIGGER_VALUES } from '../../../../CreateTrigger/containers/CreateTrigger/utils/constants';
import { FORMIK_INITIAL_VALUES } from '../../../containers/CreateMonitor/utils/constants';

export function buildClusterMetricsRequest(values) {
Expand Down Expand Up @@ -66,17 +63,6 @@ export const getApiTypesRequiringPathParams = () => {
return apiList;
};

export const getDefaultScript = (monitorValues) => {
const searchType = _.get(monitorValues, 'searchType', FORMIK_INITIAL_VALUES.searchType);
switch (searchType) {
case SEARCH_TYPE.CLUSTER_METRICS:
const apiType = _.get(monitorValues, 'uri.api_type');
return _.get(API_TYPES, `${apiType}.defaultCondition`, DEFAULT_CLUSTER_METRICS_SCRIPT);
default:
return FORMIK_INITIAL_TRIGGER_VALUES.script;
}
};

export const getExamplePathParams = (apiType) => {
if (_.isEmpty(apiType)) return NO_PATH_PARAMS_PLACEHOLDER_TEXT;
let exampleText = _.get(API_TYPES, `${apiType}.exampleText`, '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import _ from 'lodash';
import {
API_TYPES,
DEFAULT_CLUSTER_METRICS_SCRIPT,
GET_API_TYPE_DEBUG_TEXT,
ILLEGAL_PATH_PARAMETER_CHARACTERS,
NO_PATH_PARAMS_PLACEHOLDER_TEXT,
Expand All @@ -19,15 +18,12 @@ import {
getApiPath,
getApiType,
getApiTypesRequiringPathParams,
getDefaultScript,
getExamplePathParams,
isInvalidApiPathParameter,
pathParamsContainIllegalCharacters,
validateApiPathParameter,
} from './clusterMetricsMonitorHelpers';
import { FORMIK_INITIAL_VALUES } from '../../../containers/CreateMonitor/utils/constants';
import { SEARCH_TYPE } from '../../../../../utils/constants';
import { FORMIK_INITIAL_TRIGGER_VALUES } from '../../../../CreateTrigger/containers/CreateTrigger/utils/constants';

describe('clusterMetricsMonitorHelpers', () => {
describe('buildClusterMetricsRequest', () => {
Expand Down Expand Up @@ -273,61 +269,6 @@ describe('clusterMetricsMonitorHelpers', () => {
});
});

describe('getDefaultScript', () => {
test('when searchType is undefined', () => {
const monitorValues = undefined;
expect(getDefaultScript(monitorValues)).toEqual(FORMIK_INITIAL_TRIGGER_VALUES.script);
});
test('when searchType is clusterMetrics and api_type is undefined', () => {
const monitorValues = {
searchType: SEARCH_TYPE.CLUSTER_METRICS,
uri: undefined,
};
expect(getDefaultScript(monitorValues)).toEqual(DEFAULT_CLUSTER_METRICS_SCRIPT);
});
test('when searchType is clusterMetrics and api_type is empty', () => {
const monitorValues = {
searchType: SEARCH_TYPE.CLUSTER_METRICS,
uri: {
api_type: '',
},
};
expect(getDefaultScript(monitorValues)).toEqual(DEFAULT_CLUSTER_METRICS_SCRIPT);
});
test('when searchType is clusterMetrics and api_type does not have a default condition', () => {
const monitorValues = {
searchType: SEARCH_TYPE.CLUSTER_METRICS,
uri: {
api_type: 'unknownApi',
},
};
expect(getDefaultScript(monitorValues)).toEqual(DEFAULT_CLUSTER_METRICS_SCRIPT);
});

_.keys(SEARCH_TYPE).forEach((searchType) => {
test(`when searchType is ${searchType}`, () => {
if (SEARCH_TYPE[searchType] !== SEARCH_TYPE.CLUSTER_METRICS) {
const monitorValues = { searchType: searchType };
expect(getDefaultScript(monitorValues)).toEqual(FORMIK_INITIAL_TRIGGER_VALUES.script);
}
});
});

_.keys(API_TYPES).forEach((apiType) => {
test(`when searchType is clusterMetrics and api_type is ${apiType}`, () => {
const monitorValues = {
searchType: SEARCH_TYPE.CLUSTER_METRICS,
uri: {
api_type: apiType,
},
};
const expectedOutput = _.get(API_TYPES, `${apiType}.defaultCondition`);
if (!_.isEmpty(expectedOutput))
expect(getDefaultScript(monitorValues)).toEqual(expectedOutput);
});
});
});

describe('getExamplePathParams', () => {
test('when apiType has no example text', () => {
const apiType = 'apiTypeWithoutExampleText';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import React from 'react';
import _ from 'lodash';
import { EuiFlexGrid, EuiFlexItem, EuiText } from '@elastic/eui';
import FormikCheckableCard from '../../../../components/FormControls/FormikCheckableCard';
import { MONITOR_TYPE, SEARCH_TYPE } from '../../../../utils/constants';
Expand All @@ -23,8 +22,12 @@ const onChangeDefinition = (e, form) => {
// Clearing various form fields when changing monitor types.
// TODO: Implement modal that confirms the change before clearing.
form.setFieldValue('index', FORMIK_INITIAL_VALUES.index);
form.setFieldValue('searchType', FORMIK_INITIAL_VALUES.searchType);
form.setFieldValue('triggerDefinitions', FORMIK_INITIAL_TRIGGER_VALUES.triggerConditions);
switch (type) {
case MONITOR_TYPE.CLUSTER_METRICS:
form.setFieldValue('searchType', SEARCH_TYPE.CLUSTER_METRICS);
break;
case MONITOR_TYPE.DOC_LEVEL:
form.setFieldValue('query', DEFAULT_DOCUMENT_LEVEL_QUERY);
break;
Expand Down Expand Up @@ -71,9 +74,7 @@ const MonitorType = ({ values }) => (
label: 'Per query monitor',
checked: values.monitor_type === MONITOR_TYPE.QUERY_LEVEL,
value: MONITOR_TYPE.QUERY_LEVEL,
onChange: (e, field, form) => {
onChangeDefinition(e, form);
},
onChange: (e, field, form) => onChangeDefinition(e, form),
children: queryLevelDescription,
'data-test-subj': 'queryLevelMonitorRadioCard',
}}
Expand All @@ -89,14 +90,7 @@ const MonitorType = ({ values }) => (
label: 'Per bucket monitor',
checked: values.monitor_type === MONITOR_TYPE.BUCKET_LEVEL,
value: MONITOR_TYPE.BUCKET_LEVEL,
onChange: (e, field, form) => {
const searchType = _.get(values, 'searchType');
// Setting search type to graph when changing monitor type from query-level to bucket-level,
// and the search type is not supported by bucket-level monitors.
if (searchType !== SEARCH_TYPE.GRAPH || searchType !== SEARCH_TYPE.QUERY)
form.setFieldValue('searchType', SEARCH_TYPE.GRAPH);
onChangeDefinition(e, form);
},
onChange: (e, field, form) => onChangeDefinition(e, form),
children: bucketLevelDescription,
'data-test-subj': 'bucketLevelMonitorRadioCard',
}}
Expand All @@ -112,10 +106,7 @@ const MonitorType = ({ values }) => (
label: 'Per cluster metrics monitor',
checked: values.monitor_type === MONITOR_TYPE.CLUSTER_METRICS,
value: MONITOR_TYPE.CLUSTER_METRICS,
onChange: (e, field, form) => {
form.setFieldValue('searchType', SEARCH_TYPE.CLUSTER_METRICS);
onChangeDefinition(e, form);
},
onChange: (e, field, form) => onChangeDefinition(e, form),
children: clusterMetricsDescription,
'data-test-subj': 'clusterMetricsMonitorRadioCard',
}}
Expand All @@ -131,9 +122,7 @@ const MonitorType = ({ values }) => (
label: 'Per document monitor',
checked: values.monitor_type === MONITOR_TYPE.DOC_LEVEL,
value: MONITOR_TYPE.DOC_LEVEL,
onChange: (e, field, form) => {
onChangeDefinition(e, form);
},
onChange: (e, field, form) => onChangeDefinition(e, form),
children: documentLevelDescription,
'data-test-subj': 'docLevelMonitorRadioCard',
}}
Expand Down
Loading