diff --git a/COPYRIGHT b/COPYRIGHT index e31ac1f812a61..ad8a171d9dd28 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -239,6 +239,8 @@ Redistributions in binary form must reproduce the above copyright notice, this l THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +%%%%%%%%% + opentracing-openresty https://github.com/iresty/opentracing-openresty diff --git a/doc/plugins/zipkin.md b/doc/plugins/zipkin.md new file mode 100644 index 0000000000000..bcfd4d730b49d --- /dev/null +++ b/doc/plugins/zipkin.md @@ -0,0 +1,92 @@ +# Summary +- [**Name**](#name) +- [**Attributes**](#attributes) +- [**How To Enable**](#how-to-enable) +- [**Test Plugin**](#test-plugin) +- [**Disable Plugin**](#disable-plugin) + + +## Name + +`Zipkin` is a OpenTracing plugin. + +It's also works with `Apache SkyWalking`, which is support Zipkin v1/v2 format. + +## Attributes + +* `endpoint`: the http endpoint of Ziplin, for example: `http://127.0.0.1:9411/api/v2/spans`. + +* `sample_ratio`: the ratio of sample, the default value is 0.001, the minimum is 0.00001, the maximum is 1. + +## How To Enable + +Here's an example, enable the zipkin plugin on the specified route: + +```shell +curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' +{ + "methods": ["GET"], + "uri": "/index.html", + "plugins": { + "zipkin": { + "endpoint": "http://127.0.0.1:9411/api/v2/spans", + "sample_ratio": 1 + } + }, + "upstream": { + "type": "roundrobin", + "nodes": { + "39.97.63.215:80": 1 + } + } +}' +``` + +## Test Plugin + +### run the Zipkin instance + +e.g. using docker: + +``` +sudo docker run -d -p 9411:9411 openzipkin/zipkin +``` + +Here is a test example: + +```shell +$ curl http://127.0.0.1:9080/index.html +HTTP/1.1 200 OK +... +``` + +Then you can use a browser to access the webUI of Zipkin: + +``` +http://127.0.0.1:9411/zipkin +``` + +## Disable Plugin + +When you want to disable the zipkin plugin, it is very simple, + you can delete the corresponding json configuration in the plugin configuration, + no need to restart the service, it will take effect immediately: + +```shell +$ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value=' +{ + "methods": ["GET"], + "uri": "/index.html", + "id": 1, + "plugins": { + }, + "upstream": { + "type": "roundrobin", + "nodes": { + "39.97.63.215:80": 1 + } + } +}' +``` + +The zipkin plugin has been disabled now. It works for other plugins. diff --git a/lua/apisix/core/request.lua b/lua/apisix/core/request.lua index 0071bda607cf7..9ca6c541ab2bc 100644 --- a/lua/apisix/core/request.lua +++ b/lua/apisix/core/request.lua @@ -2,7 +2,7 @@ local ngx = ngx local get_headers = ngx.req.get_headers - +local tonumber = tonumber local _M = {version = 0.1} diff --git a/lua/apisix/core/response.lua b/lua/apisix/core/response.lua index 2e23096c9649c..d17f385af78fe 100644 --- a/lua/apisix/core/response.lua +++ b/lua/apisix/core/response.lua @@ -11,6 +11,7 @@ local ngx_exit = ngx.exit local insert_tab = table.insert local concat_tab = table.concat local str_sub = string.sub +local tonumber = tonumber local _M = {version = 0.1} diff --git a/lua/apisix/plugins/zipkin.lua b/lua/apisix/plugins/zipkin.lua index 5b405334493ac..534da6126418d 100644 --- a/lua/apisix/plugins/zipkin.lua +++ b/lua/apisix/plugins/zipkin.lua @@ -3,6 +3,8 @@ local new_tracer = require("opentracing.tracer").new local zipkin_codec = require("apisix.plugins.zipkin.codec") local new_random_sampler = require("apisix.plugins.zipkin.random_sampler").new local new_reporter = require("apisix.plugins.zipkin.reporter").new +local ngx = ngx +local pairs = pairs local plugin_name = "zipkin" diff --git a/t/admin/plugins.t b/t/admin/plugins.t index 158bba6ddb9f7..68ac848d3a576 100644 --- a/t/admin/plugins.t +++ b/t/admin/plugins.t @@ -14,6 +14,6 @@ __DATA__ --- request GET /apisix/admin/plugins/list --- response_body_like eval -qr/example-plugin","limit-req","limit-count","key-auth","prometheus","limit-conn","node-status"/ +qr/\["example-plugin","limit-req","limit-count","limit-conn","key-auth","prometheus","node-status","jwt-auth","zipkin"\]/ --- no_error_log [error]