[ 
https://issues.apache.org/jira/browse/SCB-166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16315660#comment-16315660
 ] 

ASF GitHub Bot commented on SCB-166:
------------------------------------

zhengyangyong commented on a change in pull request #487: [SCB-166] Metrics 
Support HealthCheck
URL: 
https://github.com/apache/incubator-servicecomb-java-chassis/pull/487#discussion_r160075416
 
 

 ##########
 File path: 
metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
 ##########
 @@ -0,0 +1,65 @@
+/*
+ * 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 io.servicecomb.metrics.core.health;
+
+import javax.ws.rs.core.Response.Status;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.servicecomb.foundation.common.utils.JsonUtils;
+import io.servicecomb.metrics.common.DefaultHealthCheckExtraData;
+import io.servicecomb.metrics.common.HealthCheckResult;
+import io.servicecomb.metrics.common.HealthChecker;
+import io.servicecomb.serviceregistry.RegistryUtils;
+import io.servicecomb.serviceregistry.api.registry.Microservice;
+import io.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import io.servicecomb.swagger.invocation.exception.InvocationException;
+
+public class DefaultMicroserviceHealthChecker implements HealthChecker {
+
+  private static Logger logger = 
LoggerFactory.getLogger(DefaultMicroserviceHealthChecker.class);
+
+  @Override
+  public String getName() {
+    return "default";
+  }
+
+  @Override
+  public HealthCheckResult check() {
+    return new HealthCheckResult(true, "", getExtraData());
+  }
+
+  private String getExtraData() {
+    try {
+      Microservice microservice = RegistryUtils.getMicroservice();
+      MicroserviceInstance instance = RegistryUtils.getMicroserviceInstance();
+      return JsonUtils.writeValueAsString(new DefaultHealthCheckExtraData(
 
 Review comment:
   I think report this is OK ,or we can add a switch with default false?
   Our config center may not use ServiceCenter,Apollo is coming. And Health 
check is more wide mechanism also can used for check DB,Microservice or other 
related resource,one Microservice can have many HealthChecker;
   So I think "if not health, then SDK will stop heartBeat to SC or report 
status to SC" is a Ops policy and we can support later

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


> Support HealthCheck
> -------------------
>
>                 Key: SCB-166
>                 URL: https://issues.apache.org/jira/browse/SCB-166
>             Project: Apache ServiceComb
>          Issue Type: Sub-task
>          Components: Java-Chassis
>            Reporter: yangyongzheng
>            Assignee: yangyongzheng
>             Fix For: java-chassis-1.0.0-m1
>
>
> Java Chassis metrics can support HealthCheck rest interface like Spring boot 
> actuator



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to