Kong[nginx]-09 zipkin插件體驗


KONG專題目錄


Zipkin是什么?
Zipkin is a distributed tracing system. It helps gather timing data needed to troubleshoot latency problems in service architectures. Features include both the collection and lookup of this data.

Zipkin是分布式跟蹤系統(tǒng).幫助解決微服務系統(tǒng)中的數(shù)據(jù)接口時間消耗問題.包含數(shù)據(jù)收集和查詢等功能.

0x00 本文目標

  • 配置kong的zipkin插件
  • 發(fā)起指定格式的接口請求, 向zipkin服務提交有效記錄數(shù)據(jù)

0x01 配置插件

如果看過前面幾篇文章, 再向kong添加插件就會非常容易.
這里我們添加一個全局插件(可以監(jiān)聽所有接口請求).


插件列表
選擇zipkin

配置endpoint

假設我們的zipkin服務也是搭建在, 與kong相同的服務器.
那么在彈出框中http_endpoint位置輸入 http://localhost:9411/api/v2/spans, 并提交即可.
確認插件配置

0x02 關于驗證

前幾次試驗失敗的原因是: 簡單的認為zipkin插件配置后, 就可以直接監(jiān)聽所有接口了.今天再次閱讀了zipkin插件的官方說明 ,才明白一個事情:
zipkin插件會監(jiān)聽指定格式的請求, 才會向zipkin服務提交監(jiān)控數(shù)據(jù).

  • 那么問題來了, 具體格式是什么樣子哩 ?

The Zipkin plugin is derived from an OpenTracing base.
A tracer is created with the "http_headers" formatter set to use the headers described in b3-propagation

詳細內(nèi)容請到這里閱讀.

這里只舉個最簡單的例子:

X-B3-TraceId: 80f198ee56343ba864fe8b2a57d3eff7
X-B3-ParentSpanId: 05e3ac9a4f6e3b90
X-B3-SpanId: e457b5a2e4d86bd1
X-B3-Sampled: 1

需要注意的是, openzipkin 里對上面的參數(shù)長度是有限定的:

TraceId
The TraceId is 64 or 128-bit in length and indicates the overall ID of the trace. Every span in a trace shares this ID.

SpanId
The SpanId is 64-bit in length and indicates the position of the current operation in the trace tree. The value should not be interpreted: it may or may not be derived from the value of the TraceId.

ParentSpanId
The ParentSpanId is 64-bit in length and indicates the position of the parent operation in the trace tree. When the span is the root of the trace tree, there is no ParentSpanId.

0x03 驗證

把上一步中介紹的header參數(shù)添加到的我們的測試接口, 并發(fā)請求:

curl -i http://cc/v1/user/get -H X-B3-TraceId:80f198ee56343ba864fe8b2a57d3eff7 -H X-B3-ParentSpanId:05e3ac9a4f6e3b90 -H X-B3-SpanId:e457b5a2e4d86bd1 -H X-B3-Sampled:1
命令行請求

從接口返回上來看, 沒什么不同.

但是這時, 我們在后臺數(shù)據(jù)庫, 和zipkin的UI畫面, 已經(jīng)能看到請求的信息了 _

數(shù)據(jù)庫變化
接口提交成功
接口請求信息

0x04 后記

這篇體驗篇算是告一段落了.

但是, 這樣的使用體驗, 顯然不能用于生產(chǎn)啊.
因為, 目前為止, 我還不知道如何正確生成 traceId, spanId信息 -_-!!!

另外, 在SpringBoot中,也有關于zipkin的支持了.更大的可能性是使用SpringBoot 去集成zipkin功能了.

下一篇, 打算進入自定義插件開發(fā)的領域.畢竟,不會開發(fā)的后端,不是好打野.


KONG專題目錄


最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容