Commit b4386d8d authored by zhouzihao's avatar zhouzihao

dev-添加配置项获取。添加失败跳过。添加说明文档

parent 0decc262
# java-devop-sentry
# Overview
定期请求接口,检查是否成功。如果失败累计到一定程度。发送邮件(或者其他形式)
来进行提醒。
# Feature
- 正常接口请求一组的时间间隔为5秒钟(配置的),也就是一分钟请求了12次。
- 可以设置接口在时间段内出错个数。可以设置一个阈值。(建议设置成6次)。
# 项目结构
# TODO
# ChangeLog
......@@ -47,6 +47,11 @@
<artifactId>hutool-all</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
......
......@@ -3,9 +3,11 @@ package com.vandyo.sentry.core;
import cn.hutool.json.JSONUtil;
import com.vandyo.sentry.core.cases.*;
import com.vandyo.sentry.core.collectionMachine.CollectionMachine;
import com.vandyo.sentry.core.config.MapConfig;
import com.vandyo.sentry.core.dto.ErrStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
......@@ -26,6 +28,10 @@ public class Tmp {
@Value("${vandyo.pwd}")
public String pwd;
@Autowired
private MapConfig mapConfig;
@Scheduled(fixedRate = 1000)
public void test() {
log.info("we run it {} times", ++times);
......@@ -47,6 +53,9 @@ public class Tmp {
public void check() {
Map<String, Map<ErrStatus, Long>> data = CollectionMachine.checkRule(5);
String info = JSONUtil.parseFromMap(data).toStringPretty();
log.warn(info);
// log.warn(info);
// 查看是否 符合规则 Using timeMap
Map<String,Integer> timeMap = mapConfig.getTimeMap();
log.info("start to check rule!");
}
}
......@@ -56,12 +56,14 @@ public class CarDetectDecorator extends CaseDecorator {
newRes.setData(carMap);
newRes.setSuccess(true);
}else {
newRes.setKey(carDetectUrl);
newRes.setStatus(Signature.matchStatus(response.getStatus()));
newRes.setSuccess(false);
}
}
return newRes;
}else {
oldRes.setIgnore(true);
return oldRes;
}
}
......
......@@ -60,6 +60,7 @@ public class CarInfoDecorator extends CaseDecorator {
CollectionMachine.post(newRes);
return newRes;
}else {
oldRes.setIgnore(true);
return oldRes;
}
}
......
......@@ -55,6 +55,7 @@ public class CarListDecorator extends CaseDecorator {
CollectionMachine.post(newRes);
return newRes;
} else {
oldRes.setIgnore(true);
return oldRes;
}
}
......
......@@ -24,6 +24,8 @@ public class EmptyCase extends Case {
res.setSId(sId);
res.setUId(uid);
res.setSuccess(true);
// 这里的请求结果进行跳过
res.setIgnore(true);
CollectionMachine.post(res);
return res;
}
......
......@@ -16,7 +16,7 @@ import java.util.stream.Collectors;
public class CollectionMachine {
private static final Logger logger = LoggerFactory.getLogger(Tmp.class);
// 收集进来的数据 进到存储 相当于一个临时的日志
private static Map<Long, Res> temp = new ConcurrentHashMap<>(124);
private static Map<Long, Res> temp = new ConcurrentHashMap<>(1024);
public static void post(Res<Map<String, String>> log) {
// 应该对于不同的请求统一管理 还是 每个单独管理呢?
......@@ -26,6 +26,7 @@ public class CollectionMachine {
} else {
if (temp.size() > 100) {
logger.info("try to put data");
// 删除一分钟前的key数据
checkSize(1);
}
try {
......
package com.vandyo.sentry.core.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
@Configuration
@ConfigurationProperties(prefix = "checkmeta")
@EnableConfigurationProperties(MapConfig.class)
public class MapConfig {
private Map<String,String> desMap = new HashMap<>();
private Map<String,Integer> timeMap = new HashMap<>();
public Map<String, String> getDesMap() {
return desMap;
}
public void setDesMap(Map<String, String> desMap) {
this.desMap = desMap;
}
public Map<String, Integer> getTimeMap() {
return timeMap;
}
public void setTimeMap(Map<String, Integer> timeMap) {
this.timeMap = timeMap;
}
}
......@@ -29,4 +29,15 @@ public class Res<T> {
* 失败类型
*/
private ErrStatus status;
/**
* 请求接口 (和配置项一样)
*/
private String key;
/**
* 是否忽略请求
*/
private Boolean ignore = false;
}
......@@ -2,4 +2,10 @@ vandyo:
sid: 38201fe198ef43b68f6bcf6101bc2970
uid: 860a776c832749ce86754d59c7ca9fca
mobile: 18623414467
pwd: 5f83f54fb34e2eed0439d37d80f5b1a3
\ No newline at end of file
pwd: 5f83f54fb34e2eed0439d37d80f5b1a3
checkmeta:
desMap:
"[/car/my_car/info]": 车辆信息
timeMap:
"[/car/my_car/info]": 6
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment