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/09/07 12:27:34 UTC

[GitHub] [apisix] Zheaoli opened a new pull request #5011: [WIP] add new dump config api for control api

Zheaoli opened a new pull request #5011:
URL: https://github.com/apache/apisix/pull/5011


   ### 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?
   * [ ] 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**
   
   Add new API for dumping config in control api
   


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



[GitHub] [apisix] spacewander commented on a change in pull request #5011: feat(control): add new dump route config api for control api

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



##########
File path: t/control/routes.t
##########
@@ -0,0 +1,171 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("info");
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    config_center: yaml
+    enable_admin: false
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if (!$block->request) {
+        $block->set_value("request", "GET /t");
+    }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: routes
+--- apisix_yaml
+routes:
+  -
+    id: 1
+    uris:
+        - /hello
+    upstream:
+      nodes:
+        "127.0.0.1:1980": 1
+        "127.0.0.1:1988": 1
+      type: roundrobin
+      checks:
+        active:
+            http_path: "/status"
+            host: "127.0.0.1"
+            healthy:
+                interval: 1
+                successes: 1
+            unhealthy:
+                interval: 1
+                http_failures: 1
+#END
+--- config
+    location /t {
+        content_by_lua_block {
+            local json = require("toolkit.json")
+            local t = require("lib.test_admin")
+            local code, body, res = t.test('/v1/routes',
+                ngx.HTTP_GET)
+            res = json.decode(res)
+            if res[1] then
+                local data = {}
+                data.uris = res[1].value.uris

Review comment:
       We should also check the upstream part

##########
File path: docs/en/latest/control-api.md
##########
@@ -204,3 +204,160 @@ Introduced since `v2.8`.
 
 Trigger a full GC in the http subsystem.
 Note that when you enable stream proxy, APISIX will run another Lua VM for the stream subsystem. It won't trigger a full GC in this Lua VM .
+
+### Get /v1/routes
+
+Introduced since `v3.0`.
+
+Return all routes info in the format below:
+
+```json
+[
+  {
+    "value": {
+      "uris": [
+        "/hello"
+      ],
+      "id": "1",
+      "upstream": {
+        "scheme": "http",
+        "checks": {

Review comment:
       The example here is too long to focus on the point. Can we remove the healthcheck part?

##########
File path: apisix/control/v1.lua
##########
@@ -156,6 +156,40 @@ function _M.get_health_checker()
     return 200, info
 end
 
+local function iter_add_get_routes_info(infos, values, route_id)

Review comment:
       The infos can be created inside this function, and there is no need to pass out a flag -- use nil if route_id given but not matched.

##########
File path: t/control/routes.t
##########
@@ -0,0 +1,171 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("info");
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    config_center: yaml
+    enable_admin: false
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if (!$block->request) {
+        $block->set_value("request", "GET /t");
+    }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: routes
+--- apisix_yaml
+routes:
+  -
+    id: 1
+    uris:
+        - /hello
+    upstream:
+      nodes:
+        "127.0.0.1:1980": 1
+        "127.0.0.1:1988": 1
+      type: roundrobin
+      checks:
+        active:
+            http_path: "/status"
+            host: "127.0.0.1"
+            healthy:
+                interval: 1
+                successes: 1
+            unhealthy:
+                interval: 1
+                http_failures: 1
+#END
+--- config
+    location /t {
+        content_by_lua_block {
+            local json = require("toolkit.json")
+            local t = require("lib.test_admin")
+            local code, body, res = t.test('/v1/routes',
+                ngx.HTTP_GET)
+            res = json.decode(res)
+            if res[1] then
+                local data = {}
+                data.uris = res[1].value.uris
+                ngx.say(json.encode(data))
+            end
+        }
+    }
+--- response_body
+{"uris":["/hello"]}
+
+
+
+=== TEST 2: get route with id 1
+--- apisix_yaml
+routes:
+  -
+    id: 1
+    uris:
+        - /hello
+    upstream:
+      nodes:
+        "127.0.0.1:1980": 1
+        "127.0.0.1:1988": 1
+      type: roundrobin
+      checks:
+        active:
+            http_path: "/status"
+            host: "127.0.0.1"
+            healthy:
+                interval: 1
+                successes: 1
+            unhealthy:
+                interval: 1
+                http_failures: 1
+#END
+--- config
+    location /t {
+        content_by_lua_block {
+            local json = require("toolkit.json")
+            local t = require("lib.test_admin")
+            local code, body, res = t.test('/v1/route/1',
+                ngx.HTTP_GET)
+            res = json.decode(res)
+            if res then
+                local data = {}
+                data.uris = res.value.uris
+                ngx.say(json.encode(data))
+            end
+        }
+    }
+--- response_body
+{"uris":["/hello"]}
+
+
+
+=== TEST 3: routes with invalid id
+--- apisix_yaml
+routes:
+  -
+    id: 1
+    uris:
+        - /hello
+    upstream:
+      nodes:
+        "127.0.0.1:1980": 1
+        "127.0.0.1:1988": 1
+      type: roundrobin
+      checks:

Review comment:
       We don't need to define a long upstream for a test just check if the route exists




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



[GitHub] [apisix] spacewander merged pull request #5011: feat(control): add new dump route config api for control api

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


   


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



[GitHub] [apisix] Zheaoli commented on a change in pull request #5011: feat(control): add new dump route config api for control api

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



##########
File path: docs/en/latest/control-api.md
##########
@@ -204,3 +204,160 @@ Introduced since `v2.8`.
 
 Trigger a full GC in the http subsystem.
 Note that when you enable stream proxy, APISIX will run another Lua VM for the stream subsystem. It won't trigger a full GC in this Lua VM .
+
+### Get /v1/routes
+
+Introduced since `v3.0`.
+
+Return all routes info in the format below:
+
+```json
+[
+  {
+    "value": {
+      "uris": [
+        "/hello"
+      ],
+      "id": "1",
+      "upstream": {
+        "scheme": "http",
+        "checks": {

Review comment:
       of course




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



[GitHub] [apisix] spacewander commented on a change in pull request #5011: [WIP] add new dump config api for control api

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



##########
File path: apisix/control/v1.lua
##########
@@ -189,4 +212,10 @@ return {
         uris = {"/gc"},
         handler = _M.trigger_gc,
     },
+    -- /v1/dump

Review comment:
       Please use restful like API names for dump specific resources, like `/v1/upstreams/xxx` and `/v1/upstreams`.

##########
File path: apisix/control/v1.lua
##########
@@ -156,6 +157,28 @@ function _M.get_health_checker()
     return 200, info
 end
 
+local function iter_add_get_routes_info(infos, values)
+    local temp_infos = {}
+    for _, route in core.config_util.iterate_values(values) do
+        local new_route = copy.deepcopy(route)

Review comment:
       We already have `core.table.deepcopy`




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



[GitHub] [apisix] spacewander commented on a change in pull request #5011: feat(control): add new dump route config api for control api

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



##########
File path: apisix/control/v1.lua
##########
@@ -156,6 +156,42 @@ function _M.get_health_checker()
     return 200, info
 end
 
+local function iter_add_get_routes_info(values, route_id)
+    local infos = {}
+    for _, route in core.config_util.iterate_values(values) do
+        local new_route = core.table.deepcopy(route)
+        if new_route.value.upstream and new_route.value.upstream.parent then
+            new_route.value.upstream.parent = nil
+        end
+        core.table.insert(infos, new_route)
+        if route_id and route.value.id == route_id then
+            return new_route, true
+        end
+    end
+    if not route_id then
+        return infos, true
+    end
+    return nil, false

Review comment:
       We don't need a flag, just check the first result is nil or not

##########
File path: t/control/routes.t
##########
@@ -0,0 +1,171 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("info");
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    config_center: yaml
+    enable_admin: false
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if (!$block->request) {
+        $block->set_value("request", "GET /t");
+    }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: routes
+--- apisix_yaml
+routes:
+  -
+    id: 1
+    uris:
+        - /hello
+    upstream:
+      nodes:
+        "127.0.0.1:1980": 1
+        "127.0.0.1:1988": 1
+      type: roundrobin
+      checks:
+        active:
+            http_path: "/status"
+            host: "127.0.0.1"
+            healthy:
+                interval: 1
+                successes: 1
+            unhealthy:
+                interval: 1
+                http_failures: 1
+#END
+--- config
+    location /t {
+        content_by_lua_block {
+            local json = require("toolkit.json")
+            local t = require("lib.test_admin")
+            local code, body, res = t.test('/v1/routes',
+                ngx.HTTP_GET)
+            res = json.decode(res)
+            if res[1] then
+                local data = {}
+                data.uris = res[1].value.uris

Review comment:
       Need to check the upstream part too




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