From daa0fe00f2bbbe3848df723502464974a2b8b23d Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Thu, 13 Jul 2023 17:39:16 -0700 Subject: [PATCH] Fix URI string generation logic. (#639) (#640) * Fix URI string generation logic. Signed-off-by: AWSHurneyt * Updated test. Signed-off-by: AWSHurneyt --------- Signed-off-by: AWSHurneyt (cherry picked from commit 043881b52dfa8749016a141c38c695ee6f7d76aa) Co-authored-by: AWSHurneyt --- .../utils/clusterMetricsMonitorHelpers.test.js | 2 +- .../containers/CreateMonitor/utils/formikToMonitor.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) 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: {