设置环境变量
CGO_ENABLED=0
SPAN_STORAGE_TYPE=elasticsearch
ES_SERVER_URLS=http://*:9200
测试url
query只是提供http服务,ui是单独的服务,可以通过ui上看看接口是怎么调用的。主要有:查看所有服务、trace查询、trace详情。
http://localhost:16686/api/services
http://localhost:16686/api/traces?end=1572417840000000&limit=20&lookback=custom&maxDuration&minDuration&service=jdsf-client&start=1572364800000000
代码流程
http服务器启动
cmd/query/app/server.go:createHTTPServer
httphanlder支持
cmd/query/app/http_handler.go:RegisterRoutes
func (aH *APIHandler) RegisterRoutes(router *mux.Router) {
// 根据ID查询trace信息
aH.handleFunc(router, aH.getTrace, "/traces/{%s}", traceIDParam).Methods(http.MethodGet)
// 条件搜索
aH.handleFunc(router, aH.search, "/traces").Methods(http.MethodGet)
// 服务列表
aH.handleFunc(router, aH.getServices, "/services").Methods(http.MethodGet)
}
搜索支持
cmd/query/app/http_handler.go:search
搜索参数为:traceQueryParameters,支持开始结束时间、服务名、span名等。
type TraceQueryParameters struct {
ServiceName string
OperationName string
Tags map[string]string
StartTimeMin time.Time
StartTimeMax time.Time
DurationMin time.Duration
DurationMax time.Duration
NumTraces int
}
读取trace数据
plugin/storage/es/spanstore/reader.go:FindTraces
大致流程:先根据条件聚合traceId,然后根据traceId查询根节点Span信息。
由于查询过程有聚合,所以jaeger目前不支持后台分页,后台排序(对聚合结果进行操作会很耗时,耗内存)。
网友评论