未验证 提交 cc60f152 编写于 作者: yunrao's avatar yunrao 提交者: GitHub

resolve "receiver don't need to get itself when healthCheck #6515 " (#6538)

上级 169640bd
...@@ -49,6 +49,7 @@ Release Notes. ...@@ -49,6 +49,7 @@ Release Notes.
* Add telemetry data about metrics in, metrics scraping and trace in metrics to zipkin receiver. * Add telemetry data about metrics in, metrics scraping and trace in metrics to zipkin receiver.
* Fix tags store of log and trace on h2/mysql/pg storage. * Fix tags store of log and trace on h2/mysql/pg storage.
* Merge indices by Metrics Function and Meter Function in Elasticsearch Storage. * Merge indices by Metrics Function and Meter Function in Elasticsearch Storage.
* Fix receiver don't need to get itself when healthCheck
#### UI #### UI
* Update selector scroller to show in all pages. * Update selector scroller to show in all pages.
......
...@@ -157,7 +157,16 @@ public class CoreModuleConfig extends ModuleConfig { ...@@ -157,7 +157,16 @@ public class CoreModuleConfig extends ModuleConfig {
* Aggregator mode OAP receives data from {@link #Mixed} and {@link #Aggregator} OAP nodes, and do 2nd round * Aggregator mode OAP receives data from {@link #Mixed} and {@link #Aggregator} OAP nodes, and do 2nd round
* aggregation. Then save the final result to the storage. * aggregation. Then save the final result to the storage.
*/ */
Aggregator Aggregator;
public static Role fromName(String name) {
for (Role role : Role.values()) {
if (role.name().equalsIgnoreCase(name)) {
return role;
}
}
return Mixed;
}
} }
/** /**
......
...@@ -38,6 +38,7 @@ import org.apache.skywalking.oap.server.core.cache.NetworkAddressAliasCache; ...@@ -38,6 +38,7 @@ import org.apache.skywalking.oap.server.core.cache.NetworkAddressAliasCache;
import org.apache.skywalking.oap.server.core.cache.ProfileTaskCache; import org.apache.skywalking.oap.server.core.cache.ProfileTaskCache;
import org.apache.skywalking.oap.server.core.cluster.ClusterModule; import org.apache.skywalking.oap.server.core.cluster.ClusterModule;
import org.apache.skywalking.oap.server.core.cluster.ClusterRegister; import org.apache.skywalking.oap.server.core.cluster.ClusterRegister;
import org.apache.skywalking.oap.server.core.cluster.OAPNodeChecker;
import org.apache.skywalking.oap.server.core.cluster.RemoteInstance; import org.apache.skywalking.oap.server.core.cluster.RemoteInstance;
import org.apache.skywalking.oap.server.core.command.CommandService; import org.apache.skywalking.oap.server.core.command.CommandService;
import org.apache.skywalking.oap.server.core.config.ComponentLibraryCatalogService; import org.apache.skywalking.oap.server.core.config.ComponentLibraryCatalogService;
...@@ -315,6 +316,8 @@ public class CoreModuleProvider extends ModuleProvider { ...@@ -315,6 +316,8 @@ public class CoreModuleProvider extends ModuleProvider {
.registerRemote(gRPCServerInstance); .registerRemote(gRPCServerInstance);
} }
OAPNodeChecker.setROLE(CoreModuleConfig.Role.fromName(moduleConfig.getRole()));
DynamicConfigurationService dynamicConfigurationService = getManager().find(ConfigurationModule.NAME) DynamicConfigurationService dynamicConfigurationService = getManager().find(ConfigurationModule.NAME)
.provider() .provider()
.getService( .getService(
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.apache.skywalking.oap.server.core.cluster; package org.apache.skywalking.oap.server.core.cluster;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.CoreModuleConfig;
import org.apache.skywalking.oap.server.library.util.CollectionUtils; import org.apache.skywalking.oap.server.library.util.CollectionUtils;
import java.util.List; import java.util.List;
...@@ -28,6 +30,9 @@ import java.util.stream.Collectors; ...@@ -28,6 +30,9 @@ import java.util.stream.Collectors;
public class OAPNodeChecker { public class OAPNodeChecker {
private static final Set<String> ILLEGAL_NODE_ADDRESS_IN_CLUSTER_MODE = Sets.newHashSet("127.0.0.1", "localhost"); private static final Set<String> ILLEGAL_NODE_ADDRESS_IN_CLUSTER_MODE = Sets.newHashSet("127.0.0.1", "localhost");
@Setter
private static CoreModuleConfig.Role ROLE = CoreModuleConfig.Role.Mixed;
public static boolean hasIllegalNodeAddress(List<RemoteInstance> remoteInstances) { public static boolean hasIllegalNodeAddress(List<RemoteInstance> remoteInstances) {
if (CollectionUtils.isEmpty(remoteInstances)) { if (CollectionUtils.isEmpty(remoteInstances)) {
return false; return false;
...@@ -50,10 +55,12 @@ public class OAPNodeChecker { ...@@ -50,10 +55,12 @@ public class OAPNodeChecker {
if (CollectionUtils.isEmpty(remoteInstances)) { if (CollectionUtils.isEmpty(remoteInstances)) {
return ClusterHealthStatus.unHealth("can't get the instance list"); return ClusterHealthStatus.unHealth("can't get the instance list");
} }
List<RemoteInstance> selfInstances = remoteInstances.stream(). if (!CoreModuleConfig.Role.Receiver.equals(ROLE)) {
filter(remoteInstance -> remoteInstance.getAddress().isSelf()).collect(Collectors.toList()); List<RemoteInstance> selfInstances = remoteInstances.stream().
if (CollectionUtils.isEmpty(selfInstances)) { filter(remoteInstance -> remoteInstance.getAddress().isSelf()).collect(Collectors.toList());
return ClusterHealthStatus.unHealth("can't get itself"); if (CollectionUtils.isEmpty(selfInstances)) {
return ClusterHealthStatus.unHealth("can't get itself");
}
} }
if (remoteInstances.size() > 1 && hasIllegalNodeAddress(remoteInstances)) { if (remoteInstances.size() > 1 && hasIllegalNodeAddress(remoteInstances)) {
return ClusterHealthStatus.unHealth("find illegal node in cluster mode such as 127.0.0.1, localhost"); return ClusterHealthStatus.unHealth("find illegal node in cluster mode such as 127.0.0.1, localhost");
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import org.junit.Test;
public class CoreModuleConfigTest {
@Test
public void testRoleFromNameNormalSituation() {
Assert.assertEquals(CoreModuleConfig.Role.Mixed, CoreModuleConfig.Role.fromName("Mixed"));
Assert.assertEquals(CoreModuleConfig.Role.Receiver, CoreModuleConfig.Role.fromName("Receiver"));
Assert.assertEquals(CoreModuleConfig.Role.Aggregator, CoreModuleConfig.Role.fromName("Aggregator"));
}
@Test
public void testRoleFromNameBlockParameter() {
Assert.assertEquals(CoreModuleConfig.Role.Mixed, CoreModuleConfig.Role.fromName(StringUtils.EMPTY));
Assert.assertEquals(CoreModuleConfig.Role.Mixed, CoreModuleConfig.Role.fromName(null));
}
@Test
public void testRoleFromNameNotIncludeRole() {
Assert.assertEquals(CoreModuleConfig.Role.Mixed, CoreModuleConfig.Role.fromName("a"));
}
}
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.skywalking.oap.server.core.cluster; package org.apache.skywalking.oap.server.core.cluster;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.skywalking.oap.server.core.CoreModuleConfig;
import org.apache.skywalking.oap.server.core.remote.client.Address; import org.apache.skywalking.oap.server.core.remote.client.Address;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
...@@ -102,4 +103,13 @@ public class OAPNodeCheckerTest { ...@@ -102,4 +103,13 @@ public class OAPNodeCheckerTest {
ClusterHealthStatus clusterHealthStatus = OAPNodeChecker.isHealth(remoteInstances); ClusterHealthStatus clusterHealthStatus = OAPNodeChecker.isHealth(remoteInstances);
Assert.assertTrue(clusterHealthStatus.isHealth()); Assert.assertTrue(clusterHealthStatus.isHealth());
} }
@Test
public void healthWhenReceiverRoleWithEmptySelfInstance() {
List<RemoteInstance> remoteInstances = new ArrayList<>();
remoteInstances.add(new RemoteInstance(new Address("192.168.0.1", 8892, false)));
OAPNodeChecker.setROLE(CoreModuleConfig.Role.Receiver);
ClusterHealthStatus clusterHealthStatus = OAPNodeChecker.isHealth(remoteInstances);
Assert.assertTrue(clusterHealthStatus.isHealth());
}
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册