You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/08/10 11:20:20 UTC

[GitHub] [apisix] membphis commented on pull request #2026: Adding request id plugin to uniquely track requests in APISIX

membphis commented on pull request #2026:
URL: https://github.com/apache/apisix/pull/2026#issuecomment-671297565


   It works fine at my side. And we got different `request id` in test case `2`.
   
   I think you can append those test cases.
   
   ```
   === TEST 1: enable request-id with default value
   --- config
       location /t {
           content_by_lua_block {
               local t = require("lib.test_admin").test
               local code, body = t('/apisix/admin/routes/1',
                    ngx.HTTP_PUT,
                    [[{
                           "plugins": {
                               "request-id": {
                               }
                           },
                           "upstream": {
                               "nodes": {
                                   "127.0.0.1:1982": 1
                               },
                               "type": "roundrobin"
                           },
                           "uri": "/hello"
                   }]]
                   )
   
               if code >= 300 then
                   ngx.status = code
               end
               ngx.say(body)
           }
       }
   --- request
   GET /t
   --- response_body
   passed
   --- no_error_log
   [error]
   
   
   
   === TEST 2: check for unique id
   --- config
       location /t {
           content_by_lua_block {
               local http = require "resty.http"
               local httpc = http.new()
               local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
               local res1, err1 = httpc:request_uri(uri,
                   {
                       method = "GET",
                       headers = {
                           ["Content-Type"] = "application/json",
                       }
                   }
               )
               local res2, err2 = httpc:request_uri(uri,
                   {
                       method = "GET",
                       headers = {
                           ["Content-Type"] = "application/json",
                       }
                   }
               )
   
               -- ngx.say("res1: ", res1.headers["X-Request-Id"])
               -- ngx.say("res2: ", res2.headers["X-Request-Id"])
               if res1.headers["X-Request-Id"] == res2.headers["X-Request-Id"] then
                   ngx.say("unique request id")
               else
                   ngx.say("failed")
               end
           }
       }
   --- request
   GET /t
   --- response_body
   failed
   --- no_error_log
   [error]
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org