[GitHub] [skywalking] xbkaishui commented on a change in pull request #5661: Add health checker for cluster management module

2020-11-03 Thread GitBox


xbkaishui commented on a change in pull request #5661:
URL: https://github.com/apache/skywalking/pull/5661#discussion_r516613613



##
File path: 
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/OAPNodeChecker.java
##
@@ -0,0 +1,63 @@
+/*
+ * 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.cluster;
+
+import com.google.common.collect.Sets;
+import org.apache.skywalking.oap.server.library.util.CollectionUtils;
+
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class OAPNodeChecker {
+private static final Set ILLEGAL_NODE_ADDRESS_IN_CLUSTER_MODE = 
Sets.newHashSet("127.0.0.1", "localhost");
+
+public static boolean hasIllegalNodeAddress(List 
remoteInstances) {
+if (CollectionUtils.isEmpty(remoteInstances)) {
+return false;
+}
+Set remoteAddressSet = 
remoteInstances.stream().map(remoteInstance ->
+
remoteInstance.getAddress().getHost()).collect(Collectors.toSet());
+return !Sets.intersection(ILLEGAL_NODE_ADDRESS_IN_CLUSTER_MODE, 
remoteAddressSet).isEmpty();
+}
+
+/**
+ * Check the remote instance healthiness, set health to false for bellow 
conditions:
+ * 1.can't get the instance list
+ * 2.can't get itself
+ * 3.check for illegal node in cluster mode such as 127.0.0.1, localhost
+ *
+ * @param remoteInstances all the remote instances from cluster
+ * @return true health false unHealth
+ */
+public static boolean isHealth(List remoteInstances) {

Review comment:
   done, please help to check 





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] xbkaishui commented on a change in pull request #5661: Add health checker for cluster management module

2020-10-19 Thread GitBox


xbkaishui commented on a change in pull request #5661:
URL: https://github.com/apache/skywalking/pull/5661#discussion_r508149094



##
File path: 
oap-server/server-cluster-plugin/cluster-etcd-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/etcd/EtcdCoordinator.java
##
@@ -51,6 +59,9 @@
 
 private static final Integer KEY_TTL = 45;
 
+@Setter
+private HealthCheckMetrics healthChecker;

Review comment:
   done





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] xbkaishui commented on a change in pull request #5661: Add health checker for cluster management module

2020-10-19 Thread GitBox


xbkaishui commented on a change in pull request #5661:
URL: https://github.com/apache/skywalking/pull/5661#discussion_r508148908



##
File path: 
oap-server/server-cluster-plugin/cluster-etcd-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/etcd/EtcdCoordinator.java
##
@@ -73,15 +83,30 @@ public EtcdCoordinator(ClusterModuleEtcdConfig config, 
EtcdClient client) {
 if (!address.equals(selfAddress)) {
 address.setSelf(false);
 }
-res.add(new RemoteInstance(address));
+remoteInstances.add(new RemoteInstance(address));
 });
 }
