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 microservice applications in the High-Speed Service Framework (HSF) and Apache Dubbo frameworks. The feature of diagnosing microservice applications 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 provider and consumer applications.

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

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 left-side navigation pane of the Settings page, choose Alibaba Cloud Toolkit > EDAS.
  4. On the registry configuration page, select Use Local Registry and click Start Now.
    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 left-side navigation pane of the Settings page, choose Alibaba Cloud Toolkit > EDAS.
  4. On the registry configuration page, select Join Custom Registry. In the field on the right side, enter the IP address of the registry, and then click OK.

Diagnose microservices

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

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

      Assume that you 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 from the right-click shortcut menu.

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

      Assume that you 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 from the right-click 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, configure the diagnostic parameters and click Diagnose.
    Parameter Description
    Registry After you select Join Custom Registry on the registry management page, the system automatically fills in registry information. If the registry is not configured, you must enter the address of the registry in the IP address:Port format, for example, 127.0.0.1:8080.
    Service information If you go to the Service Diagnostics dialog box through a valid entrance, the system automatically fills in the service information. Make sure that the VERSION field value and the GROUP field value are consistent with the service version and group in the service name. For example, if the service name is providers:com.dubbo.example.DemoService:1.0.0:dubbo, the service information is dubbo://com.dubbo.example.DemoService?VERSION=1.0.0&GROUP=dubbo.

Diagnostic logs

Diagnose 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 diagnosis is successful, the system prints out a valid IP address of the registry.

Diagnose whether a service can be called

You can use logs to diagnose whether a service in a registry can be called. You can query service information, including the interface, version, and group. If a service cannot be found, an error message appears.

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

Diagnose whether a service is running on an instance

You can use logs to diagnose whether a service is running on an instance. You can query instance information, including the IP address and port of the instance. If the service cannot be found, an error message appears, which indicates that no instance that runs the service is found.

Diagnose whether you can connect to an instance that runs a service

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