Skip to content

Commit 8ebe2d0

Browse files
committed
feat: 支持sharedict数据界面操作管理
feat: 优化sharedict场景划分 feat: 移除代码部分无效引用 fix: 修复auth插件拦截异常执行问题
1 parent 6c30482 commit 8ebe2d0

24 files changed

+1146
-28
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
-- tl_ops_api
2+
-- en : get share dict key state
3+
-- zn : 获取share dict key数据内容
4+
-- @author iamtsm
5+
-- @email 1905333456@qq.com
6+
7+
local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt;
8+
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
9+
local balance_shared = ngx.shared.tlopsbalance
10+
local plugin_shared = ngx.shared.tlopsplugin
11+
local waf_shared = ngx.shared.tlopswaf
12+
local cache_shared = ngx.shared.tlopscache
13+
local cjson = require("cjson.safe");
14+
cjson.encode_empty_table_as_object(false)
15+
16+
17+
local Router = function()
18+
19+
local res_data = {}
20+
21+
local args = ngx.req.get_uri_args()
22+
23+
local type = args.type
24+
if not type then
25+
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error, "type nil");
26+
return
27+
end
28+
29+
local key = args.key
30+
31+
if not key then
32+
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error, "key nil");
33+
return
34+
end
35+
36+
if type and type == 'balance' then
37+
res_data = {
38+
value = balance_shared:get(key)
39+
}
40+
end
41+
42+
if type and type == 'waf' then
43+
res_data = {
44+
value = waf_shared:get(key);
45+
}
46+
end
47+
48+
if type and type == 'plugin' then
49+
res_data = {
50+
value = plugin_shared:get(key);
51+
}
52+
end
53+
54+
if type and type == 'cache' then
55+
res_data = {
56+
value = cache_shared:get(key);
57+
}
58+
end
59+
60+
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
61+
end
62+
63+
return Router
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
-- tl_ops_api
2+
-- en : get share dict state
3+
-- zn : 获取share dict状态
4+
-- @author iamtsm
5+
-- @email 1905333456@qq.com
6+
7+
local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt;
8+
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
9+
local balance_shared = ngx.shared.tlopsbalance
10+
local plugin_shared = ngx.shared.tlopsplugin
11+
local waf_shared = ngx.shared.tlopswaf
12+
local cache_shared = ngx.shared.tlopscache
13+
local cjson = require("cjson.safe");
14+
cjson.encode_empty_table_as_object(false)
15+
16+
17+
local Router = function()
18+
19+
local res_data = {}
20+
21+
local args = ngx.req.get_uri_args()
22+
23+
local type = args.type
24+
25+
if not type then
26+
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error, "type nil");
27+
return
28+
end
29+
30+
if type and type == 'balance' then
31+
res_data = {
32+
free_space = balance_shared:free_space(),
33+
capacity = balance_shared:capacity(),
34+
keys = balance_shared:get_keys(),
35+
}
36+
end
37+
38+
if type and type == 'waf' then
39+
res_data = {
40+
free_space = waf_shared:free_space(),
41+
capacity = waf_shared:capacity(),
42+
keys = waf_shared:get_keys(),
43+
}
44+
end
45+
46+
if type and type == 'plugin' then
47+
res_data = {
48+
free_space = plugin_shared:free_space(),
49+
capacity = plugin_shared:capacity(),
50+
keys = plugin_shared:get_keys(),
51+
}
52+
end
53+
54+
if type and type == 'cache' then
55+
res_data = {
56+
free_space = cache_shared:free_space(),
57+
capacity = cache_shared:capacity(),
58+
keys = cache_shared:get_keys(),
59+
}
60+
end
61+
62+
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
63+
end
64+
65+
return Router

api/router/tl_ops_api_set_state.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
-- @email 1905333456@qq.com
66

77

8-
local snowflake = require("lib.snowflake");
98
local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt;
109
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
1110
local tl_ops_constant_health = require("constant.tl_ops_constant_health")
1211
local tl_ops_health_check_version = require("health.tl_ops_health_check_version")
13-
local cache_service = require("cache.tl_ops_cache_core"):new("tl-ops-service");
14-
local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_state");
1512
local shared = ngx.shared.tlopsbalance
1613
local cjson = require("cjson.safe");
1714
cjson.encode_empty_table_as_object(false)

api/tl_ops_api.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
-- @email 1905333456@qq.com
66

77
local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_api_router");
8-
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
98

109
local _M = {}
1110

