You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/04/02 01:01:42 UTC
[apisix] branch master updated: feat: add management fields for
stream_route and proto in schema (#3966)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 9a68bd3 feat: add management fields for stream_route and proto in schema (#3966)
9a68bd3 is described below
commit 9a68bd38628ca03c0c7c58c7813c2743301b3966
Author: nic-chen <33...@users.noreply.github.com>
AuthorDate: Fri Apr 2 09:01:31 2021 +0800
feat: add management fields for stream_route and proto in schema (#3966)
---
apisix/admin/proto.lua | 10 ++++++++++
apisix/admin/stream_routes.lua | 10 ++++++++++
apisix/schema_def.lua | 7 +++++++
t/admin/schema.t | 20 ++++++++++++++++++++
t/admin/stream-routes.t | 22 ++++++++++++++++++++++
t/plugin/grpc-transcode.t | 8 ++++++++
6 files changed, 77 insertions(+)
diff --git a/apisix/admin/proto.lua b/apisix/admin/proto.lua
index 2095c1f..f9a4eb9 100644
--- a/apisix/admin/proto.lua
+++ b/apisix/admin/proto.lua
@@ -17,6 +17,7 @@
local type = type
local ipairs = ipairs
local core = require("apisix.core")
+local utils = require("apisix.admin.utils")
local get_routes = require("apisix.router").http_routes
local get_services = require("apisix.http.service").services
local tostring = tostring
@@ -63,6 +64,12 @@ function _M.put(id, conf)
end
local key = "/proto/" .. id
+
+ local ok, err = utils.inject_conf_with_prev_conf("proto", key, conf)
+ if not ok then
+ return 500, {error_msg = err}
+ end
+
local res, err = core.etcd.set(key, conf)
if not res then
core.log.error("failed to put proto[", key, "]: ", err)
@@ -96,6 +103,9 @@ function _M.post(id, conf)
end
local key = "/proto"
+
+ utils.inject_timestamp(conf)
+
-- core.log.info("key: ", key)
local res, err = core.etcd.push("/proto", conf)
if not res then
diff --git a/apisix/admin/stream_routes.lua b/apisix/admin/stream_routes.lua
index b768c8a..2a00893 100644
--- a/apisix/admin/stream_routes.lua
+++ b/apisix/admin/stream_routes.lua
@@ -15,6 +15,7 @@
-- limitations under the License.
--
local core = require("apisix.core")
+local utils = require("apisix.admin.utils")
local schema_plugin = require("apisix.admin.plugins").stream_check_schema
local tostring = tostring
@@ -86,6 +87,12 @@ function _M.put(id, conf)
end
local key = "/stream_routes/" .. id
+
+ local ok, err = utils.inject_conf_with_prev_conf("stream_routes", key, conf)
+ if not ok then
+ return 500, {error_msg = err}
+ end
+
local res, err = core.etcd.set(key, conf)
if not res then
core.log.error("failed to put stream route[", key, "]: ", err)
@@ -119,6 +126,9 @@ function _M.post(id, conf)
end
local key = "/stream_routes"
+
+ utils.inject_timestamp(conf)
+
local res, err = core.etcd.push("/stream_routes", conf)
if not res then
core.log.error("failed to post stream route[", key, "]: ", err)
diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua
index bb76523..f26ef3c 100644
--- a/apisix/schema_def.lua
+++ b/apisix/schema_def.lua
@@ -664,6 +664,10 @@ _M.ssl = {
_M.proto = {
type = "object",
properties = {
+ id = id_schema,
+ desc = desc_def,
+ create_time = timestamp_def,
+ update_time = timestamp_def,
content = {
type = "string", minLength = 1, maxLength = 1024*1024
}
@@ -690,6 +694,9 @@ _M.stream_route = {
type = "object",
properties = {
id = id_schema,
+ desc = desc_def,
+ create_time = timestamp_def,
+ update_time = timestamp_def,
remote_addr = remote_addr_def,
server_addr = {
description = "server IP",
diff --git a/t/admin/schema.t b/t/admin/schema.t
index 0a8896d..83d1b7e 100644
--- a/t/admin/schema.t
+++ b/t/admin/schema.t
@@ -291,3 +291,23 @@ GET /apisix/admin/schema/global_rule
qr/("update_time":\{"type":"integer"\}.*"create_time":\{"type":"integer"\}|"create_time":\{"type":"integer"\}.*"update_time":\{"type":"integer"\})/
--- no_error_log
[error]
+
+
+
+=== TEST 16: get proto schema to check if it contains `create_time` and `update_time`
+--- request
+GET /apisix/admin/schema/proto
+--- response_body eval
+qr/("update_time":\{"type":"integer"\}.*"create_time":\{"type":"integer"\}|"create_time":\{"type":"integer"\}.*"update_time":\{"type":"integer"\})/
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: get stream_route schema to check if it contains `create_time` and `update_time`
+--- request
+GET /apisix/admin/schema/stream_route
+--- response_body eval
+qr/("update_time":\{"type":"integer"\}.*"create_time":\{"type":"integer"\}|"create_time":\{"type":"integer"\}.*"update_time":\{"type":"integer"\})/
+--- no_error_log
+[error]
diff --git a/t/admin/stream-routes.t b/t/admin/stream-routes.t
index 013af48..da3d041 100644
--- a/t/admin/stream-routes.t
+++ b/t/admin/stream-routes.t
@@ -31,10 +31,12 @@ __DATA__
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
+ local etcd = require("apisix.core.etcd")
local code, body = t('/apisix/admin/stream_routes/1',
ngx.HTTP_PUT,
[[{
"remote_addr": "127.0.0.1",
+ "desc": "test-desc",
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
@@ -47,6 +49,7 @@ __DATA__
"node": {
"value": {
"remote_addr": "127.0.0.1",
+ "desc": "test-desc",
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
@@ -63,6 +66,13 @@ __DATA__
ngx.status = code
ngx.say(body)
+
+ local res = assert(etcd.get('/stream_routes/1'))
+ local create_time = res.body.node.value.create_time
+ assert(create_time ~= nil, "create_time is nil")
+ local update_time = res.body.node.value.update_time
+ assert(update_time ~= nil, "update_time is nil")
+
}
}
--- request
@@ -142,6 +152,7 @@ GET /t
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
+ local etcd = require("apisix.core.etcd")
local code, message, res = t('/apisix/admin/stream_routes',
ngx.HTTP_POST,
[[{
@@ -180,6 +191,13 @@ GET /t
ngx.say("[push] code: ", code, " message: ", message)
local id = string.sub(res.node.key, #"/apisix/stream_routes/" + 1)
+
+ local ret = assert(etcd.get('/stream_routes/' .. id))
+ local create_time = ret.body.node.value.create_time
+ assert(create_time ~= nil, "create_time is nil")
+ local update_time = ret.body.node.value.update_time
+ assert(update_time ~= nil, "update_time is nil")
+
code, message = t('/apisix/admin/stream_routes/' .. id,
ngx.HTTP_DELETE,
nil,
@@ -497,7 +515,11 @@ GET /t
res = json.decode(res)
assert(res.count ~= nil)
+ assert(res.node.value.create_time ~= nil)
+ assert(res.node.value.update_time ~= nil)
res.count = nil
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
ngx.say(json.encode(res))
}
}
diff --git a/t/plugin/grpc-transcode.t b/t/plugin/grpc-transcode.t
index 2a1afa2..c87ba56 100644
--- a/t/plugin/grpc-transcode.t
+++ b/t/plugin/grpc-transcode.t
@@ -41,6 +41,7 @@ __DATA__
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
+ local etcd = require("apisix.core.etcd")
local code, body = t('/apisix/admin/proto/1',
ngx.HTTP_PUT,
[[{
@@ -62,6 +63,13 @@ __DATA__
ngx.status = code
end
ngx.say(body)
+
+ local res = assert(etcd.get('/proto/1'))
+ local create_time = res.body.node.value.create_time
+ assert(create_time ~= nil, "create_time is nil")
+ local update_time = res.body.node.value.update_time
+ assert(update_time ~= nil, "update_time is nil")
+
}
}
--- request