Skip to content

Commit

Permalink
feat: log manager create tail valid and agent handle .* monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
wtt40122 committed Aug 2, 2023
1 parent 5ca944b commit 4d4f778
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ private List<String> newMonitorDirectories(List<MonitorFile> monitorPathList) {
/**
* 已经是最干净的目录了,只会有1个
*/
newMonitorDirectories.add(watchDList.get(0));
String monitorDirectory = watchDList.get(0);
if (monitorDirectory.contains(".*")) {
monitorDirectory = StringUtils.substringBefore(monitorDirectory, ".*");
}
if (pathList.stream().noneMatch(monitorDirectory::startsWith)) {
newMonitorDirectories.add(monitorDirectory);
}
}
}
newMonitorDirectories = newMonitorDirectories.stream().distinct().collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
import com.xiaomi.mone.log.manager.model.bo.MlogParseParam;
import com.xiaomi.mone.log.manager.model.pojo.MilogLogStoreDO;
import com.xiaomi.mone.log.manager.model.pojo.MilogLogTailDo;
import com.xiaomi.mone.log.manager.service.extension.agent.MilogAgentService;
import com.xiaomi.mone.log.manager.service.extension.agent.MilogAgentServiceFactory;
import com.xiaomi.mone.log.manager.service.extension.resource.ResourceExtensionService;
import com.xiaomi.mone.log.manager.service.extension.resource.ResourceExtensionServiceFactory;
import com.xiaomi.mone.log.manager.service.extension.store.StoreExtensionService;
import com.xiaomi.mone.log.manager.service.extension.store.StoreExtensionServiceFactory;
import com.xiaomi.mone.log.manager.service.extension.tail.TailExtensionService;
import com.xiaomi.mone.log.manager.service.extension.tail.TailExtensionServiceFactory;
import com.xiaomi.mone.log.parse.LogParserFactory;
import com.xiaomi.youpin.docean.anno.Component;
import com.xiaomi.youpin.docean.plugin.config.anno.Value;
Expand All @@ -47,6 +55,21 @@ public class HeraConfigValid {
@Resource
private MilogLogTailDao milogLogtailDao;

private TailExtensionService tailExtensionService;

private MilogAgentService milogAgentService;

private StoreExtensionService storeExtensionService;

private ResourceExtensionService resourceExtensionService;

public void init() {
tailExtensionService = TailExtensionServiceFactory.getTailExtensionService();
milogAgentService = MilogAgentServiceFactory.getAgentExtensionService();
storeExtensionService = StoreExtensionServiceFactory.getStoreExtensionService();
resourceExtensionService = ResourceExtensionServiceFactory.getResourceExtensionService();
}

public String verifyLogTailParam(LogTailParam param) {
if (null == param.getMilogAppId()) {
return "选择的应用不能为空";
Expand All @@ -69,16 +92,8 @@ public String verifyLogTailParam(LogTailParam param) {
if (path.equals("/home/work/log/") || path.equals("/home/work/log") || path.startsWith("/home/work/log") && path.split("/").length < 4) {
return "日志路径错误,请确认后提交";
}
if (Objects.equals(ProjectTypeEnum.MIONE_TYPE.getCode(), param.getAppType())) {
// 校验同名日志文件
List<MilogLogTailDo> appLogTails = milogLogtailDao.queryByMilogAppAndEnv(param.getMilogAppId(), param.getEnvId());
for (int i = 0; i < appLogTails.size() && null == param.getId(); i++) {
if (appLogTails.get(i).getLogPath().equals(param.getLogPath())) {
return "当前部署环境该文件" + param.getLogPath() + "已配置日志采集,别名为:" + appLogTails.get(i).getTail();
}
}
}
return "";
String validMsg = tailExtensionService.validLogPath(param);
return StringUtils.isNotEmpty(validMsg) ? validMsg : StringUtils.EMPTY;
}

public String checkParseParam(MlogParseParam mlogParseParam) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.xiaomi.mone.app.api.response.AppBaseInfo;
import com.xiaomi.mone.log.api.enums.OperateEnum;
import com.xiaomi.mone.log.api.enums.ProjectTypeEnum;
import com.xiaomi.mone.log.manager.dao.MilogLogTailDao;
import com.xiaomi.mone.log.manager.model.bo.LogTailParam;
import com.xiaomi.mone.log.manager.model.dto.MilogAppEnvDTO;
import com.xiaomi.mone.log.manager.model.pojo.MilogLogStoreDO;
Expand Down Expand Up @@ -66,6 +67,9 @@ public class DefaultTailExtensionService implements TailExtensionService {
@Resource(name = DEFAULT_AGENT_EXTENSION_SERVICE_KEY)
private MilogAgentServiceImpl milogAgentService;

@Resource
private MilogLogTailDao milogLogtailDao;

@Override
public boolean tailHandlePreprocessingSwitch(MilogLogStoreDO milogLogStore, LogTailParam param) {
return true;
Expand Down Expand Up @@ -171,4 +175,18 @@ public String deleteCheckProcessPre(Long id) {
return StringUtils.EMPTY;
}

@Override
public String validLogPath(LogTailParam param) {
if (Objects.equals(ProjectTypeEnum.MIONE_TYPE.getCode(), param.getAppType())) {
// 校验同名日志文件
List<MilogLogTailDo> appLogTails = milogLogtailDao.queryByMilogAppAndEnv(param.getMilogAppId(), param.getEnvId());
for (int i = 0; i < appLogTails.size() && null == param.getId(); i++) {
if (appLogTails.get(i).getLogPath().equals(param.getLogPath())) {
return "当前部署环境该文件" + param.getLogPath() + "已配置日志采集,别名为:" + appLogTails.get(i).getTail();
}
}
}
return StringUtils.EMPTY;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ public interface TailExtensionService {
List<String> getStreamMachineUniqueList(Integer projectTypeCode, String motorRoomEn);

String deleteCheckProcessPre(Long id);

String validLogPath(LogTailParam param);
}

0 comments on commit 4d4f778

Please sign in to comment.