[Cloud Native & Microservices > SCG Gateway Chapter 10] Detailed case of Spring Cloud Gateway integrating Actuator and Zipkin

I. Introduction

So far, the microservice gateway series of articles have been published:

  1. [Cloud Native & Microservices > SCG Gateway Part 1] Why there is a gateway and how to choose a gateway in a production environment
  2. Cloud Native & Microservices > SCG Gateway Part 2] Those grayscale release methods in production
  3. [Cloud Native & Microservices > SCG Gateway Part 3] What is Spring Cloud Gateway and detailed use cases
  4. Cloud Native & Microservices > SCG Gateway Part 4] How to use the 11 kinds of PredicateFactory built in Spring Cloud Gateway
  5. [Cloud Native & Microservices > SCG Gateway Part 5] Spring Cloud Gateway Custom PredicateFactory
  6. [Cloud Native & Microservices > SCG Gateway Chapter 6] 18 filter usage postures built in Spring Cloud Gateway
  7. [Cloud Native & Microservices > SCG Gateway Chapter 7] Spring Cloud Gateway implements current limiting, fusing, and retrying based on built-in Filters
  8. [Cloud native & microservices > SCG gateway chapter 8] Spring Cloud Gateway three ways to customize Filter and GlobalFilter
  9. [Cloud Native & Microservices > SCG Gateway Chapter 9] A detailed case of Spring Cloud Gateway integrating Nacos

Discussed the following issues:

  1. Why have a gateway? What is the role of a gateway?
  2. Classification of gateways?
  3. Gateway technology selection?
  4. What are the commonly used grayscale publishing methods when using gateways?
  5. What is Spring Cloud Gateway? Detailed use case?
  6. 11 kinds of PredicateFactory built in Spring Cloud Gateway
  7. How to customize PredicateFactory?
  8. 18 commonly used Filters built in Spring Cloud Gateway
  9. Spring Cloud Gateway implements current limiting, fusing, and retrying based on built-in Filters
  10. Three ways to customize Filter and GlobalFilter in Spring Cloud Gateway
  11. Spring Cloud Gateway integration Nacos case

This article then talks about how Spring Cloud Gateway integrates actuators to track service status and integrate zipkin to track service call link information?

PS: SpringCloud version information:

<properties>
    <spring-boot.version>2.4.2</spring-boot.version>
    <spring-cloud.version>2020.0.1</spring-cloud.version>
    <spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring-boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!--整合spring cloud-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!--整合spring cloud alibaba-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>${spring-cloud-alibaba.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

2. Integrated Actuator monitoring gateway

Then [Cloud Native & Microservices > SCG Gateway Chapter 9] Spring Cloud Gateway integrated Nacos detailed case to continue the operation;

GatewayMetricsFilterThe gateway can give the call status of the Gateway through the gateway indicator filter ( ),

1> Introduce spring-boot-starter-actuator dependency in pom:

<!--集成actuator-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2> Specify the monitoring path in the application.yml file:

# 集成actuator,使用http://xxxx/actuator/metrics查看请求信息
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always

3> Use http://127.0.0.1:9999/actuator/metrics to view all categories of request monitoring information:

insert image description here

4> Use http://127.0.0.1:9999/actuator/spring.cloud.gateway.requests to view gateway-related request monitoring information:

Before viewing the gateway-related request monitoring information, you must request the gateway once.

insert image description here

3. Integrate Zipkin

1> Introduce zipkin and sleuth dependencies in pom:

<!--集成zipkin, ZipKin中包含sleuth-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>

2> Configure zipkin and sleuth information in application.yml:

spring:
    # 集成zipkin
  zipkin:
    base-url: http://127.0.0.1:9411/
    # zipkin不注册到nacos
    discovery-client-enabled: false
  sleuth:
    sampler:
      # 抽样率。默认是0.1(10%),即丢弃90%的数据
      probability: 1.0

3> After calling the request, visit http://127.0.0.1:9411/zipkin/ to trace the service call link:

insert image description here
For each request, you can click the SHOWbutton on the right to view the specific service call link information:

insert image description here

4. Summary

This article is a purely practical article. It describes how to integrate actuators to monitor service status and integrate zipkin / sleuth for service call link tracking in Spring Cloud Gateway.

There are two practical articles later: Gateway solves cross-domain problems, Gateway integrates Sentinel to achieve current limiting; then enter the source code analysis article; analyze the principle of Gateway.

Guess you like

Origin blog.csdn.net/Saintmm/article/details/125834960