Skip to content

Commit

Permalink
feat: 补充定时器异常退出日志
Browse files Browse the repository at this point in the history
feat: 补充store存储前一次索引
fix: 修复reload导致自检定时器没有重启
fix: 修复登录页面名称错误
fix: 修复ssl调用代码错误
fix: 优化一些调用代码
  • Loading branch information
iamtsm committed Jul 27, 2023
1 parent c70316f commit 6f8cd37
Show file tree
Hide file tree
Showing 29 changed files with 108 additions and 54 deletions.
1 change: 1 addition & 0 deletions balance/count/tl_ops_balance_count_core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ end
-- 统计balance次数周期默认为5min,可调整配置
tl_ops_balance_count_timer = function(premature, args)
if premature then
tlog:err("premature")
return
end

Expand Down
4 changes: 2 additions & 2 deletions balance/tl_ops_balance_core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function _M:tl_ops_balance_core_filter(ctx)
balance_count_node.tl_ops_balance_count_incr_node_fail(node.service, node_id)
-- 负载失败 -- 限流统计器
tl_ops_limit:tl_ops_limit_fuse_incr_fail(node.service, node_id);

tl_ops_err_content:err_content_rewrite_to_balance(node.service .. ":" .. node.name, "offline", balance_mode, tl_ops_constant_balance.cache_key.offline, "")
return
end
Expand Down Expand Up @@ -164,7 +164,7 @@ function _M:tl_ops_balance_core_balance(ctx)
ngx.header[tl_ops_constant_balance.proxy_state] = "online"
ngx.header[tl_ops_constant_balance.proxy_mode] = tlops_ups_mode
ngx.header[tl_ops_constant_balance.proxy_prefix] = tlops_ups_api_prefix

local ok, err = ngx_balancer.set_current_peer(tlops_ups_node.ip, tlops_ups_node.port)
if ok then
ngx_balancer.set_timeouts(3, 60, 60)
Expand Down
2 changes: 1 addition & 1 deletion bin/install_centeros.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TL_OPS_PATH="/usr/local/tl-ops-manage/"
TL_OPS_CONF_PATH="/usr/local/tl-ops-manage/conf/tl_ops_manage.conf"
TL_OPS_LUA_PATH="/usr/local/openresty/lualib/?.lua;;/usr/local/tl-ops-manage/?.lua;;"
TL_OPS_LUAC_PATH="/usr/local/openresty/lualib/?.so;;"
TL_OPS_VER="v3.4.5"
TL_OPS_VER="v3.4.6"

