From f28998f947e32677ffb31a43cca3d617cab8ccb7 Mon Sep 17 00:00:00 2001 From: Fine Date: Wed, 31 May 2023 17:53:40 +0800 Subject: [PATCH] feat: add regex --- src/components/Selector.vue | 8 ++- src/types/continous-profiling.d.ts | 2 +- .../components/EditPolicy.vue | 6 +-- .../components/Policy.vue | 50 ++++++++++++++++--- .../components/PolicyList.vue | 2 +- 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/components/Selector.vue b/src/components/Selector.vue index 5c2d9ca6..30be63bc 100644 --- a/src/components/Selector.vue +++ b/src/components/Selector.vue @@ -27,7 +27,13 @@ limitations under the License. --> :remote-method="remoteMethod" :filterable="filterable" > - + diff --git a/src/types/continous-profiling.d.ts b/src/types/continous-profiling.d.ts index 10e99878..e09f1195 100644 --- a/src/types/continous-profiling.d.ts +++ b/src/types/continous-profiling.d.ts @@ -16,7 +16,7 @@ */ export interface StrategyItem { - targetType: string; + type: string; checkItems: CheckItems[]; } export type CheckItems = { diff --git a/src/views/dashboard/related/continuous-profiling/components/EditPolicy.vue b/src/views/dashboard/related/continuous-profiling/components/EditPolicy.vue index 2ef0f0c7..6a6638e1 100644 --- a/src/views/dashboard/related/continuous-profiling/components/EditPolicy.vue +++ b/src/views/dashboard/related/continuous-profiling/components/EditPolicy.vue @@ -80,7 +80,7 @@ limitations under the License. --> function createPolicy(e: PointerEvent) { e.stopPropagation(); policyList.value.push({ - targetType: "", + type: "", checkItems: [ { type: "", @@ -99,9 +99,9 @@ limitations under the License. --> const checkItems = d.checkItems.filter( (item: CheckItems) => item.type && item.threshold && item.period && item.count, ); - if (d.targetType && checkItems.length) { + if (d.type && checkItems.length) { const v = { - ...d, + targetType: d.type, checkItems, }; params.push(v); diff --git a/src/views/dashboard/related/continuous-profiling/components/Policy.vue b/src/views/dashboard/related/continuous-profiling/components/Policy.vue index 8f95c5ca..1d50293d 100644 --- a/src/views/dashboard/related/continuous-profiling/components/Policy.vue +++ b/src/views/dashboard/related/continuous-profiling/components/Policy.vue @@ -18,7 +18,7 @@ limitations under the License. -->
-
{{ t("threshold") }}
- +
+ {{ t("threshold") }} + ({{ getNotice(item.type) }} ) +
+
{{ t("period") }}
@@ -100,13 +109,12 @@ limitations under the License. --> const { t } = useI18n(); const states = reactive(props.policyList[props.order]); const TYPES = ["HTTP_ERROR_RATE", "HTTP_AVG_RESPONSE_TIME"]; - function changeType(opt: { value: string }[]) { - const types = props.policyList.map((item: StrategyItem) => item.targetType); + const types = props.policyList.map((item: StrategyItem) => item.type); if (types.includes(opt[0].value)) { return ElMessage.warning("Target type cannot be configured repeatedly."); } - states.targetType = opt[0].value; + states.type = opt[0].value; emits("edit", states, props.order); } @@ -130,6 +138,24 @@ limitations under the License. --> emits("edit", states, props.order); } + function changeThreshold(index: number) { + let regex = /^(100(\.0{1,2})?|[1-9]?\d(\.\d{1,2})?)%$/; + if (MonitorType[1].value === states.checkItems[index].type) { + regex = /^\d+$/; + } + if (MonitorType[2].value === states.checkItems[index].type) { + regex = /^(\d+)(\.\d+)?$/; + } + if (MonitorType[4].value === states.checkItems[index].type) { + regex = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/; + } + + if (!regex.test(states.checkItems[index].threshold)) { + return ElMessage.warning(getNotice(states.checkItems[index].type)); + } + emits("edit", states, props.order); + } + function changeParam(index?: any) { if (index !== undefined && (states.checkItems[index] || {}).uriList) { return ElMessage.warning("UriList or UriRegex only be configured with one option"); @@ -161,6 +187,18 @@ limitations under the License. --> states.checkItems = states.checkItems.filter((_, index: number) => index !== key); emits("edit", states, props.order); } + + function getNotice(type: string) { + const map: { [key: string]: string } = { + PROCESS_CPU: "It should be percentage data", + PROCESS_THREAD_COUNT: "It should be a positive integer", + SYSTEM_LOAD: "It should be a floating point number", + HTTP_ERROR_RATE: "It should be percentage data", + HTTP_AVG_RESPONSE_TIME: "It should be a response time in milliseconds", + }; + + return map[type]; + }