简介
zipkin是分布式跟踪系统,在微服务架构中,它可以获取实时的数据帮助解决请求延迟问题。zipkin收集并展示调用链数据。zipkin是基于谷歌的Dapper系统设计的。

zipkin架构

首先在app使用zipkin的客户端,收集server,client(后面会讲)的调用关系数据,通过reporter上传到Collector,然后Collector通过Storage进行存储,最后UI展示调用链信息。
zipkin的基本概念
span
基本工作单元,一次链路调用创建一个span,可以是httpclient,db调用。span通过parentSpanId进行关联
trace
代表一个完整的请求,期间可能横跨多个服务,用唯一标识。tace是多个span的集合。
Annotation
Annotation是span的tag集合。它主要有5种类型:
cs - Client Start,表示客户端发起请求 sr - Server Receive,表示服务端收到请求 ss - Server Send,表示服务端完成处理,并将结果发送给客户端 cr - Client Received,表示客户端获取到服务端返回信息 lc - local component,表示本地span,不能跨进程,比如一次file io操作
BinaryAnnotation
可以在此tag种添加业务信息
完整的报文
[ { "traceId": "a0e07d61b5f6060a", "id": "a0e07d61b5f6060a", "name": "get", "timestamp": 1479457971341000, "duration": 3872769, "annotations": [ { "timestamp": 1479457971341000, "value": "sr", "endpoint": { "serviceName": "service1", "ipv4": "172.16.8.79" } }, { "timestamp": 1479457975213769, "value": "ss", "endpoint": { "serviceName": "service1", "ipv4": "172.16.8.79" } } ], "binaryAnnotations": [ { "key": "exception", "value": "asdas", "endpoint": { "serviceName": "service1", "ipv4": "172.16.8.79" } }, { "key": "http.status_code", "value": "200", "endpoint": { "serviceName": "service1", "ipv4": "172.16.8.79" } }, { "key": "http.url", "value": "/start", "endpoint": { "serviceName": "service1", "ipv4": "172.16.8.79" } } ] }, { "traceId": "a0e07d61b5f6060a", "id": "3be8fed4e9846694", "name": "get", "parentId": "a0e07d61b5f6060a", "timestamp": 1479457971444000, "duration": 41291, "annotations": [ { "timestamp": 1479457971444000, "value": "cs", "endpoint": { "serviceName": "service1", "ipv4": "172.16.8.79" } }, { "timestamp": 1479457971485291, "value": "cr", "endpoint": { "serviceName": "service1", "ipv4": "172.16.8.79" } } ], "binaryAnnotations": [ { "key": "http.url", "value": "http://www.baidu.com/", "endpoint": { "serviceName": "service1", "ipv4": "172.16.8.79" } } ] } ]
来源:oschina
链接:https://my.oschina.net/u/913896/blog/793908