feat(运维监控模块): 【微服务网关管理】支持网关限流

调用Sentinel接口获取流控应用列表,获取appType为11(代表为网关)的应用,构建相关跳转参数对象进行返回
This commit is contained in:
OTTO 2025-07-31 09:29:30 +08:00
parent 356b85fd35
commit 02e369849d
5 changed files with 55 additions and 17 deletions

View File

@ -177,6 +177,12 @@ public class MicroManagementController extends BaseController {
return new GenericsTableDataInfo<>(microManagementService.getExceptionHandingRecordList(date));
}
@ApiOperation(value = "获取网关限流跳转参数")
@GetMapping(value = "/gateway/flowLimitingPara")
public GenericsAjaxResult<JSONObject> getGatewayFlowLimitingPara() {
return GenericsAjaxResult.success(microManagementService.getGatewayFlowLimitingPara());
}
@ApiOperation(value = "获取链路追踪应用列表")
@GetMapping(value = "/application/linkTrackingList")
public GenericsTableDataInfo<LinkTrackingApplication> getLinkTrackingList(@RequestParam(value = "applicationName", required = false) @ApiParam(value = "应用名称") String applicationName) {

View File

@ -1,5 +1,6 @@
package com.microservices.mon.k8s.service;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.microservices.mon.k8s.domain.*;
@ -27,4 +28,6 @@ public interface IK8sDashboardService {
List<K8sNamespace> getK8sNamespaceList();
List<MetricCommonData> getMetricCommonDataList(JSONObject metricResJson);
JSONArray getSentinelAppList();
}

View File

@ -55,4 +55,6 @@ public interface IMicroManagementService {
List<String> getExceptionHandingRecordList(String date);
List<LinkTrackingApplication> getLinkTrackingList(String applicationName);
JSONObject getGatewayFlowLimitingPara();
}

View File

@ -32,7 +32,7 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo
@Override
public List<K8sNamespace> getNamespaceDetailList(boolean needPod, String search) {
return monCommonAsyncService.getNamespaceDetailList(needPod,search);
return monCommonAsyncService.getNamespaceDetailList(needPod, search);
}
@Override
@ -264,22 +264,17 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo
break;
case FLOW_CONTROL:
// 处理应用流量控制功能相关逻辑
JSONObject sentinelAppList = remoteGatewayService.getSentinelAppList(SecurityContextHolder.getUserKey());
if (sentinelAppList != null && sentinelAppList.containsKey("success") && sentinelAppList.getBoolean("success")) {
JSONArray sentinelAppListArray = sentinelAppList.getJSONArray("data");
if (sentinelAppListArray != null && !sentinelAppList.getJSONArray("data").isEmpty()) {
for (int i = 0; i < sentinelAppListArray.size(); i++) {
JSONObject sentinelApp = sentinelAppListArray.getJSONObject(i);
if (k8sLabelValue.equals(sentinelApp.getString("app"))) {
applicationFunction = new ApplicationFunction();
applicationFunction.setKeyAndName(applicationFunctionType);
functionVariables = new JSONObject();
functionVariables.put("app", k8sLabelValue);
functionVariables.put("appType", sentinelApp.getLongValue("appType"));
applicationFunction.setVariables(functionVariables);
applicationFunctionsList.add(applicationFunction);
}
}
JSONArray sentinelAppListArray = getSentinelAppList();
for (int i = 0; i < sentinelAppListArray.size(); i++) {
JSONObject sentinelApp = sentinelAppListArray.getJSONObject(i);
if (k8sLabelValue.equals(sentinelApp.getString("app"))) {
applicationFunction = new ApplicationFunction();
applicationFunction.setKeyAndName(applicationFunctionType);
functionVariables = new JSONObject();
functionVariables.put("app", k8sLabelValue);
functionVariables.put("appType", sentinelApp.getLongValue("appType"));
applicationFunction.setVariables(functionVariables);
applicationFunctionsList.add(applicationFunction);
}
}
break;
@ -352,4 +347,16 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo
}
return metricCommonDataList;
}
@Override
public JSONArray getSentinelAppList() {
JSONObject sentinelAppList = remoteGatewayService.getSentinelAppList(SecurityContextHolder.getUserKey());
if (sentinelAppList != null && sentinelAppList.containsKey("success") && sentinelAppList.getBoolean("success")) {
JSONArray sentinelAppListArray = sentinelAppList.getJSONArray("data");
if (sentinelAppListArray != null && !sentinelAppList.getJSONArray("data").isEmpty()) {
return sentinelAppListArray;
}
}
return new JSONArray();
}
}

View File

@ -13,6 +13,7 @@ import com.microservices.common.core.utils.DateUtils;
import com.microservices.common.core.utils.StringUtils;
import com.microservices.mon.k8s.domain.*;
import com.microservices.mon.k8s.domain.vo.*;
import com.microservices.mon.k8s.service.IK8sDashboardService;
import com.microservices.mon.k8s.service.IMicroManagementService;
import com.microservices.mon.k8s.service.IMonCommonAsyncService;
import com.microservices.mon.k8s.utils.RancherResponseHandler;
@ -24,6 +25,7 @@ import com.microservices.system.api.utils.FeignUtils;
import feign.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.Yaml;
@ -41,6 +43,9 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
@Autowired
private IMonCommonAsyncService monCommonAsyncService;
@Autowired
@Lazy
private IK8sDashboardService dashboardService;
@Autowired
private RemoteRancherService remoteRancherService;
@Autowired
private RemoteGatewayService remoteGatewayService;
@ -673,6 +678,21 @@ public class MicroManagementServiceImpl extends CommonService implements IMicroM
return linkTrackingApplicationList;
}
@Override
public JSONObject getGatewayFlowLimitingPara() {
JSONObject gatewayFlowLimitingPara = new JSONObject();
JSONArray sentinelAppListArray = dashboardService.getSentinelAppList();
for (int i = 0; i < sentinelAppListArray.size(); i++) {
JSONObject sentinelApp = sentinelAppListArray.getJSONObject(i);
if (sentinelApp.getLongValue("appType") == 11) {
gatewayFlowLimitingPara.put("app", sentinelApp.getString("app"));
gatewayFlowLimitingPara.put("appType", sentinelApp.getLongValue("appType"));
return gatewayFlowLimitingPara;
}
}
return gatewayFlowLimitingPara;
}
/**
* 根据传入的环境变量列表生成并更新容器对象的 env envFrom 字段
*