api.proto 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. syntax = "proto3";
  2. import "google/api/annotations.proto";
  3. import "github.com/gogo/protobuf/gogoproto/gogo.proto";
  4. package dapper.query.v1;
  5. option go_package = "v1";
  6. message ListServiceNameReq {}
  7. message ListServiceNameReply {
  8. repeated string service_names = 1;
  9. }
  10. message ListOperationNameReq {
  11. string service_name = 1 [(gogoproto.moretags) = "form:\"service_name\" validate:\"required\""];
  12. }
  13. message ListOperationNameReply {
  14. repeated string operation_names = 1;
  15. }
  16. message ListSpanReq {
  17. string service_name = 1 [(gogoproto.moretags) = "form:\"service_name\" validate:\"required\""];
  18. string operation_name = 2 [(gogoproto.moretags) = "form:\"operation_name\" validate:\"required\""];
  19. int64 start = 3 [(gogoproto.moretags) = "form:\"start\""];
  20. int64 end = 4 [(gogoproto.moretags) = "form:\"end\""];
  21. // 目前支持的 order
  22. // time:desc time:asc 按时间排序
  23. // duration:desc duration:asc 按耗时排序
  24. string order = 5 [(gogoproto.moretags) = "form:\"order\""];
  25. // 只显示 error 的 span
  26. bool only_error = 6 [(gogoproto.moretags) = "form:\"only_error\""];
  27. int32 offset = 7 [(gogoproto.moretags) = "form:\"offset\""];
  28. int32 limit = 8 [(gogoproto.moretags) = "form:\"limit\""];
  29. }
  30. message SpanListItem {
  31. string trace_id = 1;
  32. string span_id = 2;
  33. string parent_id = 3;
  34. string service_name = 4;
  35. string operation_name = 5;
  36. string start_time = 6; // span 开始时间
  37. string duration = 7; // span 耗时
  38. map<string, TagValue> tags = 12;
  39. // Deprecated: use tags
  40. bool is_error = 8; // 是否发生错误
  41. string container_ip = 9;
  42. string region_zone = 10;
  43. string mark = 11;
  44. }
  45. message TraceReq {
  46. string trace_id = 1 [(gogoproto.moretags) = "form:\"trace_id\" validate:\"required\""];
  47. string span_id = 2 [(gogoproto.moretags) = "form:\"span_id\""];
  48. }
  49. message RawTraceReq {
  50. string trace_id = 1 [(gogoproto.moretags) = "form:\"trace_id\" validate:\"required\""];
  51. };
  52. message RawTraceReply {
  53. repeated Span items = 1;
  54. }
  55. message TagValue {
  56. oneof value {
  57. string string_value = 2;
  58. int64 int64_value = 3;
  59. bool bool_value = 4;
  60. float float_value = 5;
  61. }
  62. }
  63. message Field {
  64. string key = 1;
  65. string value = 2;
  66. }
  67. message Log {
  68. int64 timestamp = 1;
  69. repeated Field fields = 2;
  70. }
  71. message Span {
  72. string service_name = 1;
  73. string operation_name = 2;
  74. string trace_id = 3;
  75. string span_id = 4;
  76. string parent_id = 5;
  77. int64 start_time = 6;
  78. int64 duration = 7;
  79. map<string, TagValue> tags = 8;
  80. repeated Log logs = 9;
  81. int32 level = 10;
  82. repeated Span childs = 11;
  83. }
  84. message TraceReply {
  85. int32 service_count = 1;
  86. int32 span_count = 2;
  87. int32 max_level = 3;
  88. Span root = 4;
  89. }
  90. message ListSpanReply {
  91. repeated SpanListItem items = 2;
  92. }
  93. message OperationNameRankReq {
  94. string service_name = 1 [(gogoproto.moretags) = "form:\"service_name\" validate:\"required\""];
  95. int64 start = 2 [(gogoproto.moretags) = "form:\"start\""];
  96. int64 end = 3 [(gogoproto.moretags) = "form:\"end\""];
  97. // 排序类型 max_duration 最大耗时, min_duration 最小耗时, avg_duration 平均耗时, errors 错误数
  98. string rank_type = 4 [(gogoproto.moretags) = "form:\"rank_type\""];
  99. }
  100. message RankItem {
  101. string service_name = 1;
  102. string operation_name = 2;
  103. // 当 rank type 是 max_duration, min_duration, avg_duration 时 value 是纳秒
  104. // 当 rank type 是 errors 是 value 是错误数
  105. double value = 3;
  106. }
  107. message OperationNameRankReply {
  108. string rank_type = 1;
  109. repeated RankItem items = 2;
  110. }
  111. message DependsRankReq {
  112. string service_name = 1 [(gogoproto.moretags) = "form:\"service_name\" validate:\"required\""];
  113. int64 start = 3 [(gogoproto.moretags) = "form:\"start\""];
  114. int64 end = 4 [(gogoproto.moretags) = "form:\"end\""];
  115. // 排序类型 max_duration 最大耗时, min_duration 最小耗时, avg_duration 平均耗时, errors 错误数
  116. string rank_type = 5 [(gogoproto.moretags) = "form:\"rank_type\""];
  117. }
  118. message DependsRankReply {
  119. string rank_type = 1;
  120. repeated RankItem items = 2;
  121. }
  122. message SpanSeriesReq {
  123. string service_name = 1 [(gogoproto.moretags) = "form:\"service_name\" validate:\"required\""];
  124. string operation_name = 2 [(gogoproto.moretags) = "form:\"operation_name\" validate:\"required\""];
  125. int64 start = 3 [(gogoproto.moretags) = "form:\"start\""];
  126. int64 end = 4 [(gogoproto.moretags) = "form:\"end\""];
  127. // 可选的 fields 有 max_duration, min_duration, avg_duration, errors
  128. // 其中除 errors 返回的是一段时间内的总数 其他返回的都是平均数
  129. // fields 是个数组可以通过 fields=max_duration,min_duration,avg_duration 逗号分隔
  130. string fields = 6 [(gogoproto.moretags) = "form:\"fields\""];
  131. }
  132. message SeriesItem {
  133. // 名称一般是请求的 field+{count|mean}
  134. string field = 1;
  135. repeated int64 values = 2 [(gogoproto.customtype) = "*int64"];
  136. }
  137. message SpanSeriesReply {
  138. // 返回点的间隔
  139. int64 interval = 5;
  140. repeated string times = 1;
  141. repeated SeriesItem items = 2;
  142. }
  143. message CltStatusReq {}
  144. message Client {
  145. string addr = 1;
  146. int64 err_count = 2;
  147. int64 rate = 3;
  148. int64 up_time = 4;
  149. }
  150. message CltNode {
  151. string node = 1;
  152. int64 queue_len = 2;
  153. repeated Client clients = 3;
  154. }
  155. message CltStatusReply {
  156. repeated CltNode nodes = 1;
  157. }
  158. message SamplePointReq {
  159. string service_name = 1 [(gogoproto.moretags) = "form:\"service_name\" validate:\"required\""];
  160. string operation_name = 2 [(gogoproto.moretags) = "form:\"operation_name\" validate:\"required\""];
  161. // only_error 在 errors 那个图可以指定为 true
  162. bool only_error = 3 [(gogoproto.moretags) = "form:\"only_error\""];
  163. // interval 使用 span-series 返回的 interval 即可
  164. int64 interval = 5 [(gogoproto.moretags) = "form:\"interval\" validate:\"required\""];
  165. // time 使用 time-series 返回的时间即可,相同格式型如 2006-01-02T15:04:05
  166. string time = 6 [(gogoproto.moretags) = "form:\"time\" validate:\"required\""];
  167. }
  168. message SamplePointItem {
  169. string trace_id = 1;
  170. string span_id = 2;
  171. int64 duration = 3;
  172. bool is_error = 4;
  173. }
  174. message SamplePointReply {
  175. repeated SamplePointItem items = 1;
  176. }
  177. message DependsTopologyReq {}
  178. message DependsTopologyItem {
  179. string service_name = 1;
  180. string depend_on = 2;
  181. }
  182. message DependsTopologyReply {
  183. repeated DependsTopologyItem items = 1;
  184. }
  185. message OpsLogReq {
  186. string trace_id = 1 [(gogoproto.moretags) = "form:\"trace_id\" validate:\"required\""];
  187. string span_id = 2 [(gogoproto.moretags) = "form:\"span_id\""];
  188. string trace_field = 3 [(gogoproto.moretags) = "form:\"trace_field\""];
  189. string service_name = 4 [(gogoproto.moretags) = "form:\"service_name\""];
  190. string operation_name = 5 [(gogoproto.moretags) = "form:\"operation_name\""];
  191. // 开始时间
  192. int64 start = 6 [(gogoproto.moretags) = "form:\"start\""];
  193. // 结束时间
  194. int64 end = 7[(gogoproto.moretags) = "form:\"end\""];
  195. }
  196. message OpsLogRecord {
  197. string time = 1;
  198. map<string, TagValue> fields = 2;
  199. string level = 3;
  200. string message = 4;
  201. }
  202. message OpsLogReply {
  203. repeated OpsLogRecord records = 1;
  204. }
  205. message ServiceDependReq {
  206. // service_name 不解释!
  207. string service_name = 1 [(gogoproto.moretags) = "form:\"service_name\" validate:\"required\""];
  208. // operation_name 当 operation_name 为空时查询所有 operation_name 然后 merge 结果
  209. string operation_name = 2 [(gogoproto.moretags) = "form:\"operation_name\""];
  210. }
  211. message ServiceDependReply {
  212. repeated ServiceDependItem items = 1;
  213. }
  214. message ServiceDependItem {
  215. // service_name 依赖服务名称, service 为 AppID 其他为组件名 mysql, redis, http 等
  216. string service_name = 1;
  217. // component, 通讯组件 e.g. net/http, goRPC, gRPC
  218. string component = 2;
  219. // operation_names 被依赖服务的 operation_names, mysql, redis 等为空
  220. repeated string operation_names = 3;
  221. }
  222. // DapperQuery dapper 查询服务
  223. service DapperQuery {
  224. // ListServiceName 列出所有 service
  225. rpc ListServiceName(ListServiceNameReq) returns (ListServiceNameReply) {
  226. option (google.api.http) = {
  227. get: "/x/internal/dapper/service-names";
  228. };
  229. }
  230. // ListOperationName 列出某一 service 下所有 operation_name 仅 span.kind 为 server 的 operation_name
  231. rpc ListOperationName(ListOperationNameReq) returns (ListOperationNameReply) {
  232. option (google.api.http) = {
  233. get: "/x/internal/dapper/operation-names";
  234. };
  235. }
  236. // ListSpan 列出一个 service_name 某一 operation_name 所有采样到 Span
  237. rpc ListSpan(ListSpanReq) returns (ListSpanReply) {
  238. option (google.api.http) = {
  239. get: "/x/internal/dapper/list-span";
  240. };
  241. }
  242. // Trace 查询一个 Trace
  243. rpc Trace(TraceReq) returns (TraceReply) {
  244. option (google.api.http) = {
  245. get: "/x/internal/dapper/trace";
  246. };
  247. }
  248. // RawTrace 原始 Trace 数据
  249. rpc RawTrace(RawTraceReq) returns (RawTraceReply) {
  250. option (google.api.http) = {
  251. get: "/x/internal/dapper/raw-trace";
  252. };
  253. }
  254. // OperationNameRank 查询 OperationName 排名列表
  255. rpc OperationNameRank(OperationNameRankReq) returns(OperationNameRankReply) {
  256. option (google.api.http) = {
  257. get: "/x/internal/dapper/operation-names-rank";
  258. };
  259. }
  260. // DependsRank 查询某一个 service_name:operation_name 下所有依赖组件排名
  261. rpc DependsRank(DependsRankReq) returns(DependsRankReply) {
  262. option (google.api.http) = {
  263. get: "/x/internal/dapper/depends-rank";
  264. };
  265. }
  266. // SpanSeries 获取 span 的时间序列数据
  267. rpc SpanSeries(SpanSeriesReq) returns (SpanSeriesReply) {
  268. option (google.api.http) = {
  269. get: "/x/internal/dapper/span-series";
  270. };
  271. }
  272. // SamplePoint 获取采样点数据
  273. rpc SamplePoint(SamplePointReq) returns(SamplePointReply) {
  274. option (google.api.http) = {
  275. get: "/x/internal/dapper/sample-point";
  276. };
  277. }
  278. // CltStatus 获取 collector 信息
  279. rpc CltStatus(CltStatusReq) returns(CltStatusReply) {
  280. option (google.api.http) = {
  281. get: "/x/internal/dapper/clt-status";
  282. };
  283. }
  284. // DependsTopology 获取依赖拓扑图
  285. rpc DependsTopology(DependsTopologyReq) returns (DependsTopologyReply) {
  286. option (google.api.http) = {
  287. get: "/x/internal/dapper/depends-topology";
  288. };
  289. }
  290. // OpsLog 获取 通过 trace-id 获取 opslog 记录
  291. // 如果请求的 trace-id 没有被记录到, 则需要提供 service_name operation_name 和 timestamp 进行模糊查询
  292. rpc OpsLog(OpsLogReq) returns (OpsLogReply) {
  293. option (google.api.http) = {
  294. get: "/x/internal/dapper/ops-log";
  295. };
  296. }
  297. // ServiceDepend 查询服务的直接依赖
  298. // TODO: 通过最近收集的到3 个 span 实时计算的,在当前查询的服务出现不正常的时候,查询结果可能不准确
  299. rpc ServiceDepend(ServiceDependReq) returns (ServiceDependReply) {
  300. option (google.api.http) = {
  301. get: "/x/internal/dapper/service-depend";
  302. };
  303. }
  304. }