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

This commit is contained in:
史精文 2021-03-12 20:45:38 +08:00 committed by GitHub
parent 169640bd08
commit cc60f1529f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 5 deletions

View File

@ -49,6 +49,7 @@ Release Notes.
* 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.
* Merge indices by Metrics Function and Meter Function in Elasticsearch Storage.
* Fix receiver don't need to get itself when healthCheck
#### UI
* Update selector scroller to show in all pages.

View File

@ -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
* 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;
}
}
/**

View File

@ -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.cluster.ClusterModule;
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.command.CommandService;
import org.apache.skywalking.oap.server.core.config.ComponentLibraryCatalogService;
@ -315,6 +316,8 @@ public class CoreModuleProvider extends ModuleProvider {
.registerRemote(gRPCServerInstance);
}
OAPNodeChecker.setROLE(CoreModuleConfig.Role.fromName(moduleConfig.getRole()));
DynamicConfigurationService dynamicConfigurationService = getManager().find(ConfigurationModule.NAME)
.provider()
.getService(

View File

@ -19,6 +19,8 @@
package org.apache.skywalking.oap.server.core.cluster;
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 java.util.List;
@ -28,6 +30,9 @@ import java.util.stream.Collectors;
public class OAPNodeChecker {
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) {
if (CollectionUtils.isEmpty(remoteInstances)) {
return false;
@ -50,10 +55,12 @@ public class OAPNodeChecker {
if (CollectionUtils.isEmpty(remoteInstances)) {
return ClusterHealthStatus.unHealth("can't get the instance list");
}
List<RemoteInstance> selfInstances = remoteInstances.stream().
filter(remoteInstance -> remoteInstance.getAddress().isSelf()).collect(Collectors.toList());
if (CollectionUtils.isEmpty(selfInstances)) {
return ClusterHealthStatus.unHealth("can't get itself");
if (!CoreModuleConfig.Role.Receiver.equals(ROLE)) {
List<RemoteInstance> selfInstances = remoteInstances.stream().
filter(remoteInstance -> remoteInstance.getAddress().isSelf()).collect(Collectors.toList());
if (CollectionUtils.isEmpty(selfInstances)) {
return ClusterHealthStatus.unHealth("can't get itself");
}
}
if (remoteInstances.size() > 1 && hasIllegalNodeAddress(remoteInstances)) {
return ClusterHealthStatus.unHealth("find illegal node in cluster mode such as 127.0.0.1, localhost");

View File

@ -0,0 +1,44 @@
/*
* 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"));
}
}

View File

@ -19,6 +19,7 @@
package org.apache.skywalking.oap.server.core.cluster;
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.junit.Assert;
import org.junit.Test;
@ -102,4 +103,13 @@ public class OAPNodeCheckerTest {
ClusterHealthStatus clusterHealthStatus = OAPNodeChecker.isHealth(remoteInstances);
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());
}
}