The preface
We will show you a detailed example of a Go-Zero microservice in a series of ten articles. The table of contents is as follows:
- Environment set up
- Service split
- Customer service
- Product/service
- Order service
- Payment service
- Auth authentication for RPC service
- Service monitoring
- Link Tracing (this article)
- Distributed transaction
I hope this series will take you to use the Docker environment on the machine and use go-Zero to quickly develop a mall system, so that you can quickly get started with micro services.
Full example code: github.com/nivin-studi…
First, let’s look at the overall service breakdown diagram:
9.1 Jaeger
introduce
Jaeger is a distributed tracking system developed and open source by Uber. Compatible with OpenTracing API, Jaeger is suitable for the following scenarios:
- Distributed trace information delivery
- Distributed transaction monitoring
- Problem analysis
- Service dependency analysis
- Performance optimization
The full-link tracking function of Jaeger is mainly performed by three roles:
client
: Is responsible for timing, sampling at each call point on the whole link, and willtracing
Data is sent locallyagent
.agent
: Responsible for collectionclient
From thetracing
Data, and tothrift
Protocol forward tocollector
.collector
: Responsible for collecting allagent
reportedtracing
Data, unified storage.
9.2 go-zero
useJaeger
Link to track
The Go-Zero framework has already enabled link tracing (see: Go-zero link tracing), and integrated support for Jaeger and Zipkin link tracing reporting tools. With simple configuration, we can visually view the complete call chain of a request, as well as the call situation and performance of each link.
9.2.1 adduser api
serviceTelemetry
configuration
$ vim mall/service/user/api/etc/user.yaml
Copy the code
Name: User
Host: 0.0. 0. 0
Port: 8000
.
Telemetry:
Name: user.api
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
Copy the code
9.2.2 adduser rpc
serviceTelemetry
configuration
$ vim mall/service/user/rpc/etc/user.yaml
Copy the code
Name: user.rpc
ListenOn: 0.0. 0. 0: 9000
.
Telemetry:
Name: user.rpc
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
Copy the code
9.2.3 addproduct api
serviceTelemetry
configuration
$ vim mall/service/product/api/etc/product.yaml
Copy the code
Name: Product
Host: 0.0. 0. 0
Port: 8001
.
Telemetry:
Name: product.api
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
Copy the code
9.2.4 addproduct rpc
serviceTelemetry
configuration
$ vim mall/service/product/rpc/etc/product.yaml
Copy the code
Name: product.rpc
ListenOn: 0.0. 0. 0: 9001
.
Telemetry:
Name: product.rpc
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
Copy the code
9.2.5 addorder api
serviceTelemetry
configuration
$ vim mall/service/order/api/etc/order.yaml
Copy the code
Name: Order
Host: 0.0. 0. 0
Port: 8002
.
Telemetry:
Name: order.api
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
Copy the code
9.2.6 addorder rpc
serviceTelemetry
configuration
$ vim mall/service/order/rpc/etc/order.yaml
Copy the code
Name: order.rpc
ListenOn: 0.0. 0. 0: 9002
.
Telemetry:
Name: order.rpc
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
Copy the code
9.2.7 addpay api
serviceTelemetry
configuration
$ vim mall/service/pay/api/etc/pay.yaml
Copy the code
Name: Pay
Host: 0.0. 0. 0
Port: 8003
.
Telemetry:
Name: pay.api
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
Copy the code
9.2.8 addpay rpc
serviceTelemetry
configuration
$ vim mall/service/pay/rpc/etc/pay.yaml
Copy the code
Name: pay.rpc
ListenOn: 0.0. 0. 0: 9003
.
Telemetry:
Name: pay.rpc
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
Copy the code
Note: The modification takes effect only after the service is restarted.
9.3 the use ofJaeger UI
See the link
- access
/api/user/userinfo
API interface
- inChapter 1 Environment ConstructionWe integrate
Jaeger
Serve, and forJaeger UI
The port number16686
Made the host port5000
“, so enter it in your browserhttp://127.0.0.1:5000/
accessJaeger UI
Interface. chooseSearch
The menu,Service
Select a value from the drop-down list boxuser.api
And then clickFind Traces
Button to query to the one you just visited/api/user/userinfo
Link tracing data of the interface.
- Click in, and you can see this
/api/user/userinfo
Link timing diagram of the interface, as well as service dependencies, and time consumption.
- Different data presentation styles can be selected from the drop-down menu in the upper right corner.
- Link tracing renderings of other interfaces
The project address
Github.com/zeromicro/g…
Welcome to Go-Zero and star support us!
Wechat communication group
Pay attention to the public account of “micro-service Practice” and click on the exchange group to obtain the QR code of the community group.