-
-} catch (Exception e) {
+if (remoteInstances.size() > 1) {
+Set remoteAddressSet = 
remoteInstances.stream().map(remoteInstance ->
+
remoteInstance.getAddress().getHost()).collect(Collectors.toSet());
+boolean hasUnHealthAddress = 
OAPNodeChecker.hasUnHealthAddress(remoteAddressSet);
+if (hasUnHealthAddress) {
+this.healthChecker.unHealth(new 
ServiceQueryException("found 127.0.0.1 or localhost in cluster mode"));
+} else {
+List selfInstances = 
remoteInstances.stream().
+filter(remoteInstance -> 
remoteInstance.getAddress().isSelf()).collect(Collectors.toList());
+if (CollectionUtils.isNotEmpty(selfInstances) && 
selfInstances.size() == 1) {

Review comment:
   Yes, changed 





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] xbkaishui commented on a change in pull request #5661: Add health checker for cluster management module

2020-10-19 Thread GitBox


xbkaishui commented on a change in pull request #5661:
URL: https://github.com/apache/skywalking/pull/5661#discussion_r508149027



##
File path: 
oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/cluster/OAPNodeCheckerTest.java
##
@@ -0,0 +1,58 @@
+/*
+ * 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.cluster;
+
+import com.google.common.collect.Sets;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Set;
+
+import static org.hamcrest.CoreMatchers.is;
+
+public class OAPNodeCheckerTest {
+
+@Test
+public void hasUnHealthAddressFalse() {
+Set address = Sets.newHashSet("123.23.4.2");
+boolean flag = OAPNodeChecker.hasUnHealthAddress(address);
+Assert.assertThat(flag, is(false));

Review comment:
   done





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] xbkaishui commented on a change in pull request #5661: Add health checker for cluster management module

2020-10-19 Thread GitBox


xbkaishui commented on a change in pull request #5661:
URL: https://github.com/apache/skywalking/pull/5661#discussion_r507736678



##
File path: 
oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/HealthCheckUtil.java
##
@@ -0,0 +1,34 @@
+/*
+ * 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.library.util;
+
+import com.google.common.collect.Sets;
+
+import java.util.Set;
+
+public class HealthCheckUtil {

Review comment:
   done





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] xbkaishui commented on a change in pull request #5661: Add health checker for cluster management module

2020-10-19 Thread GitBox


xbkaishui commented on a change in pull request #5661:
URL: https://github.com/apache/skywalking/pull/5661#discussion_r507736757



##
File path: 
oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/HealthCheckUtil.java
##
@@ -0,0 +1,34 @@
+/*
+ * 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.library.util;
+
+import com.google.common.collect.Sets;
+
+import java.util.Set;
+
+public class HealthCheckUtil {
+private static final Set UN_HEALTH_ADDRESS = 
Sets.newHashSet("127.0.0.1", "localhost");

Review comment:
   done





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] xbkaishui commented on a change in pull request #5661: Add health checker for cluster management module

2020-10-16 Thread GitBox


xbkaishui commented on a change in pull request #5661:
URL: https://github.com/apache/skywalking/pull/5661#discussion_r506772792



##
File path: 
oap-server/server-cluster-plugin/cluster-consul-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/consul/ConsulCoordinator.java
##
@@ -49,22 +56,32 @@ public ConsulCoordinator(ClusterModuleConsulConfig config, 
Consul client) {
 
 @Override
 public List queryRemoteNodes() {
-HealthClient healthClient = client.healthClient();
-
-// Discover only "passing" nodes
-List nodes = 
healthClient.getHealthyServiceInstances(serviceName).getResponse();
-
 List remoteInstances = new ArrayList<>();
-if (CollectionUtils.isNotEmpty(nodes)) {
-nodes.forEach(node -> {
-if (!Strings.isNullOrEmpty(node.getService().getAddress())) {
-Address address = new 
Address(node.getService().getAddress(), node.getService().getPort(), false);
-if (address.equals(selfAddress)) {
-address.setSelf(true);
+try {
+HealthClient healthClient = client.healthClient();
+// Discover only "passing" nodes
+List nodes = 
healthClient.getHealthyServiceInstances(serviceName).getResponse();
+if (CollectionUtils.isNotEmpty(nodes)) {
+nodes.forEach(node -> {
+if 
(!Strings.isNullOrEmpty(node.getService().getAddress())) {
+Address address = new 
Address(node.getService().getAddress(), node.getService().getPort(), false);
+if (address.equals(selfAddress)) {
+address.setSelf(true);
+}
+remoteInstances.add(new RemoteInstance(address));

Review comment:
   Done, current implementation will ignore coordinator  standalone mode 





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] xbkaishui commented on a change in pull request #5661: Add health checker for cluster management module

2020-10-16 Thread GitBox


xbkaishui commented on a change in pull request #5661:
URL: https://github.com/apache/skywalking/pull/5661#discussion_r506766573



##
File path: 
oap-server/server-cluster-plugin/cluster-consul-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/consul/ConsulCoordinator.java
##
@@ -49,22 +56,32 @@ public ConsulCoordinator(ClusterModuleConsulConfig config, 
Consul client) {
 
 @Override
 public List queryRemoteNodes() {
-HealthClient healthClient = client.healthClient();
-
-// Discover only "passing" nodes
-List nodes = 
healthClient.getHealthyServiceInstances(serviceName).getResponse();
-
 List remoteInstances = new ArrayList<>();
-if (CollectionUtils.isNotEmpty(nodes)) {
-nodes.forEach(node -> {
-if (!Strings.isNullOrEmpty(node.getService().getAddress())) {
-Address address = new 
Address(node.getService().getAddress(), node.getService().getPort(), false);
-if (address.equals(selfAddress)) {
-address.setSelf(true);
+try {
+HealthClient healthClient = client.healthClient();
+// Discover only "passing" nodes
+List nodes = 
healthClient.getHealthyServiceInstances(serviceName).getResponse();
+if (CollectionUtils.isNotEmpty(nodes)) {
+nodes.forEach(node -> {
+if 
(!Strings.isNullOrEmpty(node.getService().getAddress())) {
+Address address = new 
Address(node.getService().getAddress(), node.getService().getPort(), false);
+if (address.equals(selfAddress)) {
+address.setSelf(true);
+}
+remoteInstances.add(new RemoteInstance(address));

Review comment:
   got it 





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] xbkaishui commented on a change in pull request #5661: Add health checker for cluster management module

2020-10-16 Thread GitBox


xbkaishui commented on a change in pull request #5661:
URL: https://github.com/apache/skywalking/pull/5661#discussion_r506466982



##
File path: 
oap-server/server-cluster-plugin/cluster-consul-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/consul/ConsulCoordinator.java
##
@@ -27,19 +27,25 @@
 import com.orbitz.consul.model.health.ServiceHealth;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
+
 import org.apache.skywalking.oap.server.core.cluster.ClusterNodesQuery;
 import org.apache.skywalking.oap.server.core.cluster.ClusterRegister;
 import org.apache.skywalking.oap.server.core.cluster.RemoteInstance;
+import org.apache.skywalking.oap.server.core.cluster.ServiceQueryException;
 import org.apache.skywalking.oap.server.core.cluster.ServiceRegisterException;
 import org.apache.skywalking.oap.server.core.remote.client.Address;
+import 
org.apache.skywalking.oap.server.library.client.healthcheck.HealthCheckable;
 import org.apache.skywalking.oap.server.library.util.CollectionUtils;
+import org.apache.skywalking.oap.server.library.util.HealthChecker;
 
-public class ConsulCoordinator implements ClusterRegister, ClusterNodesQuery {
+public class ConsulCoordinator implements ClusterRegister, ClusterNodesQuery, 
HealthCheckable {

Review comment:
   done





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] xbkaishui commented on a change in pull request #5661: Add health checker for cluster management module

2020-10-15 Thread GitBox


xbkaishui commented on a change in pull request #5661:
URL: https://github.com/apache/skywalking/pull/5661#discussion_r505519247



##
File path: oap-server/server-cluster-plugin/pom.xml
##
@@ -47,5 +47,10 @@
 library-util
 ${project.version}
 
+
+org.apache.skywalking
+library-client
+${project.version}
+

Review comment:
   done





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org