In a microservice architecture, service diagnostics faces an increasing number of challenges. You can configure a local registry so that you can use Alibaba Cloud Toolkit to diagnose microservices. Alibaba Cloud Toolkit allows you to diagnose microservices in the High-speed Service Framework (HSF) and Apache Dubbo frameworks. The feature of diagnosing microservices in the Spring Cloud framework is being developed.

Prerequisites

Before you use Alibaba Cloud Toolkit to diagnose microservices, make sure that the following operations are complete:

Configure and start a registry

Separately configure a registry for a provider application and a consumer application.

Note You can use Alibaba Cloud Toolkit to configure a registry. You can also start a lightweight configuration center in an on-premises environment. For more information, see Start the light-weight configuration registry. You may use a standalone instance to configure the lightweight configuration center. In this case, enter http://<IP address of the instance>:8080 in Step 2 to view the microservice version and microservice group.

Start a local registry for a provider application

  1. Open a provider project in IntelliJ IDEA.
  2. In the top navigation bar of IntelliJ IDEA, choose File > Settings.
  3. In the Settings dialog box, choose Alibaba Cloud Toolkit > Microservice > Microservice.
  4. On the registry configuration page, select Use Local Registry, select a registry type, and then click Start.
    After the configuration is complete, Local registry started appears in the Local Registry dialog box.

Configure a custom registry for a consumer application

  1. Open a consumer project in IntelliJ IDEA.
  2. In the top navigation bar of IntelliJ IDEA, choose File > Settings.
  3. In the Settings dialog box, choose Alibaba Cloud Toolkit > Microservice > Microservice.
  4. On the registry configuration page, select Join Self-managed Nacos Registry, enter the IP address of the registry to be used in the text box, and then click OK.

Diagnose microservices

This section uses a Dubbo microservice as an example to describe how to diagnose microservices. The procedure for diagnosing HSF microservices is the same as that for diagnosing Dubbo microservices.

  1. Go to the microservice diagnostics page.
    • Use annotations

      You may use annotations that are similar to the following sample code. In this case, right-click the code area that contains the annotations, and choose Alibaba Cloud > Microservice Tools > Diagnostic in the shortcut menu.

          @Reference(version = "1.0.0", check=false)
          private DemoService demoService;
    • Use a configuration file

      You may use annotations that are similar to the following sample code. In this case, right-click the code area that contains the annotations, and choose Alibaba Cloud > Microservice Tools > Diagnostic in the shortcut menu.

      <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
             xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
             xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
             http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
          <context:property-placeholder/>
      
          <dubbo:application name="dubbo-echo-consumer"/>
      
          <dubbo:registry address="nacos://${nacos.address:127.0.0.1}:8848"/>
      
          <dubbo:reference id="demoService" check="false" interface="com.dubbo.example.DemoService" version="1.0.0"/>
      </beans>
  2. In the Service Diagnostics dialog box, set the diagnostics parameters and click Diagnose.
    Parameter Description
    Registry After you select Join Custom Registry on the registry management page, the registry information is automatically entered. If the registry is not configured, you must enter the address of the registry in the IP address:Port format, such as 127.0.0.1:8080.
    Service information If you go to the Service Diagnostics dialog box by using a valid method, the microservice information is automatically entered. Make sure that the VERSION field value and the GROUP field value are consistent with the microservice version and group in the microservice name. For example, if the microservice name is providers:com.dubbo.example.DemoService:1.0.0:dubbo, the microservice information is dubbo://com.dubbo.example.DemoService?VERSION=1.0.0&GROUP=dubbo.

Diagnostic logs

Check whether you can connect to a registry

You can use logs to diagnose network connections between an on-premises server and a registry. If the registry fails to be connected, an error message appears.

If the preceding error logs appear, check whether the IP address and port of the registry are valid. If the diagnostics is successful, the system returns a valid IP address of the registry.

Check whether a microservice can be called

You can use logs to check whether a microservice in a registry can be called. You can obtain microservice information, including the microservice interface, version, and group, from logs. If a microservice cannot be found, an error message appears.

If the preceding error logs appear, check microservice information, including the microservice type, interface, version, and group. The microservice type can be HSF or Dubbo. If the diagnostics is successful, the system returns the microservice that can be called in the registry.

Check whether a microservice is running on an instance

You can use logs to check whether a microservice is running on an instance. You can obtain the IP address and port of the instance from logs. If the microservice cannot be found, an error message appears, which indicates that no instance that runs the microservice is found.

Check whether you can connect to an instance that runs a microservice

You can use logs to check whether your on-premises server can connect to an instance that runs a microservice. If the connection fails, an error message appears, which indicates that the instance cannot be connected.