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/10/19 03:26:05 UTC

[GitHub] [apisix] juzhiyuan commented on a change in pull request #5259: feat: add dump upstream api in control api

juzhiyuan commented on a change in pull request #5259:
URL: https://github.com/apache/apisix/pull/5259#discussion_r731463742



##########
File path: apisix/control/v1.lua
##########
@@ -193,7 +193,45 @@ function _M.dump_route_info()
     return 200, route
 end
 
+local function iter_add_get_upstream_info(values, upstream_id)
+    if not values then
+        return nil
+    end
 
+    local infos = {}
+    for _, upstream in core.config_util.iterate_values(values) do
+        local new_upstream = core.table.deepcopy(upstream)
+        core.table.insert(infos, new_upstream)
+        if new_upstream.value and new_upstream.value.parent then
+            new_upstream.value.parent = nil
+        end
+        -- check the upstream id
+        if upstream_id and upstream.value.id == upstream_id then
+            return new_upstream
+        end
+    end
+    if not upstream_id then
+        return infos
+    end
+    return nil
+end
+
+function _M.dump_all_upstreams_info()
+    local upstreams = get_upstreams()
+    local infos = iter_add_get_upstream_info(upstreams, nil)
+    return 200, infos
+end
+
+function _M.dump_upstream_info()
+    local upstreams = get_upstreams()
+    local uri_segs = core.utils.split_uri(ngx_var.uri)
+    local upstream_id = uri_segs[4]
+    local upstream = iter_add_get_upstream_info(upstreams, upstream_id)
+    if not upstream then
+        return 404, {error_msg = str_format("upstream[%s] not found", upstream_id)}

Review comment:
       Do we need a space like `upstream [%s]`?

##########
File path: docs/en/latest/control-api.md
##########
@@ -283,3 +283,83 @@ Return specific route info with **route_id** in the format below:
   "key": "/routes/1"
 }
 ```
+
+### Get /v1/upstreams
+
+Introduced since `v2.11.0`.
+
+Return all upstreams info in the format below:
+
+```json
+[
+   {
+      "value":{
+         "scheme":"http",
+         "pass_host":"pass",
+         "nodes":[
+            {
+               "host":"127.0.0.1",
+               "port":80,
+               "weight":1
+            },
+            {
+               "host":"foo.com",
+               "port":80,
+               "weight":2
+            }
+         ],
+         "hash_on":"vars",
+         "update_time":1634543819,
+         "key":"remote_addr",
+         "create_time":1634539759,
+         "id":"1",
+         "type":"chash"
+      },
+      "has_domain":true,
+      "key":"\/apisix\/upstreams\/1",
+      "clean_handlers":{
+      },
+      "createdIndex":938,
+      "modifiedIndex":1225
+   }
+]
+```
+
+### Get /v1/upstream/{upstream_id}
+
+Introduced since `v2.11.0`.
+
+Return specific upstream info with **upstream_id** in the format below:

Review comment:
       ```suggestion
   Dump specific upstream info with **upstream_id** in the format below:
   ```

##########
File path: docs/en/latest/control-api.md
##########
@@ -283,3 +283,83 @@ Return specific route info with **route_id** in the format below:
   "key": "/routes/1"
 }
 ```
+
+### Get /v1/upstreams
+
+Introduced since `v2.11.0`.
+
+Return all upstreams info in the format below:

Review comment:
       ```suggestion
   Dump all upstreams in the format below:
   ```

##########
File path: apisix/control/v1.lua
##########
@@ -193,7 +193,45 @@ function _M.dump_route_info()
     return 200, route
 end
 
+local function iter_add_get_upstream_info(values, upstream_id)

Review comment:
       How about using `data` or `value` instead of `_info`?




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

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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