diff --git a/public/pages/CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorHelpers.test.js b/public/pages/CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorHelpers.test.js index fee91cd81..018614b7f 100644 --- a/public/pages/CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorHelpers.test.js +++ b/public/pages/CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorHelpers.test.js @@ -88,7 +88,7 @@ describe('clusterMetricsMonitorHelpers', () => { uri: { api_type: API_TYPES.CLUSTER_HEALTH.type, path: path, - path_params: pathParams, + path_params: '/' + pathParams, url: `http://localhost:9200/${path}/${pathParams}`, }, }; diff --git a/public/pages/CreateMonitor/containers/CreateMonitor/utils/formikToMonitor.js b/public/pages/CreateMonitor/containers/CreateMonitor/utils/formikToMonitor.js index 6aea28e13..bb9d81a33 100644 --- a/public/pages/CreateMonitor/containers/CreateMonitor/utils/formikToMonitor.js +++ b/public/pages/CreateMonitor/containers/CreateMonitor/utils/formikToMonitor.js @@ -157,13 +157,18 @@ export function formikToClusterMetricsInput(values) { if (_.isEmpty(apiType)) apiType = getApiType(_.get(values, 'uri')); let pathParams = _.get(values, 'uri.path_params', FORMIK_INITIAL_VALUES.uri.path_params); pathParams = _.trim(pathParams); + // Trim '/' characters from the beginning and end of the path + pathParams = pathParams?.replace(/^\/+|\/+$/g, ''); const hasPathParams = !_.isEmpty(pathParams); const path = getApiPath(hasPathParams, apiType); let url = FORMIK_INITIAL_VALUES.uri.url; if (!_.isEmpty(apiType)) { url = URL_DEFAULT_PREFIX; if (!_.isEmpty(path)) url = url + '/' + path; - if (hasPathParams) url = url + '/' + pathParams + _.get(API_TYPES, `${apiType}.appendText`, ''); + if (hasPathParams) { + pathParams = '/' + pathParams; + url = url + pathParams + _.get(API_TYPES, `${apiType}.appendText`, ''); + } } return { uri: {