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/08 09:57:14 UTC
[GitHub] [apisix] sshniro opened a new pull request #2026: Adding request id plugin to uniquely track requests in APISIX
sshniro opened a new pull request #2026:
URL: https://github.com/apache/apisix/pull/2026
### What this PR does / why we need it:
Resolves #2018
----------------------------------------------------------------
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
[GitHub] [apisix] moonming commented on pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
moonming commented on pull request #2026:
URL: https://github.com/apache/apisix/pull/2026#issuecomment-671207895
got it, thanks for your explanation
Thanks,
Ming Wen
Twitter: _WenMing
Nirojan Selvanathan <no...@github.com> 于2020年8月10日周一 下午3:36写道:
> @moonming <https://github.com/moonming> the requirement is to provide
> customers and API consumers with a request ID to report any API failures.
> This will helps to easily track down the root cause.
>
> Many provide such id with each request, the following is a format provided
> by AWS
> <https://aws.amazon.com/premiumsupport/knowledge-center/s3-request-id-values/>
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/apache/apisix/pull/2026#issuecomment-671206915>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AGJZBK7KWOUFOQCNH2ZN5JDR76PPPANCNFSM4PYSPUGA>
> .
>
----------------------------------------------------------------
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
[GitHub] [apisix] sshniro commented on pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
sshniro commented on pull request #2026:
URL: https://github.com/apache/apisix/pull/2026#issuecomment-671206915
@moonming the requirement is to provide customers and API consumers with a request ID to report any API failures. This will helps to easily track down the root cause.
Many provide such id with each request, the following is a format provided by [AWS](https://aws.amazon.com/premiumsupport/knowledge-center/s3-request-id-values/)
----------------------------------------------------------------
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
[GitHub] [apisix] sshniro edited a comment on pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
sshniro edited a comment on pull request #2026:
URL: https://github.com/apache/apisix/pull/2026#issuecomment-671206915
@moonming the requirement is to provide customers and API consumers with a request ID to report any API failures. This helps to easily track down the root cause. Therefore, yes this helps to trace requests.
Many provide such id with each request, the following is a format provided by [AWS](https://aws.amazon.com/premiumsupport/knowledge-center/s3-request-id-values/)
----------------------------------------------------------------
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
[GitHub] [apisix] sshniro commented on a change in pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
sshniro commented on a change in pull request #2026:
URL: https://github.com/apache/apisix/pull/2026#discussion_r467733759
##########
File path: apisix/plugins/request-id.lua
##########
@@ -0,0 +1,67 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local plugin_name = "request-id"
+local ngx = ngx
+local uuid = require("resty.jit-uuid")
+
+local schema = {
+ type = "object",
+ properties = {
+ header_name = {type = "string", default = "X-Request-Id"},
+ include_in_response = {type = "boolean", default = false}
Review comment:
agreed.
----------------------------------------------------------------
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
[GitHub] [apisix] sshniro commented on pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
sshniro commented on pull request #2026:
URL: https://github.com/apache/apisix/pull/2026#issuecomment-671208112
@membphis small question why does consequent calls to the endpoint returns the same value to the header? However if I call this endpoint via curl I do get different results. Is this something related to UUID seed not getting set in unit tests?
```shell
=== TEST X: 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 .. "/opentracing"
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",
}
})
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
unique request id
--- 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
[GitHub] [apisix] sshniro commented on pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
sshniro commented on pull request #2026:
URL: https://github.com/apache/apisix/pull/2026#issuecomment-671884797
@membphis thanks, pending issues have been fixed now.
----------------------------------------------------------------
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
[GitHub] [apisix] membphis commented on a change in pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
membphis commented on a change in pull request #2026:
URL: https://github.com/apache/apisix/pull/2026#discussion_r467522195
##########
File path: apisix/plugins/request-id.lua
##########
@@ -0,0 +1,67 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local plugin_name = "request-id"
+local ngx = ngx
+local uuid = require("resty.jit-uuid")
+
+local schema = {
+ type = "object",
+ properties = {
+ header_name = {type = "string", default = "X-Request-Id"},
+ include_in_response = {type = "boolean", default = false}
Review comment:
I think the default value should be `true`.
----------------------------------------------------------------
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
[GitHub] [apisix] membphis commented on a change in pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
membphis commented on a change in pull request #2026:
URL: https://github.com/apache/apisix/pull/2026#discussion_r467442848
##########
File path: apisix/plugins/request-id.lua
##########
@@ -0,0 +1,67 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local plugin_name = "request-id"
+local ngx = ngx
+local uuid = require("resty.jit-uuid")
+
+local schema = {
+ type = "object",
+ properties = {
+ header_name = {type = "string", default = "X-Request-Id"},
+ include_in_response = {type = "boolean", default = false}
+ }
+}
+
+
+local _M = {
+ version = 0.1,
+ priority = 11010,
+ name = plugin_name,
+ schema = schema,
+}
+
+
+function _M.check_schema(conf)
+ return core.schema.check(schema, conf)
+end
+
+
+function _M.rewrite(conf)
+ local headers = ngx.req.get_headers()
+ uuid.seed()
Review comment:
we have set the right `seed`, so we do not need to set it again:
https://github.com/apache/apisix/blob/master/apisix/init.lua#L71
let we remove it.
##########
File path: apisix/plugins/request-id.lua
##########
@@ -0,0 +1,67 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local plugin_name = "request-id"
+local ngx = ngx
+local uuid = require("resty.jit-uuid")
+
+local schema = {
+ type = "object",
+ properties = {
+ header_name = {type = "string", default = "X-Request-Id"},
+ include_in_response = {type = "boolean", default = false}
+ }
+}
+
+
+local _M = {
+ version = 0.1,
+ priority = 11010,
+ name = plugin_name,
+ schema = schema,
+}
+
+
+function _M.check_schema(conf)
+ return core.schema.check(schema, conf)
+end
+
+
+function _M.rewrite(conf)
+ local headers = ngx.req.get_headers()
+ uuid.seed()
+ local uuid_val = uuid()
+ if not headers[conf.header_name] then
+ core.request.set_header(conf.header_name, uuid_val)
+ end
+
+ if conf.include_in_response then
+ ngx.ctx.api_ctx.x_request_id = uuid_val
Review comment:
`ctx.x_request_id = uuid_val`, simpler way
##########
File path: apisix/plugins/request-id.lua
##########
@@ -0,0 +1,67 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local plugin_name = "request-id"
+local ngx = ngx
+local uuid = require("resty.jit-uuid")
+
+local schema = {
+ type = "object",
+ properties = {
+ header_name = {type = "string", default = "X-Request-Id"},
+ include_in_response = {type = "boolean", default = false}
+ }
+}
+
+
+local _M = {
+ version = 0.1,
+ priority = 11010,
+ name = plugin_name,
+ schema = schema,
+}
+
+
+function _M.check_schema(conf)
+ return core.schema.check(schema, conf)
+end
+
+
+function _M.rewrite(conf)
Review comment:
`_M.rewrite(conf)` -> `_M.rewrite(conf, ctx)`
##########
File path: apisix/plugins/request-id.lua
##########
@@ -0,0 +1,67 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local plugin_name = "request-id"
+local ngx = ngx
+local uuid = require("resty.jit-uuid")
+
+local schema = {
+ type = "object",
+ properties = {
+ header_name = {type = "string", default = "X-Request-Id"},
+ include_in_response = {type = "boolean", default = false}
+ }
+}
+
+
+local _M = {
+ version = 0.1,
+ priority = 11010,
+ name = plugin_name,
+ schema = schema,
+}
+
+
+function _M.check_schema(conf)
+ return core.schema.check(schema, conf)
+end
+
+
+function _M.rewrite(conf)
+ local headers = ngx.req.get_headers()
+ uuid.seed()
+ local uuid_val = uuid()
+ if not headers[conf.header_name] then
+ core.request.set_header(conf.header_name, uuid_val)
+ end
+
+ if conf.include_in_response then
+ ngx.ctx.api_ctx.x_request_id = uuid_val
+ end
+end
+
+
+function _M.header_filter(conf, ctx)
+ if conf.include_in_response then
Review comment:
another style:
```lua
if not conf.include_in_response then
return
end
local headers = ngx.resp.get_headers()
if not headers[conf.header_name] then
core.response.set_header(conf.header_name, ctx.x_request_id)
end
```
----------------------------------------------------------------
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
[GitHub] [apisix] sshniro edited a comment on pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
sshniro edited a comment on pull request #2026:
URL: https://github.com/apache/apisix/pull/2026#issuecomment-671206915
@moonming the requirement is to provide customers and API consumers with a request ID to report any API failures. This will helps to easily track down the root cause. Therefore, yes this helps to trace requests.
Many provide such id with each request, the following is a format provided by [AWS](https://aws.amazon.com/premiumsupport/knowledge-center/s3-request-id-values/)
----------------------------------------------------------------
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
[GitHub] [apisix] moonming commented on pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
moonming commented on pull request #2026:
URL: https://github.com/apache/apisix/pull/2026#issuecomment-670995043
Is this PR for tracing like skywalking or zipkin?
YuanSheng Wang <no...@github.com> 于 2020年8月9日周日 上午9:23写道:
> *@membphis* commented on this pull request.
> ------------------------------
>
> In apisix/plugins/request-id.lua
> <https://github.com/apache/apisix/pull/2026#discussion_r467522195>:
>
> > +-- Unless required by applicable law or agreed to in writing, software
> +-- distributed under the License is distributed on an "AS IS" BASIS,
> +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +-- See the License for the specific language governing permissions and
> +-- limitations under the License.
> +--
> +local core = require("apisix.core")
> +local plugin_name = "request-id"
> +local ngx = ngx
> +local uuid = require("resty.jit-uuid")
> +
> +local schema = {
> + type = "object",
> + properties = {
> + header_name = {type = "string", default = "X-Request-Id"},
> + include_in_response = {type = "boolean", default = false}
>
> I think the default value should be true.
>
> —
> You are receiving this because your review was requested.
> Reply to this email directly, view it on GitHub
> <https://github.com/apache/apisix/pull/2026#pullrequestreview-463836184>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AGJZBK2XE4FZ4FIEWX5GKFLR7X27PANCNFSM4PYSPUGA>
> .
>
----------------------------------------------------------------
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
[GitHub] [apisix] membphis commented on pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
membphis commented on pull request #2026:
URL: https://github.com/apache/apisix/pull/2026#issuecomment-672932439
@sshniro nice PR, merged already
----------------------------------------------------------------
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
[GitHub] [apisix] membphis merged pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
membphis merged pull request #2026:
URL: https://github.com/apache/apisix/pull/2026
----------------------------------------------------------------
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
[GitHub] [apisix] membphis commented on pull request #2026: Adding request id plugin to uniquely track requests in APISIX
Posted by GitBox <gi...@apache.org>.
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