Skip to content

Commit

Permalink
fix bug for beacon checker
Browse files Browse the repository at this point in the history
  • Loading branch information
qifanwang committed Dec 3, 2024
1 parent 61194bb commit a086b53
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.ctrip.xpipe.redis.core.config.ConsoleCommonConfig;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.Set;

import static com.ctrip.xpipe.api.config.ConfigProvider.COMMON_CONFIG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,21 @@ private void doJob() {
Set<String> inconsistencyClusters = new HashSet<>();
Set<String> notfoundCluster = new HashSet<>();

Set<String> supportDcs = getSupportDcs();

Map<String, DcMeta> dcs = metaCache.getXpipeMeta().getDcs();
Set<String> supportZones = config.getBeaconSupportZones();
for (DcMeta dcMeta : dcs.values()) {
if(!supportZones.isEmpty() && supportZones.stream().noneMatch(zone -> StringUtil.trimEquals(dcMeta.getZone(), zone, true))) {
if(!supportDcs.contains(dcMeta.getId().toUpperCase())) {
continue;
}
Map<String, ClusterMeta> clusterMetaMap = dcMeta.getClusters();
for (ClusterMeta cluster : clusterMetaMap.values()) {
String clusterName = cluster.getId();
String activeDc = cluster.getActiveDc();
if(StringUtil.trimEquals(ClusterType.ONE_WAY.toString(), cluster.getType(), true)) {
if(!StringUtil.trimEquals(dcMeta.getId(), activeDc, true)) {
continue;
}
String dc = cluster.getActiveDc().toUpperCase();
if(!allClusters.containsKey(clusterName)) {
notfoundCluster.add(clusterName);
Expand All @@ -87,6 +92,7 @@ private void doJob() {
Set<String> beaconDcSet = getBeaconClusterDcSet(allClusters, clusterName);
Set<String> loaclDcSet = Arrays.stream(cluster.getDcs().split(","))
.map(String::toUpperCase)
.filter(dc -> supportDcs.contains(dc))
.collect(Collectors.toSet());
if(!beaconDcSet.equals(loaclDcSet)) {
inconsistencyClusters.add(clusterName);
Expand All @@ -105,6 +111,10 @@ private void doJob() {
MetricData metricData = getMetricData(clusterName, "NOTFOUND");
sendMetricData(metricData);
}
if(inconsistencyClusters.isEmpty() && notfoundCluster.isEmpty()) {
MetricData metricData = getMetricData("", "CONSISTENT");
sendMetricData(metricData);
}

}

Expand Down Expand Up @@ -132,6 +142,18 @@ private void sendMetricData(MetricData metricData) {
}
}

private Set<String> getSupportDcs() {
Set<String> dcs = metaCache.getXpipeMeta().getDcs().keySet();
Set<String> supportZones = config.getBeaconSupportZones();
Set<String> supportDcs = new HashSet<>();
for(String dc : dcs) {
if(supportZones.stream().anyMatch(zone -> metaCache.isDcInRegion(dc, zone))) {
supportDcs.add(dc.toUpperCase());
}
}
return supportDcs;
}

@Override
protected void doReset() {

Expand Down

0 comments on commit a086b53

Please sign in to comment.