【zipkin/jaeger使用系列】zipkin的基本概念和初步体验

参考文档

https://blog.csdn.net/apei830/article/details/78722168

概念与协议协议

概念英文版(spring官网)

概念中文版

  • Span
    基本工作单元,一次链路调用(可以是RPC,DB等没有特定的限制)创建一个span,通过一个64位ID标识它,span通过还有其他的数据,例如描述信息,时间戳,key-value对的(Annotation)tag信息,parent-id等,其中parent-id可以表示span调用链路来源,通俗的理解span就是一次请求信息。

  • Trace
    类似于树结构的Span集合,表示一条调用链路(一次端到端的完整请求),存在唯一标识,即TraceId。

  • Annotation
    span的注解,用来记录请求特定事件相关信息(例如时间),通常包含四个注解信息:
    cs:Client Start,表示客户端发起请求
    sr:Server Receive,表示服务端收到请求
    ss:Server Send,表示服务端完成处理,并将结果发送给客户端
    cr:Client Received,表示客户端获取到服务端返回信息

BinaryAnnotation:提供一些额外信息,一般以key-value对出现

传输协议

http传输

传输的数据(V2版本)

存储到es的document的_source字段

"_source": {
"traceId": "388c003cbf4d978e",
"duration": 50735,
"remoteEndpoint": {
"ipv4": "192.168.128.57",
"port": 12497
},
"shared": true,
"localEndpoint": {
"serviceName": "serviceb",
"ipv4": "192.168.128.57"
},
"timestamp_millis": 1527308495000,
"kind": "SERVER",
"name": "get /call/{id}",
"id": "c7e7ea03cfaf7108",
"parentId": "388c003cbf4d978e",
"timestamp": 1527308495000715,
"tags": {
"http.method": "GET",
"http.path": "/call/abcd",
"mvc.controller.class": "UserController",
"mvc.controller.method": "callHome"
}
}

架构图

主要包括四个模块

  • Collector 
    接收或收集各应用传输的数据
  • Storage
    存储接受或收集过来的数据,当前支持Memory,MySQL,Cassandra,ElasticSearch等,默认存储在内存中。
  • API(Query)
    负责查询Storage中存储的数据,提供简单的JSON API获取数据,主要提供给web UI使用
  • Web                 
    提供简单的web界面

服务端安装配置

mysql存储

mysql脚本

CREATE TABLE IF NOT EXISTS _spans (
trace_id_high BIGINT NOT NULL DEFAULT 0 COMMENT ‘If non zero, this means the trace uses 128 bit traceIds instead of 64 bit’,
trace_id BIGINT NOT NULL,
id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL,
remote_service_name VARCHAR(255),
parent_id BIGINT,
debug BIT(1),
start_ts BIGINT COMMENT ‘Span.timestamp(): epoch micros used for endTs query and to implement TTL’,
duration BIGINT COMMENT ‘Span.duration(): micros used for minDuration and maxDuration query’,
PRIMARY KEY (trace_id_high, trace_id, id)
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;

ALTER TABLE _spans ADD INDEX(trace_id_high, trace_id) COMMENT ‘for getTracesByIds’;
ALTER TABLE _spans ADD INDEX(name) COMMENT ‘for getTraces and getSpanNames’;
ALTER TABLE _spans ADD INDEX(remote_service_name) COMMENT ‘for getTraces and getRemoteServiceNames’;
ALTER TABLE _spans ADD INDEX(start_ts) COMMENT ‘for getTraces ordering and range’;

CREATE TABLE IF NOT EXISTS _annotations (
trace_id_high BIGINT NOT NULL DEFAULT 0 COMMENT ‘If non zero, this means the trace uses 128 bit traceIds instead of 64 bit’,
trace_id BIGINT NOT NULL COMMENT ‘coincides with _spans.trace_id’,
span_id BIGINT NOT NULL COMMENT ‘coincides with _spans.id’,
a_key VARCHAR(255) NOT NULL COMMENT ‘BinaryAnnotation.key or Annotation.value if type == -1’,
a_value BLOB COMMENT ‘BinaryAnnotation.value(), which must be smaller than 64KB’,
a_type INT NOT NULL COMMENT ‘BinaryAnnotation.type() or -1 if Annotation’,
a_timestamp BIGINT COMMENT ‘Used to implement TTL; Annotation.timestamp or _spans.timestamp’,
endpoint_ipv4 INT COMMENT ‘Null when Binary/Annotation.endpoint is null’,
endpoint_ipv6 BINARY(16) COMMENT ‘Null when Binary/Annotation.endpoint is null, or no IPv6 address’,
endpoint_port SMALLINT COMMENT ‘Null when Binary/Annotation.endpoint is null’,
endpoint_service_name VARCHAR(255) COMMENT ‘Null when Binary/Annotation.endpoint is null’
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;

ALTER TABLE _annotations ADD UNIQUE KEY(trace_id_high, trace_id, span_id, a_key, a_timestamp) COMMENT ‘Ignore insert on duplicate’;
ALTER TABLE _annotations ADD INDEX(trace_id_high, trace_id, span_id) COMMENT ‘for joining with _spans’;
ALTER TABLE _annotations ADD INDEX(trace_id_high, trace_id) COMMENT ‘for getTraces/ByIds’;
ALTER TABLE _annotations ADD INDEX(endpoint_service_name) COMMENT ‘for getTraces and getServiceNames’;
ALTER TABLE _annotations ADD INDEX(a_type) COMMENT ‘for getTraces and autocomplete values’;
ALTER TABLE _annotations ADD INDEX(a_key) COMMENT ‘for getTraces and autocomplete values’;
ALTER TABLE _annotations ADD INDEX(trace_id, span_id, a_key) COMMENT ‘for dependencies job’;

CREATE TABLE IF NOT EXISTS _dependencies (
day DATE NOT NULL,
parent VARCHAR(255) NOT NULL,
child VARCHAR(255) NOT NULL,
call_count BIGINT,
error_count BIGINT,
PRIMARY KEY (day, parent, child)
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;

启动脚本

RABBIT_URI=amqp://admin:admin@192.168.172.3:5672/sleuth STORAGE_TYPE=mysql MYSQL_DB= MYSQL_USER=root MYSQL_PASS=123456 MYSQL_TCP_PORT=3306 MYSQL_HOST=192.168.172.2 MYSQL_DB= MYSQL_USE_SSL=false java -jar .jar

elaticsearch存储

启动脚本

RABBIT_URI=amqp://admin:admin@192.168.172.3:5672/sleuth STORAGE_TYPE=elasticsearch ES_HOSTS=http://192.168.172.8:9200 ES_INDEX_REPLICAS=0 java -jar .jar –logging.level.=debug –logging.level.2=debug & > .log