Skip to content

Commit

Permalink
feat: v3.4.0版本更新
Browse files Browse the repository at this point in the history
feat: 支持负载详情多维度统计和展示
feat: 支持waf详情多维度统计和展示
feat: 支持管理后台退出登陆
feat: 优化代码注释
feat: 即将支持grpc代理插件
feat: 事务日程调整
  • Loading branch information
iamtsm committed Mar 12, 2023
1 parent 6ecac02 commit ca64066
Show file tree
Hide file tree
Showing 99 changed files with 4,101 additions and 489 deletions.
96 changes: 96 additions & 0 deletions api/router/tl_ops_api_get_balance_count_api.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
-- tl_ops_api
-- en : get balance api count data list
-- zn : 获取路由负载详情列表
-- @author iamtsm
-- @email [email protected]

local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-count");
local cache_balance_api = require("cache.tl_ops_cache_core"):new("tl-ops-balance-api")
local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt;
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api")
local tl_ops_constant_balance_count = require("constant.tl_ops_constant_balance_count")
local cjson = require("cjson.safe");
cjson.encode_empty_table_as_object(false)

local Router = function()

-- 支持只获取某个服务节点的路由规则统计
local args = ngx.req.get_uri_args()
local args_service = args['service']
local args_node = args['node']
args_node = tonumber(args_node)

local rule, _ = cache_balance_api:get(tl_ops_constant_balance_api.cache_key.rule);
if not rule or rule == nil then
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bca args err1", _);
return;
end

local list_str, _ = cache_balance_api:get(tl_ops_constant_balance_api.cache_key.list);
if not list_str or list_str == nil then
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bca args err2", _);
return;
end

local list = cjson.decode(list_str);
if not list or list == nil then
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bca args err3", _);
return;
end

local api_rule_list = list[rule];
if not api_rule_list or api_rule_list == nil then
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bca args err4", _);
return;
end

local res_data = {}

for _, api in ipairs(api_rule_list) do
repeat
local id = api.id;
local service_name = api.service;
local node_id = api.node;

if not id then
break
end
if not service_name then
break
end
if rule == tl_ops_constant_balance_api.rule.point then
if node_id == nil or node_id == '' then
break
end
end

if args_service and args_service ~= service_name then
break
end
if args_node ~= nil and args_node ~= "" and node_id ~= args_node then
break
end

local api_counting_list = cache:get001(
tl_ops_utils_func:gen_node_key( tl_ops_constant_balance_count.cache_key.api_counting_list, service_name, node_id, id)
)
if not api_counting_list then
api_counting_list = "{}"
end

table.insert(res_data, {
id = id,
service_name = service_name,
node_id = node_id,
content = api.url,
count_list = cjson.decode(api_counting_list)
})
break
until true
end

tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
end

return Router
97 changes: 97 additions & 0 deletions api/router/tl_ops_api_get_balance_count_body.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
-- tl_ops_api
-- en : get balance body count data list
-- zn : 获取路由负载详情列表
-- @author iamtsm
-- @email [email protected]

local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-count");
local cache_balance_body = require("cache.tl_ops_cache_core"):new("tl-ops-balance-body")
local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt;
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
local tl_ops_constant_balance_body = require("constant.tl_ops_constant_balance_body")
local tl_ops_constant_balance_count = require("constant.tl_ops_constant_balance_count")
local cjson = require("cjson.safe");
cjson.encode_empty_table_as_object(false)

local Router = function()

-- 支持只获取某个服务节点的路由规则统计
local args = ngx.req.get_uri_args()
local args_service = args['service']
local args_node = args['node']
args_node = tonumber(args_node)

local rule, _ = cache_balance_body:get(tl_ops_constant_balance_body.cache_key.rule);
if not rule or rule == nil then
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bc args err1", _);
return;
end

local list_str, _ = cache_balance_body:get(tl_ops_constant_balance_body.cache_key.list);
if not list_str or list_str == nil then
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bc args err2", _);
return;
end

local list = cjson.decode(list_str);
if not list or list == nil then
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bc args err3", _);
return;
end

local body_rule_list = list[rule];
if not body_rule_list or body_rule_list == nil then
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bc args err4", _);
return;
end

local res_data = {}

for _, body in ipairs(body_rule_list) do
repeat
local id = body.id;
local service_name = body.service;
local node_id = body.node;

if not id then
break
end
if not service_name then
break
end
if rule == tl_ops_constant_balance_body.rule.point then
if node_id == nil or node_id == '' then
break
end
end

-- 支持只获取某个服务节点的路由规则统计
if args_service and args_service ~= service_name then
break
end
if args_node ~= nil and args_node ~= "" and node_id ~= args_node then
break
end

local body_counting_list = cache:get001(
tl_ops_utils_func:gen_node_key( tl_ops_constant_balance_count.cache_key.body_counting_list, service_name, node_id, id)
)
if not body_counting_list then
body_counting_list = "{}"
end

table.insert(res_data, {
id = id,
service_name = service_name,
node_id = node_id,
content = body.body,
count_list = cjson.decode(body_counting_list)
})
break
until true
end

tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
end

return Router
100 changes: 100 additions & 0 deletions api/router/tl_ops_api_get_balance_count_cookie.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
-- tl_ops_api
-- en : get balance cookie count data list
-- zn : 获取路由负载详情列表
-- @author iamtsm
-- @email [email protected]

local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-count");
local cache_balance_cookie = require("cache.tl_ops_cache_core"):new("tl-ops-balance-cookie")
local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt;
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
local tl_ops_constant_balance_cookie = require("constant.tl_ops_constant_balance_cookie")
local tl_ops_constant_balance_count = require("constant.tl_ops_constant_balance_count")
local cjson = require("cjson.safe");
cjson.encode_empty_table_as_object(false)

local Router = function()

-- 支持只获取某个服务节点的路由规则统计
local args = ngx.req.get_uri_args()
local args_service = args['service']
local args_node = args['node']
args_node = tonumber(args_node)

local rule, _ = cache_balance_cookie:get(tl_ops_constant_balance_cookie.cache_key.rule);
if not rule or rule == nil then
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bc args err1", _);
return;
end

local list_str, _ = cache_balance_cookie:get(tl_ops_constant_balance_cookie.cache_key.list);
if not list_str or list_str == nil then
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bc args err2", _);
return;
end

local list = cjson.decode(list_str);
if not list or list == nil then
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bc args err3", _);
return;
end

local cookie_rule_list = list[rule];
if not cookie_rule_list or cookie_rule_list == nil then
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bc args err4", _);
return;
end

local res_data = {}

for _, cookie in ipairs(cookie_rule_list) do
repeat
local id = cookie.id;
local service_name = cookie.service;
local node_id = cookie.node;

if not id then
break
end
if not service_name then
break
end
if rule == tl_ops_constant_balance_cookie.rule.point then
if node_id == nil or node_id == '' then
break
end
end

-- 支持只获取某个服务节点的路由规则统计
if args_service and args_service ~= service_name then
break
end
if args_node ~= nil and args_node ~= "" and node_id ~= args_node then
break
end

local cookie_counting_list = cache:get001(
tl_ops_utils_func:gen_node_key( tl_ops_constant_balance_count.cache_key.cookie_counting_list, service_name, node_id, id)
)
if not cookie_counting_list then
cookie_counting_list = "{}"
end

table.insert(res_data, {
id = id,
service_name = service_name,
node_id = node_id,
content = cjson.encode({
key = cookie.key,
value = cookie.value,
}),
count_list = cjson.decode(cookie_counting_list)
})
break
until true
end

tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
end

return Router
Loading

0 comments on commit ca64066

Please sign in to comment.