Preamble
We will show you a go-zero microservice example in detail through a series of articles. The whole series is divided into ten articles. The directory structure is as follows:
- Environment construction
- service split
- User service
- product service
- Order service
- payment service
- RPC Service Auth Authentication
- service monitoring
- Link Tracing (this article)
- Distributed transaction
I hope that through this series, you can quickly develop a mall system using go-zero in the Docker environment on the local machine, so that you can quickly get started with microservices.
Complete example code: https://github.com/nivin-studio/go-zero-mall
First, let's take a look at the overall service split diagram:
9.1 Jaeger
Introduction
Jaeger
Yes Uber
A distributed tracing system developed and open source, compatible with OpenTracing API
, 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 completed by three roles:
-
client
: Responsible for the timing and sampling of each call point on the entire link, and send thetracing
data to the localagent
. -
agent
: responsible for collectingclient
senttracing
data, and tothrift
protocol forwarded tocollector
. -
collector
: Responsible for collecting allagent
tracing
and storing them uniformly.
9.2 go-zero
use Jaeger
link trace
go-zero
framework has already helped us implement link tracking (see: go-zero link tracking ), and the integration supports Jaeger
, Zipkin
these two With the link tracking reporting tool, we can visualize the complete call chain of a request, as well as the call status and performance of each link with a simple configuration.
9.2.1 Add user api
service Telemetry
configure
$ vim mall/service/user/api/etc/user.yaml
Name: User
Host: 0.0.0.0
Port: 8000
...
Telemetry:
Name: user.api
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
9.2.2 add user rpc
service Telemetry
configure
$ vim mall/service/user/rpc/etc/user.yaml
Name: user.rpc
ListenOn: 0.0.0.0:9000
...
Telemetry:
Name: user.rpc
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
9.2.3 add product api
service Telemetry
configure
$ vim mall/service/product/api/etc/product.yaml
Name: Product
Host: 0.0.0.0
Port: 8001
...
Telemetry:
Name: product.api
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
9.2.4 Add product rpc
service Telemetry
configure
$ vim mall/service/product/rpc/etc/product.yaml
Name: product.rpc
ListenOn: 0.0.0.0:9001
...
Telemetry:
Name: product.rpc
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
9.2.5 Add order api
service Telemetry
configure
$ vim mall/service/order/api/etc/order.yaml
Name: Order
Host: 0.0.0.0
Port: 8002
...
Telemetry:
Name: order.api
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
9.2.6 Add order rpc
service Telemetry
configure
$ vim mall/service/order/rpc/etc/order.yaml
Name: order.rpc
ListenOn: 0.0.0.0:9002
...
Telemetry:
Name: order.rpc
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
9.2.7 Add pay api
Service Telemetry
Configuration
$ vim mall/service/pay/api/etc/pay.yaml
Name: Pay
Host: 0.0.0.0
Port: 8003
...
Telemetry:
Name: pay.api
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
9.2.8 add pay rpc
service Telemetry
configure
$ vim mall/service/pay/rpc/etc/pay.yaml
Name: pay.rpc
ListenOn: 0.0.0.0:9003
...
Telemetry:
Name: pay.rpc
Endpoint: http://jaeger:14268/api/traces
Sampler: 1.0
Batcher: jaeger
Tip: After the configuration is modified, the service needs to be restarted to take effect.
9.3 Use Jaeger UI
view the link
- Access
/api/user/userinfo
api接口
- In the first chapter of environment construction , we integrated the
Jaeger
service, and made the host port --- ab6cb62f6a80358adff3a43a2f4519f5Jaeger UI
port number16686
the host port5000
The mapping relationship, so enterhttp://127.0.0.1:5000/
in the browser to access theJaeger UI
interface. Select theSearch
menu, selectuser.api
a075fec67d686de828af22fdb799cfda--- in theService
drop-down box, and finally click theFind Traces
button to query the --- just accessed/api/user/userinfo
Link trace data of the interface.
- Click in, you can see the link sequence diagram of this
/api/user/userinfo
interface, as well as service dependencies, and time-consuming.
- The drop-down menu in the upper right corner can select different data display styles.
- Other interface link tracking renderings
project address
https://github.com/zeromicro/go-zero
Welcome go-zero
and star support us!
WeChat exchange group
Follow the official account of " Microservice Practice " and click on the exchange group to get the QR code of the community group.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。