api/tl_ops_api_core.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ tl_ops_api_core["/tlops/service/set"] = require("api.router.tl_ops_api_set_servi
5252
-- state
5353
tl_ops_api_core["/tlops/state/get"] = require("api.router.tl_ops_api_get_state")
5454
tl_ops_api_core["/tlops/state/set"] = require("api.router.tl_ops_api_set_state")
55+
tl_ops_api_core["/tlops/state/shdict/get"] = require("api.router.tl_ops_api_get_shdict_state")
56+
tl_ops_api_core["/tlops/state/shdict/key/get"] = require("api.router.tl_ops_api_get_shdict_key_state")
57+
5558

5659
-- health
5760
tl_ops_api_core["/tlops/health/list"] = require("api.router.tl_ops_api_get_health")

balance/tl_ops_balance_core.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ local cjson = require("cjson.safe");
2424
local tl_ops_manage_env = require("tl_ops_manage_env")
2525
local ngx_balancer = require ("ngx.balancer")
2626
local tl_ops_err_content = require("err.tl_ops_err_content")
27-
local shared = ngx.shared.tlopsbalance
28-
2927

3028
local _M = {
3129
_VERSION = '0.02'

cache/tl_ops_cache_dict.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-- @author iamtsm
55
-- @email 1905333456@qq.com
66

7-
local cache_dict = ngx.shared.tlopsbalance;
7+
local cache_dict = ngx.shared.tlopscache;
88
local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_cache_dict");
99
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
1010

conf/tl_ops_manage.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
lua_shared_dict tlopsbalance 100m;
22
lua_shared_dict tlopswaf 100m;
33
lua_shared_dict tlopsplugin 100m;
4+
lua_shared_dict tlopscache 300m;
45

56
init_by_lua_block {
67
tlops = require("tl_ops_manage")

health/tl_ops_health_check.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ local cjson = require("cjson.safe")
88
local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_health")
99
local tl_ops_utils_func = require("utils.tl_ops_utils_func")
1010
local tl_ops_constant_health = require("constant.tl_ops_constant_health")
11-
local tl_ops_status = require("constant.tl_ops_constant_comm").tl_ops_status;
1211
local tl_ops_health_check_dynamic_conf = require("health.tl_ops_health_check_dynamic_conf")
1312
local tl_ops_health_check_version = require("health.tl_ops_health_check_version")
1413
local nx_socket = ngx.socket.tcp
@@ -22,7 +21,6 @@ local mt = { __index = _M }
2221

2322
local tl_ops_health_check,
2423
tl_ops_health_check_main ,
25-
tl_ops_health_check_get_lock,
2624
tl_ops_health_check_default_confs,
2725
tl_ops_health_check_nodes,
2826
tl_ops_health_check_node_failed,

health/tl_ops_health_check_version.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
-- @email 1905333456@qq.com
66

77

8-
local cjson = require("cjson.safe");
98
local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_health_check_version");
109
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
1110
local tl_ops_constant_health = require("constant.tl_ops_constant_health")
12-
local cache_dict = ngx.shared.tlopsbalance;
11+
local shared = ngx.shared.tlopsbalance;
1312

1413
local _M = {
1514
_VERSION = '0.02'
@@ -23,15 +22,15 @@ local tl_ops_health_check_version_incr_service_version = function( service_name
2322
return
2423
end
2524
local key = tl_ops_utils_func:gen_node_key(tl_ops_constant_health.cache_key.service_version, service_name)
26-
local service_version, _ = cache_dict:get(key)
25+
local service_version, _ = shared:get(key)
2726

2827
if not service_version then
29-
service_version, _ = cache_dict:add(key, 1);
28+
service_version, _ = shared:add(key, 1);
3029
if not service_version then
3130
tlog:err(" failed to publish new service_version:" , _)
3231
end
3332
else
34-
service_version, _ = cache_dict:incr(key, 1);
33+
service_version, _ = shared:incr(key, 1);
3534
if not service_version then
3635
tlog:err(" failed to publish new service_version:" , _)
3736
end
@@ -46,7 +45,7 @@ end
4645
-- 对service_options_version更新,通知timer检查是否有新增service
4746
local tl_ops_health_check_version_incr_service_option_version = function( )
4847
local key = tl_ops_constant_health.cache_key.service_options_version;
49-
local res, _ = cache_dict:set(key, true)
48+
local res, _ = shared:set(key, true)
5049

5150
tlog:dbg("service_option_version key=" , key, ", service_option_version=",res)
5251

0 commit comments

Comments
 (0)