Skip to content

Commit

Permalink
修复proxy一个npe bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yifuzhou committed Dec 27, 2023
1 parent 2eaca33 commit 8406f59
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ public class CheckerHealthController {
@Autowired
private StabilityHolder siteStability;

@Autowired
private KeeperContainerInfoReporter keeperContainerInfoReporter;

@RequestMapping(value = "/reportKeeperContainerInfo", method = RequestMethod.GET)
public void reportKeeperContainerInfo() {
keeperContainerInfoReporter.reportKeeperContainerInfo();
}

@RequestMapping(value = "/health/{ip}/{port}", method = RequestMethod.GET)
public HEALTH_STATE getHealthState(@PathVariable String ip, @PathVariable int port) {
if (siteStability.isSiteStable()) return defaultDelayPingActionCollector.getState(new HostPort(ip, port));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.ctrip.xpipe.redis.checker.healthcheck.HealthCheckAction;
import com.ctrip.xpipe.redis.checker.healthcheck.KeeperInstanceInfo;
import com.ctrip.xpipe.redis.checker.healthcheck.KeeperSupport;
import com.ctrip.xpipe.redis.checker.model.DcClusterShard;
import com.ctrip.xpipe.redis.checker.model.DcClusterShardActive;
import com.ctrip.xpipe.redis.core.protocal.cmd.InfoResultExtractor;
import com.ctrip.xpipe.utils.MapUtils;
Expand All @@ -29,7 +28,7 @@ public void onAction(KeeperInfoStatsActionContext context) {
KeeperInstanceInfo info = context.instance().getCheckInfo();
long keeperFlow = extractor.getKeeperInstantaneousInputKbps().longValue();
Map<DcClusterShardActive, Long> keeperContainerResult = MapUtils.getOrCreate(hostPort2InputFlow, info.getHostPort().getHost(), ConcurrentHashMap::new);
keeperContainerResult.put(new DcClusterShardActive(info.getDcId(), info.getClusterId(), info.getShardId(), extractor.getKeeperRole(), info.getHostPort().getPort()), keeperFlow);
keeperContainerResult.put(new DcClusterShardActive(info.getDcId(), info.getClusterId(), info.getShardId(), extractor.getKeeperActive(), info.getHostPort().getPort()), keeperFlow);
} catch (Throwable throwable) {
logger.error("get instantaneous input kbps of keeper:{} error: ", context.instance().getCheckInfo().getHostPort(), throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public void reportKeeperContainerInfo() {
.setDiskUsed(keeperDiskInfo.spaceUsageInfo.use);
} catch (RestClientException e){
logger.error("[reportKeeperContainerInfo] getKeeperDiskInfo error, keeperIp: {}", keeperIp);
} catch (Throwable e) {
logger.error("[reportKeeperContainerInfo] getKeeperDiskInfo error", e);
}
model.setDetailInfo(detailInfo)
.setActiveKeeperCount(activeKeeperCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public int hashCode() {

@Override
public String toString() {
return getDcId() + SPLITTER + getClusterId() + SPLITTER + getShardId() + SPLITTER + isActive() + SPLITTER + getPort();
return new StringBuilder().append(getDcId()).append(SPLITTER).append(getClusterId()).append(SPLITTER).append(getShardId()).append(SPLITTER).append(isActive()).append(SPLITTER).append(getPort()).toString();

Check warning on line 70 in redis/redis-checker/src/main/java/com/ctrip/xpipe/redis/checker/model/DcClusterShardActive.java

View check run for this annotation

Codecov / codecov/patch

redis/redis-checker/src/main/java/com/ctrip/xpipe/redis/checker/model/DcClusterShardActive.java#L70

Added line #L70 was not covered by tests
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Map<String, KeeperContainerOverloadStandardModel> analyzeKeeperContainerStandard
KeeperContainerOverloadStandardModel keeperContainerOverloadStandard = config.getKeeperContainerOverloadStandards().get(currentDc);
double loadFactor = config.getKeeperContainerOverloadFactor();
KeeperContainerOverloadStandardModel defaultOverloadStandard = getDefaultStandard(keeperContainerOverloadStandard, loadFactor);
logger.debug("[analyzeKeeperContainerUsedInfo] keeperContainerDefaultOverloadStandard: {}", defaultOverloadStandard);
logger.info("[analyzeKeeperContainerUsedInfo] keeperContainerDefaultOverloadStandard: {}", defaultOverloadStandard);
for (KeeperContainerUsedInfoModel keeperContainerUsedInfoModel : allKeeperContainerUsedInfoModelsList) {
KeeperContainerOverloadStandardModel realKeeperContainerOverloadStandard = getRealStandard(keeperContainerOverloadStandard, defaultOverloadStandard, keeperContainerUsedInfoModel, loadFactor);
keeperContainerUsedInfoModel.setInputFlowStandard(realKeeperContainerOverloadStandard.getFlowOverload());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9193,7 +9193,7 @@ eval("angular\n .module('index')\n .controller('KeepercontainerOverloadCtl
\***********************************************************/
/***/ (() => {

eval("angular\n .module('index')\n .controller('KeepercontainerUsedInfoCtl', KeepercontainerUsedInfoCtl);\nfunction KeepercontainerUsedInfoCtl($rootScope, $scope, $window, $stateParams, KeeperContainerService, toastr, NgTableParams, $interval) {\n $scope.originData = [];\n $scope.tableParams = new NgTableParams({}, {});\n KeeperContainerService.getAllKeepercontainerUsedInfo().then(function (response) {\n console.log(response);\n if (Array.isArray(response)) {\n $scope.originData = response;\n KeeperContainerService.getAllInfos().then(function (anotherResponse) {\n if (Array.isArray(anotherResponse)) {\n Promise.all([response, anotherResponse]).then(function (responses) {\n var originData = responses[0];\n var anotherData = responses[1];\n originData.forEach(function (row) {\n var matchingData = anotherData.find(function (d) {\n return d.addr.host === row.keeperIp;\n });\n if (matchingData) {\n Object.assign(row, matchingData);\n }\n });\n });\n }\n });\n $scope.tableParams = new NgTableParams({\n page: 1,\n count: 10,\n }, {\n filterDelay: 100,\n counts: [10, 25, 50],\n dataset: $scope.originData\n });\n }\n KeeperContainerService.getKeepercontainerFullSynchronizationTime().then(function (response) {\n $scope.fullSynchronizationTime = response.message;\n });\n });\n $scope.getKeepercontainerFullSynchronizationTime = function () {\n return $scope.fullSynchronizationTime;\n };\n}\n\n\n//# sourceURL=webpack://XPipe-Console/./scripts/controllers/KeepercontainerUsedInfoCtl.ts?");
eval("angular\n .module('index')\n .controller('KeepercontainerUsedInfoCtl', KeepercontainerUsedInfoCtl);\nfunction KeepercontainerUsedInfoCtl($rootScope, $scope, $window, $stateParams, KeeperContainerService, toastr, NgTableParams, $interval) {\n $scope.originData = [];\n $scope.tableParams = new NgTableParams({}, {});\n KeeperContainerService.getAllKeepercontainerUsedInfo().then(function (response) {\n console.log(response);\n if (Array.isArray(response)) {\n $scope.originData = response;\n KeeperContainerService.getAllInfos().then(function (anotherResponse) {\n if (Array.isArray(anotherResponse)) {\n Promise.all([response, anotherResponse]).then(function (responses) {\n var originData = responses[0];\n var anotherData = responses[1];\n originData.forEach(function (row) {\n var matchingData = anotherData.find(function (d) {\n return d.addr.host === row.keeperIp;\n });\n if (matchingData) {\n Object.assign(row, matchingData);\n }\n row.activeRedisUsedMemoryPercentage = $scope.getActivePercentage(row.activeRedisUsedMemory, row.totalRedisUsedMemory) * 100;\n row.activeRedisUsedMemoryStandardPercentage = $scope.getActivePercentage(row.activeRedisUsedMemory, row.redisUsedMemoryStandard) * 100;\n row.activeInputFlowPercentage = $scope.getActivePercentage(row.activeInputFlow, row.totalInputFlow) * 100;\n row.activeInputFlowStandardPercentage = $scope.getActivePercentage(row.activeInputFlow, row.inputFlowStandard) * 100;\n });\n });\n }\n });\n $scope.tableParams = new NgTableParams({\n page: 1,\n count: 10,\n }, {\n filterDelay: 100,\n counts: [10, 25, 50],\n dataset: $scope.originData\n });\n }\n KeeperContainerService.getKeepercontainerFullSynchronizationTime().then(function (response) {\n $scope.fullSynchronizationTime = response.message;\n });\n });\n $scope.getKeepercontainerFullSynchronizationTime = function () {\n return $scope.fullSynchronizationTime;\n };\n $scope.getActivePercentage = function (active, total) {\n if (total === 0) {\n return 0;\n }\n return active / total;\n };\n}\n\n\n//# sourceURL=webpack://XPipe-Console/./scripts/controllers/KeepercontainerUsedInfoCtl.ts?");

/***/ }),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ function KeepercontainerUsedInfoCtl($rootScope, $scope, $window, $stateParams, K
if (matchingData) {
Object.assign(row, matchingData);
}
row.activeRedisUsedMemoryPercentage = $scope.getActivePercentage(row.activeRedisUsedMemory, row.totalRedisUsedMemory)*100;
row.activeRedisUsedMemoryStandardPercentage = $scope.getActivePercentage(row.activeRedisUsedMemory, row.redisUsedMemoryStandard)*100;
row.activeInputFlowPercentage = $scope.getActivePercentage(row.activeInputFlow, row.totalInputFlow)*100;
row.activeInputFlowStandardPercentage = $scope.getActivePercentage(row.activeInputFlow, row.inputFlowStandard)*100;
});
});
}
Expand All @@ -47,4 +51,11 @@ function KeepercontainerUsedInfoCtl($rootScope, $scope, $window, $stateParams, K
return $scope.fullSynchronizationTime;
}

$scope.getActivePercentage = function (active, total) {
if (total === 0) {
return 0;
}
return active/total;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<td data-title="'az'" filter="{ azName: 'text'}" sortable="'azName'">{{info.azName}}</td>
<td data-title="'active数据量(MB)'" sortable="'activeRedisUsedMemory'">{{info.activeRedisUsedMemory/1024/1024 | number:2}}</td>
<td data-title="'backUp数据量(MB)'" sortable="'totalRedisUsedMemory-activeRedisUsedMemory'">{{(info.totalRedisUsedMemory-info.activeRedisUsedMemory)/1024/1024 | number:2}}</td>
<td data-title="'active数据量使用占比(%)'" sortable="'info.activeRedisUsedMemory/info.totalRedisUsedMemory'">{{info.activeRedisUsedMemory/info.totalRedisUsedMemory*100 | number:2}}%</td>
<td data-title="'active数据量标准占比(%)'" sortable="'info.activeRedisUsedMemory/info.redisUsedMemoryStandard'">{{info.activeRedisUsedMemory/info.redisUsedMemoryStandard*100 | number:2}}%</td>
<td data-title="'active数据量使用占比(%)'" sortable="'activeRedisUsedMemoryPercentage'">{{info.activeRedisUsedMemoryPercentage | number:2}}%</td>
<td data-title="'active数据量标准占比(%)'" sortable="'activeRedisUsedMemoryStandardPercentage'">{{info.activeRedisUsedMemoryStandardPercentage | number:2}}%</td>
<td data-title="'active流量(MB/S)'" sortable="'activeInputFlow'">{{info.activeInputFlow/1024/8 | number:2}}</td>
<td data-title="'backUp流量(MB/S)'" sortable="'totalInputFlow-activeInputFlow'">{{(info.totalInputFlow-info.activeInputFlow)/1024/8 | number:2}}</td>
<td data-title="'active流量使用占比(%)'" sortable="'activeInputFlow/totalInputFlow'">{{info.activeInputFlow/info.totalInputFlow*100 | number:2}}%</td>
<td data-title="'active流量标准占比(%)'" sortable="'activeInputFlow/inputFlowStandard'">{{info.activeInputFlow/info.inputFlowStandard*100 | number:2}}%</td>
<td data-title="'active流量使用占比(%)'" sortable="'activeInputFlowPercentage'">{{info.activeInputFlowPercentage | number:2}}%</td>
<td data-title="'active流量标准占比(%)'" sortable="'activeInputFlowStandardPercentage'">{{info.activeInputFlowStandardPercentage | number:2}}%</td>
<td data-title="'active实例数'" sortable="'activeKeeperCount'">{{info.activeKeeperCount}}</td>
<td data-title="'backUp实例数'" sortable="'totalKeeperCount-activeKeeperCount'">{{info.totalKeeperCount-info.activeKeeperCount}}</td>
<td data-title="'操作'" >
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.ctrip.xpipe.redis.core.protocal.cmd;

import com.ctrip.xpipe.utils.VisibleForTesting;
import com.google.common.base.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,7 +26,7 @@ public class InfoResultExtractor {
private static final String KEY_SWAP_USED_DB_SIZE = "swap_used_db_size";
private static final String KEY_USED_MEMORY ="used_memory";
private static final String KEY_MAX_MEMORY ="maxmemory";
private static final String KEY_KEEPER_ROLE = "state";
private static final String KEY_KEEPER_ACTIVE = "state";

protected static Logger logger = LoggerFactory.getLogger(InfoResultExtractor.class);

Expand Down Expand Up @@ -121,7 +120,7 @@ public long getSyncPartialErr() {

public Long getSwapUsedDbSize() { return extractAsLong(KEY_SWAP_USED_DB_SIZE);}

public boolean getKeeperRole() { return "ACTIVE".equals(extract(KEY_KEEPER_ROLE)); }
public boolean getKeeperActive() { return "ACTIVE".equals(extract(KEY_KEEPER_ACTIVE)); }

Check warning on line 123 in redis/redis-core/src/main/java/com/ctrip/xpipe/redis/core/protocal/cmd/InfoResultExtractor.java

View check run for this annotation

Codecov / codecov/patch

redis/redis-core/src/main/java/com/ctrip/xpipe/redis/core/protocal/cmd/InfoResultExtractor.java#L123

Added line #L123 was not covered by tests

public long getMasterReplOffset() {
Long result = extractAsLong(KEY_MASTER_REPL_OFFSET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ protected void doClean() {
if (!channel.isActive()) {
Tunnel tunnel = cache.remove(channel);
try {
tunnel.release();
if (tunnel != null) {
tunnel.release();

Check warning on line 91 in redis/redis-proxy/src/main/java/com/ctrip/xpipe/redis/proxy/tunnel/DefaultTunnelManager.java

View check run for this annotation

Codecov / codecov/patch

redis/redis-proxy/src/main/java/com/ctrip/xpipe/redis/proxy/tunnel/DefaultTunnelManager.java#L91

Added line #L91 was not covered by tests
}
} catch (Exception e) {
logger.error("[cleaner] tunnel release tunnel{} error", tunnel, e);
}
Expand Down

0 comments on commit 8406f59

Please sign in to comment.