[ https://issues.apache.org/jira/browse/SCB-166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16312729#comment-16312729 ]
ASF GitHub Bot commented on SCB-166: ------------------------------------ WillemJiang 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_r159831078 ########## File path: metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java ########## @@ -0,0 +1,62 @@ +/* + * 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 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; + +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( + instance.getInstanceId(), + instance.getHostName(), + microservice.getAppId(), + microservice.getServiceName(), + microservice.getVersion(), + String.join(",", instance.getEndpoints()))); + } catch (Exception e) { Review comment: It's better to throw the exception, otherwise the client get the 200 response code. ---------------------------------------------------------------- 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)