echo_msg(){
cur_time=$(date "+%Y-%m-%d %H:%M:%S")
Expand Down
2 changes: 1 addition & 1 deletion bin/install_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TL_OPS_PATH="/usr/local/tl-ops-manage/"
TL_OPS_CONF_PATH="/usr/local/tl-ops-manage/conf/tl_ops_manage.conf"
TL_OPS_LUA_PATH="/usr/local/openresty/lualib/?.lua;;/usr/local/tl-ops-manage/?.lua;;"
TL_OPS_LUAC_PATH="/usr/local/openresty/lualib/?.so;;"
TL_OPS_VER="v3.4.5"
TL_OPS_VER="v3.4.6"

echo_msg(){
cur_time=$(date "+%Y-%m-%d %H:%M:%S")
Expand Down
21 changes: 16 additions & 5 deletions cache/tl_ops_cache_cus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,35 @@ end


function _M:new()
local default_cus = {
get = function(key)
return nil
end,
set = function(key, value)
return nil
end,
del = function(key)
return nil
end
}
if not use_cus or use_cus == 'none' then
return nil
return default_cus
end

local status, cus = pcall(require, "cache.tl_ops_cache_" .. use_cus)
if status then
if cus and type(cus) == 'table' then
if type(cus.new) ~= 'function' then
return nil
return default_cus
end
if type(cus.get) ~= 'function' then
return nil
return default_cus
end
if type(cus.set) ~= 'function' then
return nil
return default_cus
end
if type(cus.del) ~= 'function' then
return nil
return default_cus
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion cache/tl_ops_cache_store.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function _M:del(key)
end

-- set seek to 4GB 等价删除索引
self.cache_store:store_index(key, 4 * 1024 * 1024 * 1024)
self.cache_store:store_index(key, 4 * 1024 * 1024 * 1024)

tlog:dbg("del cache store ok key=" .. key)

Expand Down
2 changes: 1 addition & 1 deletion constant/tl_ops_constant_service.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local tl_ops_constant_service = {
service_rule = "tl_ops_service_rule",
},
list = {

},
demo = {
id = 1,
Expand Down
17 changes: 16 additions & 1 deletion doc/change.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@

## 事务更新日程

2023-07-27

1. 补充定时器异常退出日志

2. 修复登录页面名称错误

3. 修复reload导致自检定时器没有重启

4. 修复ssl调用代码错误

5. 优化一些调用代码

6. 事务日程调整


2023-04-22

1. api规则细节限制优化
Expand Down Expand Up @@ -38,7 +53,7 @@

2. 支持waf详情多维度统计和展示

3. 支持管理后台退出登陆
3. 支持管理后台退出登录

4. 优化代码注释

Expand Down
2 changes: 1 addition & 1 deletion gitbook/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

* [使用配置](usage/ssl/README.md)

* [登陆认证插件](code/auth/README.md)
* [登录认证插件](code/auth/README.md)

* [使用配置](usage/auth/README.md)

Expand Down
16 changes: 8 additions & 8 deletions gitbook/code/auth/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# 登陆认证插件
# 登录认证插件

登陆认证插件主要为管理后台系统提供一个操作可控的权限认证,实现的方式是在 `tl_ops_process_before_init_rewrite` 阶段进行cookie或者header验证,对于需要拦截验证的链接进行验证,当然,拦截链接是可视化配置的,可以根据需要自定义
登录认证插件主要为管理后台系统提供一个操作可控的权限认证,实现的方式是在 `tl_ops_process_before_init_rewrite` 阶段进行cookie或者header验证,对于需要拦截验证的链接进行验证,当然,拦截链接是可视化配置的,可以根据需要自定义

登陆插件数据主要分为两个子模块,一个是自定义配置模块,一个是账号密码模块
登录插件数据主要分为两个子模块,一个是自定义配置模块,一个是账号密码模块


### 拦截配置

我们先看一下拦截配置的数据定义,主要包含几个方面,拦截的api,拦截api白名单,拦截后返回的内容,登陆验证身份相关
我们先看一下拦截配置的数据定义,主要包含几个方面,拦截的api,拦截api白名单,拦截后返回的内容,登录验证身份相关

```lua
# 代码位置 : plugins/tl_ops_auth/tl_ops_plugin_constant.lua
Expand All @@ -24,9 +24,9 @@ login = {
"/tlops/auth/login",
"/tlopsmanage/lib/",
},
auth_time = 3600, -- 登陆后session有效时间
auth_cid = "_tl_t", -- 登陆后cookie值key
auth_hid = "Tl-Auth-Rid", -- 登陆后header值key
auth_time = 3600, -- 登录后session有效时间
auth_cid = "_tl_t", -- 登录后cookie值key
auth_hid = "Tl-Auth-Rid", -- 登录后header值key
},
```

Expand Down Expand Up @@ -67,7 +67,7 @@ end
```

进入 `auth_core` 方法,看实现逻辑为拿到设置配置后,判断当前uri是否需要拦截,如果需要拦截, 判断cookie或者header中的sessionkey是否有效,
如果无效,则是没有登陆,返回自定义的配置内容。
如果无效,则是没有登录,返回自定义的配置内容。

```lua
# 代码位置 : plugins/tl_ops_auth/auth.lua
Expand Down
8 changes: 4 additions & 4 deletions health/tl_ops_health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ local _M = {}
function _M:init( )

--给定配置启动健康检查,支持动态加载已有服务变更配置
local health_check = tl_ops_health_check:new(
local health_check = tl_ops_health_check:new(
tl_ops_constant_health.options, tl_ops_constant_health.service
);
health_check:tl_ops_health_check_start();


--动态加载新增配置
tl_ops_health_check_dynamic_conf.dynamic_conf_add_start()


--默认初始化一次version
for i = 1, #tl_ops_constant_health.options do
Expand All @@ -32,7 +32,7 @@ function _M:init( )
tl_ops_health_check_version.incr_service_version(service_name)
end
end

tl_ops_health_check_version.incr_service_option_version()

end
Expand Down
8 changes: 6 additions & 2 deletions health/tl_ops_health_check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ local _M = {
}
local mt = { __index = _M }

local tl_ops_health_check,
tl_ops_health_check_main ,
local tl_ops_health_check,
tl_ops_health_check_main,
tl_ops_health_check_default_confs,
tl_ops_health_check_nodes,
tl_ops_health_check_node_failed,
Expand Down Expand Up @@ -148,6 +148,10 @@ end
-- 创建健康检查定时器
tl_ops_health_check = function(premature, conf)
if premature then
tlog:err("premature")

-- 重启时,清空所有定时器记录
shared:set(tl_ops_constant_health.cache_key.timers, nil)
return
end

Expand Down
5 changes: 3 additions & 2 deletions health/tl_ops_health_check_dynamic_conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ local tl_ops_health_check_dynamic_conf_add_core = function(options, services)
shared:set(tl_ops_constant_health.cache_key.service_options_version, nil)
return
end

-- 如果有,查看cache service中的所有服务是否都已启动timer,如果没有, 补充启动相应service timer
local timers_list = cjson.decode(timers_str)
for service_name, nodes in pairs(services) do
Expand All @@ -83,7 +83,7 @@ local tl_ops_health_check_dynamic_conf_add_core = function(options, services)
end
end
if service_name_exist == true then
tlog:dbg("[add-check] timer exist , service_name=",service_name)
tlog:dbg("[add-check] timer exist, service_name=",service_name)
else
local matcher_options = tl_ops_health_check_dynamic_conf_get_option( options, service_name)
tlog:dbg("[add-check] new timer done, service_name=",service_name, ",matcher_options=",matcher_options)
Expand Down Expand Up @@ -131,6 +131,7 @@ end
-- 加载新增配置的周期为10s
tl_ops_health_check_dynamic_conf_add_timer_check = function(premature, args)
if premature then
tlog:err("premature")
return
end

Expand Down
4 changes: 4 additions & 0 deletions limit/fuse/tl_ops_limit_fuse_check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ end

tl_ops_limit_fuse = function(premature, conf)
if premature then
tlog:err("premature")

-- 重启时,清空所有定时器记录
shared:set(tl_ops_constant_limit.fuse.cache_key.timers, nil)
return
end

Expand Down
1 change: 1 addition & 0 deletions limit/fuse/tl_ops_limit_fuse_check_dynamic_conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ end
-- 加载新增配置的周期为10s
tl_ops_limit_fuse_check_dynamic_conf_add_timer_check = function(premature, args)
if premature then
tlog:err("premature")
return
end

Expand Down
3 changes: 2 additions & 1 deletion limit/fuse/tl_ops_limit_fuse_check_version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ end

-- 对service_options_version更新,通知timer检查是否有新增service
local tl_ops_limit_fuse_version_incr_service_option_version = function( )
local res, _ = cache_dict:set(tl_ops_constant_limit.fuse.cache_key.service_options_version, true)
local key = tl_ops_constant_limit.fuse.cache_key.service_options_version
local res, _ = cache_dict:set(key, true)

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

Expand Down
4 changes: 2 additions & 2 deletions limit/tl_ops_limit_leak_bucket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ end

-- get leak with lazy generate
-- block 漏桶流速单位
local tl_ops_limit_leak_bucket = function( block )
function _M:tl_ops_limit_leak_bucket( block )
local capacity = shared:get(self.keys.capacity)
if not capacity then
return false
Expand Down Expand Up @@ -154,7 +154,7 @@ function _M:tl_ops_limit_leak( block )
return false
end

local leak = tl_ops_limit_leak_bucket( block )
local leak = self:tl_ops_limit_leak_bucket( block )
if not leak or leak == false then
return false
end
Expand Down
6 changes: 3 additions & 3 deletions limit/tl_ops_limit_sliding_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ end

-- try sliding, 尝试通过滑动窗口
-- block : 请求大小
local tl_ops_limit_sliding_window = function( block )
function _M:tl_ops_limit_sliding_window( block )

local window = shared:get(self.keys.window)
if not window then
Expand Down Expand Up @@ -116,7 +116,7 @@ local tl_ops_limit_sliding_window = function( block )
if not count then
count = 0
end
local res, _ = shared:del(self.keys.count .. i)
local res, _ = shared:delete(self.keys.count .. i)
if not res then
return false
end
Expand Down Expand Up @@ -190,7 +190,7 @@ function _M:tl_ops_sliding_window( block )
return false
end

local sliding = tl_ops_limit_sliding_window( block )
local sliding = self:tl_ops_limit_sliding_window( block )
if not sliding or sliding == false then
return false
end
Expand Down
4 changes: 2 additions & 2 deletions limit/tl_ops_limit_token_bucket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ end

-- get token with lazy generate
-- block 取用令牌数量
local tl_ops_limit_token_bucket = function( block )
function _M:tl_ops_limit_token_bucket( block )
local capacity = shared:get(self.keys.capacity)
if not capacity then
return false
Expand Down Expand Up @@ -194,7 +194,7 @@ function _M:tl_ops_limit_token( block )
return false
end

local token = tl_ops_limit_token_bucket( block )
local token = self:tl_ops_limit_token_bucket( block )
if not token or token == false then
return false
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/tl_ops_auth/tl_ops_plugin_constant.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ local default_content_page = [[
</form>
<div class="layui-form-item" style="margin-top: 30px;">
<div class="layui-input-block">
<button class="layui-btn" onclick="tl_ops_manage_login()" style="letter-spacing: 40px;text-indent: 30px;">登陆</button>
<button class="layui-btn" onclick="tl_ops_manage_login()" style="letter-spacing: 40px;text-indent: 30px;">登录</button>
</div>
</div>
</div>
Expand Down
9 changes: 4 additions & 5 deletions plugins/tl_ops_ssl/ssl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ local get_pem_key_cache = function(host)
end

local list = cjson.decode(list_str)
if not list then
return nil
if not list then
return nil
end

for i = 1, #list do
Expand All @@ -45,7 +45,7 @@ end
-- 核心逻辑
function _M:ssl_core()

local host = ssl.server_name()
local host = ssl.server_name()

local ok, err = ssl.clear_certs()
if not ok then
Expand All @@ -71,8 +71,7 @@ function _M:ssl_core()
return false, err
end

local passphrase = nil
local der_pkey, err = ssl.priv_key_pem_to_der(host_pem_key.key, passphrase)
local der_pkey, err = ssl.priv_key_pem_to_der(host_pem_key.key)
if not der_pkey then
tlog:err("failed to convert private key, ",err,",key=",host_pem_key.key)
return false, err
Expand Down
1 change: 1 addition & 0 deletions plugins/tl_ops_sync/sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local mt = { __index = _M }
-- 核心逻辑
local tl_ops_sync_timer = function(premature, args)
if premature then
tlog:err("premature")
return
end

Expand Down
Loading

0 comments on commit 6f8cd37

Please sign in to comment.