数据模型

数据模型

为了说明 Zipkin 展现的追踪数据,让我们把 Zipkin 中的信息与其对应的数据进行关联。通过对比,我们可以发现:

  • 带内和带外请求在不同的跨度中
  • 包含 cs 的跨度可以记录一个它要去哪里的 sa 的标记这有助于当目标没有 Zipkin 装配的时候,比如 MySQL

首先,让我们看一下在 Zipkin 追踪视图里的展现的一条追踪数据:

数据模型 - 图1

相同数据在 Zipkin 数据模型中:

  1. 1. [
  2. 2. {
  3. 3. "traceId": "bd7a977555f6b982",
  4. 4. "name": "get",
  5. 5. "id": "bd7a977555f6b982",
  6. 6. "timestamp": 1458702548467000,
  7. 7. "duration": 386000,
  8. 8. "annotations": [
  9. 9. {
  10. 10. "endpoint": {
  11. 11. "serviceName": "zipkin-query",
  12. 12. "ipv4": "192.168.1.2",
  13. 13. "port": 9411
  14. 14. },
  15. 15. "timestamp": 1458702548467000,
  16. 16. "value": "sr"
  17. 17. },
  18. 18. {
  19. 19. "endpoint": {
  20. 20. "serviceName": "zipkin-query",
  21. 21. "ipv4": "192.168.1.2",
  22. 22. "port": 9411
  23. 23. },
  24. 24. "timestamp": 1458702548853000,
  25. 25. "value": "ss"
  26. 26. }
  27. 27. ],
  28. 28. "binaryAnnotations": []
  29. 29. },
  30. 30. {
  31. 31. "traceId": "bd7a977555f6b982",
  32. 32. "name": "get-traces",
  33. 33. "id": "ebf33e1a81dc6f71",
  34. 34. "parentId": "bd7a977555f6b982",
  35. 35. "timestamp": 1458702548478000,
  36. 36. "duration": 354374,
  37. 37. "annotations": [],
  38. 38. "binaryAnnotations": [
  39. 39. {
  40. 40. "key": "lc",
  41. 41. "value": "JDBCSpanStore",
  42. 42. "endpoint": {
  43. 43. "serviceName": "zipkin-query",
  44. 44. "ipv4": "192.168.1.2",
  45. 45. "port": 9411
  46. 46. }
  47. 47. },
  48. 48. {
  49. 49. "key": "request",
  50. 50. "value": "QueryRequest{serviceName=zipkin-query, spanName=null, annotations=[], binaryAnnotations={}, minDuration=null, maxDuration=null, endTs=1458702548478, lookback=86400000, limit=1}",
  51. 51. "endpoint": {
  52. 52. "serviceName": "zipkin-query",
  53. 53. "ipv4": "192.168.1.2",
  54. 54. "port": 9411
  55. 55. }
  56. 56. }
  57. 57. ]
  58. 58. },
  59. 59. {
  60. 60. "traceId": "bd7a977555f6b982",
  61. 61. "name": "query",
  62. 62. "id": "be2d01e33cc78d97",
  63. 63. "parentId": "ebf33e1a81dc6f71",
  64. 64. "timestamp": 1458702548786000,
  65. 65. "duration": 13000,
  66. 66. "annotations": [
  67. 67. {
  68. 68. "endpoint": {
  69. 69. "serviceName": "zipkin-query",
  70. 70. "ipv4": "192.168.1.2",
  71. 71. "port": 9411
  72. 72. },
  73. 73. "timestamp": 1458702548786000,
  74. 74. "value": "cs"
  75. 75. },
  76. 76. {
  77. 77. "endpoint": {
  78. 78. "serviceName": "zipkin-query",
  79. 79. "ipv4": "192.168.1.2",
  80. 80. "port": 9411
  81. 81. },
  82. 82. "timestamp": 1458702548799000,
  83. 83. "value": "cr"
  84. 84. }
  85. 85. ],
  86. 86. "binaryAnnotations": [
  87. 87. {
  88. 88. "key": "jdbc.query",
  89. 89. "value": "select distinct `zipkin_spans`.`trace_id` from `zipkin_spans` join `zipkin_annotations` on (`zipkin_spans`.`trace_id` = `zipkin_annotations`.`trace_id` and `zipkin_spans`.`id` = `zipkin_annotations`.`span_id`) where (`zipkin_annotations`.`endpoint_service_name` = ? and `zipkin_spans`.`start_ts` between ? and ?) order by `zipkin_spans`.`start_ts` desc limit ?",
  90. 90. "endpoint": {
  91. 91. "serviceName": "zipkin-query",
  92. 92. "ipv4": "192.168.1.2",
  93. 93. "port": 9411
  94. 94. }
  95. 95. },
  96. 96. {
  97. 97. "key": "sa",
  98. 98. "value": true,
  99. 99. "endpoint": {
  100. 100. "serviceName": "spanstore-jdbc",
  101. 101. "ipv4": "127.0.0.1",
  102. 102. "port": 3306
  103. 103. }
  104. 104. }
  105. 105. ]
  106. 106. },
  107. 107. {
  108. 108. "traceId": "bd7a977555f6b982",
  109. 109. "name": "query",
  110. 110. "id": "13038c5fee5a2f2e",
  111. 111. "parentId": "ebf33e1a81dc6f71",
  112. 112. "timestamp": 1458702548817000,
  113. 113. "duration": 1000,
  114. 114. "annotations": [
  115. 115. {
  116. 116. "endpoint": {
  117. 117. "serviceName": "zipkin-query",
  118. 118. "ipv4": "192.168.1.2",
  119. 119. "port": 9411
  120. 120. },
  121. 121. "timestamp": 1458702548817000,
  122. 122. "value": "cs"
  123. 123. },
  124. 124. {
  125. 125. "endpoint": {
  126. 126. "serviceName": "zipkin-query",
  127. 127. "ipv4": "192.168.1.2",
  128. 128. "port": 9411
  129. 129. },
  130. 130. "timestamp": 1458702548818000,
  131. 131. "value": "cr"
  132. 132. }
  133. 133. ],
  134. 134. "binaryAnnotations": [
  135. 135. {
  136. 136. "key": "jdbc.query",
  137. 137. "value": "select `zipkin_spans`.`trace_id`, `zipkin_spans`.`id`, `zipkin_spans`.`name`, `zipkin_spans`.`parent_id`, `zipkin_spans`.`debug`, `zipkin_spans`.`start_ts`, `zipkin_spans`.`duration` from `zipkin_spans` where `zipkin_spans`.`trace_id` in (?)",
  138. 138. "endpoint": {
  139. 139. "serviceName": "zipkin-query",
  140. 140. "ipv4": "192.168.1.2",
  141. 141. "port": 9411
  142. 142. }
  143. 143. },
  144. 144. {
  145. 145. "key": "sa",
  146. 146. "value": true,
  147. 147. "endpoint": {
  148. 148. "serviceName": "spanstore-jdbc",
  149. 149. "ipv4": "127.0.0.1",
  150. 150. "port": 3306
  151. 151. }
  152. 152. }
  153. 153. ]
  154. 154. },
  155. 155. {
  156. 156. "traceId": "bd7a977555f6b982",
  157. 157. "name": "query",
  158. 158. "id": "37ee55f3d3a94336",
  159. 159. "parentId": "ebf33e1a81dc6f71",
  160. 160. "timestamp": 1458702548827000,
  161. 161. "duration": 2000,
  162. 162. "annotations": [
  163. 163. {
  164. 164. "endpoint": {
  165. 165. "serviceName": "zipkin-query",
  166. 166. "ipv4": "192.168.1.2",
  167. 167. "port": 9411
  168. 168. },
  169. 169. "timestamp": 1458702548827000,
  170. 170. "value": "cs"
  171. 171. },
  172. 172. {
  173. 173. "endpoint": {
  174. 174. "serviceName": "zipkin-query",
  175. 175. "ipv4": "192.168.1.2",
  176. 176. "port": 9411
  177. 177. },
  178. 178. "timestamp": 1458702548829000,
  179. 179. "value": "cr"
  180. 180. }
  181. 181. ],
  182. 182. "binaryAnnotations": [
  183. 183. {
  184. 184. "key": "jdbc.query",
  185. 185. "value": "select `zipkin_annotations`.`trace_id`, `zipkin_annotations`.`span_id`, `zipkin_annotations`.`a_key`, `zipkin_annotations`.`a_value`, `zipkin_annotations`.`a_type`, `zipkin_annotations`.`a_timestamp`, `zipkin_annotations`.`endpoint_ipv4`, `zipkin_annotations`.`endpoint_port`, `zipkin_annotations`.`endpoint_service_name` from `zipkin_annotations` where `zipkin_annotations`.`trace_id` in (?) order by `zipkin_annotations`.`a_timestamp` asc, `zipkin_annotations`.`a_key` asc",
  186. 186. "endpoint": {
  187. 187. "serviceName": "zipkin-query",
  188. 188. "ipv4": "192.168.1.2",
  189. 189. "port": 9411
  190. 190. }
  191. 191. },
  192. 192. {
  193. 193. "key": "sa",
  194. 194. "value": true,
  195. 195. "endpoint": {
  196. 196. "serviceName": "spanstore-jdbc",
  197. 197. "ipv4": "127.0.0.1",
  198. 198. "port": 3306
  199. 199. }
  200. 200. }
  201. 201. ]
  202. 202. }
  203. 203. ]