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 2021/06/08 07:56:06 UTC

[GitHub] [apisix] spacewander opened a new pull request #4391: feat(mqtt-proxy): support domain

spacewander opened a new pull request #4391:
URL: https://github.com/apache/apisix/pull/4391


   Fix #3964
   
   Signed-off-by: spacewander <sp...@gmail.com>
   
   ### What this PR does / why we need it:
   <!--- Why is this change required? What problem does it solve? -->
   <!--- If it fixes an open issue, please link to the issue here. -->
   
   ### Pre-submission checklist:
   
   * [x] Did you explain what problem does this PR solve? Or what new features have been added?
   * [x] Have you added corresponding test cases?
   * [x] Have you modified the corresponding document?
   * [ ] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
   


-- 
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] tokers merged pull request #4391: feat(mqtt-proxy): support domain

Posted by GitBox <gi...@apache.org>.
tokers merged pull request #4391:
URL: https://github.com/apache/apisix/pull/4391


   


-- 
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] Yiyiyimu commented on a change in pull request #4391: feat(mqtt-proxy): support domain

Posted by GitBox <gi...@apache.org>.
Yiyiyimu commented on a change in pull request #4391:
URL: https://github.com/apache/apisix/pull/4391#discussion_r647739171



##########
File path: docs/zh/latest/plugins/mqtt-proxy.md
##########
@@ -45,7 +45,8 @@ title: mqtt-proxy
 | -------------- | ------- | ------ | ------ | ------ | ------------------------------------------------------ |
 | protocol_name  | string  | 必须   |        |        | 协议名称,正常情况下应为“ MQTT”                        |
 | protocol_level | integer | 必须   |        |        | 协议级别,MQTT `3.1.*` 应为 `4` ,MQTT `5.0` 应是`5`。 |
-| upstream.ip    | string  | 必须   |        |        | 将当前请求转发到的上游的 IP 地址                       |
+| upstream.host  | string  | 必须   |        |        | 将当前请求转发到的上游的 IP 地址或域名                  |
+| upstream.ip    | string  | 必须   |        |        | 推荐使用“host”代替。将当前请求转发到的上游的 IP 地址                       |

Review comment:
       since we only need one of them, naming both of them 'required' might lead to misunderstanding




-- 
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] tokers commented on a change in pull request #4391: feat(mqtt-proxy): support domain

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #4391:
URL: https://github.com/apache/apisix/pull/4391#discussion_r648207010



##########
File path: apisix/stream/plugins/mqtt-proxy.lua
##########
@@ -159,16 +165,38 @@ function _M.preread(conf, ctx)
 
     core.log.info("mqtt client id: ", res.client_id)
 
+    local host = conf.upstream.host
+    if not host then
+        host = conf.upstream.ip
+    end
+
+    if conf.host_is_domain == nil then
+        conf.host_is_domain = not ipmatcher.parse_ipv4(host)
+                              and not ipmatcher.parse_ipv6(host)
+    end
+
+    if conf.host_is_domain then
+        local ip, err = core.resolver.parse_domain(host)
+        if not ip then
+            core.log.error("failed to parse host ", host, ", err: ", err)
+            return 500

Review comment:
       OK, got it.




-- 
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] spacewander commented on a change in pull request #4391: feat(mqtt-proxy): support domain

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #4391:
URL: https://github.com/apache/apisix/pull/4391#discussion_r647910712



##########
File path: apisix/stream/plugins/mqtt-proxy.lua
##########
@@ -159,16 +165,38 @@ function _M.preread(conf, ctx)
 
     core.log.info("mqtt client id: ", res.client_id)
 
+    local host = conf.upstream.host
+    if not host then
+        host = conf.upstream.ip
+    end
+
+    if conf.host_is_domain == nil then
+        conf.host_is_domain = not ipmatcher.parse_ipv4(host)
+                              and not ipmatcher.parse_ipv6(host)
+    end
+
+    if conf.host_is_domain then
+        local ip, err = core.resolver.parse_domain(host)
+        if not ip then
+            core.log.error("failed to parse host ", host, ", err: ", err)
+            return 500

Review comment:
       > Note : we can't invoke ngx.exit or core.respond.exit in rewrite phase and access phase. if need to exit, just return the status and body, the plugin engine will make the exit happen with the returned status and body.
   
   https://github.com/apache/apisix/blob/master/docs/en/latest/plugin-develop.md
   
   We need to fix it like what we have done with the http plugins




-- 
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] tokers commented on a change in pull request #4391: feat(mqtt-proxy): support domain

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #4391:
URL: https://github.com/apache/apisix/pull/4391#discussion_r647892650



##########
File path: apisix/stream/plugins/mqtt-proxy.lua
##########
@@ -159,16 +165,38 @@ function _M.preread(conf, ctx)
 
     core.log.info("mqtt client id: ", res.client_id)
 
+    local host = conf.upstream.host
+    if not host then
+        host = conf.upstream.ip
+    end
+
+    if conf.host_is_domain == nil then
+        conf.host_is_domain = not ipmatcher.parse_ipv4(host)
+                              and not ipmatcher.parse_ipv6(host)
+    end
+
+    if conf.host_is_domain then
+        local ip, err = core.resolver.parse_domain(host)
+        if not ip then
+            core.log.error("failed to parse host ", host, ", err: ", err)
+            return 500

Review comment:
       Other places in this method just call `ngx.exit(1)`, why here we need to return `500`.

##########
File path: apisix/stream/plugins/mqtt-proxy.lua
##########
@@ -159,16 +165,38 @@ function _M.preread(conf, ctx)
 
     core.log.info("mqtt client id: ", res.client_id)
 
+    local host = conf.upstream.host
+    if not host then
+        host = conf.upstream.ip
+    end
+
+    if conf.host_is_domain == nil then
+        conf.host_is_domain = not ipmatcher.parse_ipv4(host)
+                              and not ipmatcher.parse_ipv6(host)
+    end
+
+    if conf.host_is_domain then
+        local ip, err = core.resolver.parse_domain(host)
+        if not ip then
+            core.log.error("failed to parse host ", host, ", err: ", err)
+            return 500
+        end
+
+        host = ip
+    end
+
     local up_conf = {
         type = "roundrobin",
         nodes = {
-            {host = conf.upstream.ip, port = conf.upstream.port, weight = 1},
+            {host = host, port = conf.upstream.port, weight = 1},
         }
     }
 
     local ok, err = upstream.check_schema(up_conf)
     if not ok then
-        return 500, err
+        core.log.error("failed to check schema ", core.json.delay_encode(up_conf),
+                       ", err: ", err)
+        return 500

Review comment:
       Ditto.




-- 
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