From 636303021ff11865010e6760350b451f9963515a Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Sun, 3 Apr 2022 21:35:56 +0800 Subject: [PATCH] [monitor]feature:param yml support key-value map (#57) --- .../dispatch/timer/WheelTimerTask.java | 21 +++++++ .../usthe/common/entity/job/Configmap.java | 2 +- .../usthe/common/entity/manager/Param.java | 6 +- .../common/entity/manager/ParamDefine.java | 20 ++++-- .../service/impl/MonitorServiceImpl.java | 3 + .../main/resources/define/app/A-example.yml | 6 +- .../main/resources/define/param/A-example.yml | 8 ++- web-app/src/app/pojo/ParamDefine.ts | 3 + .../monitor-edit/monitor-edit.component.html | 12 ++++ .../monitor-edit/monitor-edit.component.ts | 8 ++- .../monitor-new/monitor-new.component.html | 12 ++++ .../monitor-new/monitor-new.component.ts | 8 ++- web-app/src/app/shared/components/README.md | 2 - .../key-value-input.component.html | 12 ++++ .../key-value-input.component.less | 12 ++++ .../key-value-input.component.spec.ts | 25 ++++++++ .../key-value-input.component.ts | 63 +++++++++++++++++++ web-app/src/app/shared/shared.module.ts | 3 +- 18 files changed, 210 insertions(+), 16 deletions(-) delete mode 100644 web-app/src/app/shared/components/README.md create mode 100644 web-app/src/app/shared/components/key-value-input/key-value-input.component.html create mode 100644 web-app/src/app/shared/components/key-value-input/key-value-input.component.less create mode 100644 web-app/src/app/shared/components/key-value-input/key-value-input.component.spec.ts create mode 100644 web-app/src/app/shared/components/key-value-input/key-value-input.component.ts diff --git a/collector/src/main/java/com/usthe/collector/dispatch/timer/WheelTimerTask.java b/collector/src/main/java/com/usthe/collector/dispatch/timer/WheelTimerTask.java index f950e3f..7cde187 100644 --- a/collector/src/main/java/com/usthe/collector/dispatch/timer/WheelTimerTask.java +++ b/collector/src/main/java/com/usthe/collector/dispatch/timer/WheelTimerTask.java @@ -12,6 +12,7 @@ import com.usthe.common.entity.job.Job; import com.usthe.common.entity.job.Metrics; import com.usthe.common.util.AesUtil; import com.usthe.common.util.CommonConstants; +import com.usthe.common.util.GsonUtil; import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; @@ -84,6 +85,26 @@ public class WheelTimerTask implements TimerTask { while (iterator.hasNext()) { Map.Entry entry = iterator.next(); JsonElement element = entry.getValue(); + String key = entry.getKey(); + // 替换KEY-VALUE情况的属性 比如http headers params + if (key != null && key.startsWith("^_^") && key.endsWith("^_^")) { + key = key.replaceAll("\\^_\\^", ""); + Configmap param = configmap.get(key); + if (param.getType() == (byte) 3) { + String jsonValue = (String) param.getValue(); + Map map = GsonUtil.fromJson(jsonValue, Map.class); + if (map != null) { + map.forEach((name, value) -> { + if (name != null && !"".equals(name.trim())) { + jsonObject.addProperty(name, value); + } + }); + } + } + iterator.remove(); + continue; + } + // 替换正常的VALUE值 if (element.isJsonPrimitive()) { // 判断是否含有特殊字符 替换 String value = element.getAsString(); diff --git a/common/src/main/java/com/usthe/common/entity/job/Configmap.java b/common/src/main/java/com/usthe/common/entity/job/Configmap.java index cc149d0..11af4ea 100644 --- a/common/src/main/java/com/usthe/common/entity/job/Configmap.java +++ b/common/src/main/java/com/usthe/common/entity/job/Configmap.java @@ -28,7 +28,7 @@ public class Configmap { private Object value; /** - * 参数类型 0:数字 1:字符串 2:加密串 + * 参数类型 0:数字 1:字符串 2:加密串 3:map映射的json串 * number,string,secret * 数字,非加密字符串,加密字符串 */ diff --git a/common/src/main/java/com/usthe/common/entity/manager/Param.java b/common/src/main/java/com/usthe/common/entity/manager/Param.java index 7a7adf6..ff09b08 100644 --- a/common/src/main/java/com/usthe/common/entity/manager/Param.java +++ b/common/src/main/java/com/usthe/common/entity/manager/Param.java @@ -63,11 +63,11 @@ public class Param { private String value; /** - * 参数类型 0:数字 1:字符串 2:加密串 + * 参数类型 0:数字 1:字符串 2:加密串 3:map映射的json串 */ - @ApiModelProperty(value = "参数类型 0:数字 1:字符串 2:加密串", accessMode = READ_WRITE, position = 4) + @ApiModelProperty(value = "参数类型 0:数字 1:字符串 2:加密串 3:map映射的json串", accessMode = READ_WRITE, position = 4) @Min(0) - @Max(2) + @Max(3) private byte type; /** diff --git a/common/src/main/java/com/usthe/common/entity/manager/ParamDefine.java b/common/src/main/java/com/usthe/common/entity/manager/ParamDefine.java index 9ff26a8..25cc5bc 100644 --- a/common/src/main/java/com/usthe/common/entity/manager/ParamDefine.java +++ b/common/src/main/java/com/usthe/common/entity/manager/ParamDefine.java @@ -110,29 +110,41 @@ public class ParamDefine { @Convert(converter = JsonOptionListAttributeConverter.class) private List