Merge pull request '【微服务编排】增加一个搜索功能,支持根据名称和标识进行搜索' (#976) from otto/microservices:dev_monitoring into dev_monitoring

This commit is contained in:
otto 2025-07-31 09:03:10 +08:00
commit 19a32e2f7c
6 changed files with 15 additions and 11 deletions

View File

@ -24,8 +24,8 @@ public class DashboardController extends BaseController {
*/
@ApiOperation(value = "获取命名空间列表")
@GetMapping("/namespace/list")
public GenericsTableDataInfo<K8sNamespace> namespaceList() {
return new GenericsTableDataInfo<>(k8sDashboardService.getNamespaceDetailList(true));
public GenericsTableDataInfo<K8sNamespace> namespaceList(@RequestParam(value = "search", required = false) @ApiParam(value = "根据应用名称查找") String search) {
return new GenericsTableDataInfo<>(k8sDashboardService.getNamespaceDetailList(true,search));
}
@ApiOperation(value = "获取集群节点列表")

View File

@ -79,7 +79,7 @@ public class K8sApplicationAndPodState {
} else if ("registryUnavailable".equalsIgnoreCase(name)) {
this.alias = "连接不到镜像中心";
} else if ("errImagePull".equalsIgnoreCase(name)) {
this.alias = "通用的拉取镜像出错";
this.alias = "拉取镜像出错";
} else if ("createContainerConfigError".equalsIgnoreCase(name)) {
this.alias = "不能创建容器配置";
} else if ("createContainerError".equalsIgnoreCase(name)) {

View File

@ -6,7 +6,7 @@ import com.microservices.mon.k8s.domain.*;
import java.util.List;
public interface IK8sDashboardService {
List<K8sNamespace> getNamespaceDetailList(boolean needPod);
List<K8sNamespace> getNamespaceDetailList(boolean needPod, String search);
List<K8sClusterNode> getClusterNodeList();

View File

@ -14,7 +14,7 @@ public interface IMonCommonAsyncService {
K8sClusterStatus getClusterStatus(String query);
List<K8sNamespace> getNamespaceDetailList(boolean needPod);
List<K8sNamespace> getNamespaceDetailList(boolean needPod, String search);
List<K8sApplicationPod> getPodList();

View File

@ -31,8 +31,8 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo
private RemoteGatewayService remoteGatewayService;
@Override
public List<K8sNamespace> getNamespaceDetailList(boolean needPod) {
return monCommonAsyncService.getNamespaceDetailList(needPod);
public List<K8sNamespace> getNamespaceDetailList(boolean needPod, String search) {
return monCommonAsyncService.getNamespaceDetailList(needPod,search);
}
@Override

View File

@ -105,7 +105,7 @@ public class MonCommonAsyncServiceImpl extends CommonService implements IMonComm
});
CustomExecutorFactory.threadPoolExecutor.execute(() -> {
try {
List<K8sNamespace> k8sNamespaceList = k8sDashboardService.getNamespaceDetailList(false);
List<K8sNamespace> k8sNamespaceList = k8sDashboardService.getNamespaceDetailList(false, null);
k8sClusterStatus.setMicroserviceApplicationCount(k8sNamespaceList);
List<String> namespaceNameList = k8sNamespaceList.stream().map(K8sNamespace::getName).collect(Collectors.toList());
JSONObject microserviceRestartCountTodayJson = remoteGatewayService.getPrometheusQueryRes(PromQLConstant.MICROSERVICE_RESTART_COUNT_TODAY(cluster_id, namespaceNameList), SecurityContextHolder.getUserKey());
@ -127,7 +127,7 @@ public class MonCommonAsyncServiceImpl extends CommonService implements IMonComm
}
@Override
public List<K8sNamespace> getNamespaceDetailList(boolean needPod) {
public List<K8sNamespace> getNamespaceDetailList(boolean needPod, String search) {
List<RancherApplicationVo> rancherApplicationVoList = new ArrayList<>();
List<K8sNamespace> k8sNamespaceList = new ArrayList<>();
CountDownLatch applicationCountDownLatch = new CountDownLatch(4);
@ -181,7 +181,11 @@ public class MonCommonAsyncServiceImpl extends CommonService implements IMonComm
// 将rancher对象转换为k8s对象
List<K8sApplication> k8sApplicationList = rancherApplicationVoList.stream().map(RancherApplicationVo::toK8sApplication).collect(Collectors.toList());
List<K8sApplication> k8sApplicationList = rancherApplicationVoList
.stream()
.map(RancherApplicationVo::toK8sApplication)
.filter(x -> StringUtils.isEmpty(search) || x.getName().contains(search))
.collect(Collectors.toList());
CountDownLatch podCountDownLatch = new CountDownLatch(k8sNamespaceList.size());
for (int i = 0; i < k8sNamespaceList.size(); i++) {
@ -233,7 +237,7 @@ public class MonCommonAsyncServiceImpl extends CommonService implements IMonComm
throw new ServiceException("K8S应用对象数据转换失败");
}
k8sNamespaceList.sort(Comparator.comparing(K8sNamespace::getName));
return k8sNamespaceList;
return k8sNamespaceList.stream().filter(x -> !x.getApplicationList().isEmpty()).collect(Collectors.toList());
}
@Override