-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathtl_ops_manage.lua
168 lines (123 loc) · 3.93 KB
/
tl_ops_manage.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
-- tl_ops_manage
-- en : core
-- zn : 核心流程
-- @author iamtsm
-- @email 1905333456@qq.com
-- module
local m_health = require("health.tl_ops_health")
local m_limit_fuse = require("limit.fuse.tl_ops_limit_fuse")
local m_balance_count = require("balance.count.tl_ops_balance_count")
local m_plugin = require("plugins.tl_ops_plugin"):new()
local m_waf = require("waf.tl_ops_waf")
local m_waf_count = require("waf.count.tl_ops_waf_count")
local m_api = require("api.tl_ops_api")
local m_balance = require("balance.tl_ops_balance")
local m_ctx = require("ctx.tl_ops_ctx");
local utils = require("utils.tl_ops_utils_func");
local env = require("tl_ops_manage_env")
local constant = require("constant.tl_ops_constant")
local cache = require("cache.tl_ops_cache")
local m_err_content = require("err.tl_ops_err_content")
local balance_shared = ngx.shared.tlopsbalance
local plugin_shared = ngx.shared.tlopsplugin
local waf_shared = ngx.shared.tlopswaf
local cache_shared = ngx.shared.tlopscache
local _M = {
env = env,
cache = cache,
utils = utils,
constant = constant,
plugins = {},
waf_shared = waf_shared,
plugin_shared = plugin_shared,
balance_shared = balance_shared,
cache_shared = cache_shared,
}
-- init阶段执行
function _M:tl_ops_process_init()
-- 加载所有插件
m_plugin:tl_ops_process_load_plugins();
_M.plugins = m_plugin:tl_ops_process_get_plugins()
end
-- init_worker阶段执行
function _M:tl_ops_process_init_worker()
-- 执行插件
m_plugin:tl_ops_process_before_init_worker();
-- 启动健康检查
m_health:init();
-- 启动限流熔断
m_limit_fuse:init();
-- 启动路由统计
m_balance_count:init();
-- 启动WAF统计
m_waf_count:init();
-- 执行插件
m_plugin:tl_ops_process_after_init_worker();
end
-- ssl阶段执行
function _M:tl_ops_process_init_ssl()
-- 执行插件
m_plugin:tl_ops_process_before_init_ssl();
-- 执行插件
m_plugin:tl_ops_process_after_init_ssl();
end
-- rewrite阶段执行
function _M:tl_ops_process_init_rewrite(onlyplugin)
-- 初始化ctx
m_ctx:init(self.plugins);
-- 执行插件
m_plugin:tl_ops_process_before_init_rewrite(ngx.ctx);
if not onlyplugin then
-- 加载管理台API
m_api:init(ngx.ctx);
-- 启动全局WAF
m_waf:init_global(ngx.ctx);
-- 负载均衡筛选
m_balance:filter(ngx.ctx);
end
-- 执行插件
m_plugin:tl_ops_process_after_init_rewrite(ngx.ctx);
end
-- access阶段执行
function _M:tl_ops_process_init_access()
-- 执行插件
m_plugin:tl_ops_process_before_init_access(ngx.ctx);
-- 执行插件
m_plugin:tl_ops_process_after_init_access(ngx.ctx);
end
-- balance阶段执行
function _M:tl_ops_process_init_balancer()
-- 执行插件
m_plugin:tl_ops_process_before_init_balancer(ngx.ctx);
-- 负载均衡请求分发
m_balance:init(ngx.ctx);
-- 执行插件
m_plugin:tl_ops_process_after_init_balancer(ngx.ctx);
end
-- content阶段执行
function _M:tl_ops_process_init_content()
-- 自定义错误内容
m_err_content:init(ngx.ctx);
end
-- header阶段执行
function _M:tl_ops_process_init_header()
-- 执行插件
m_plugin:tl_ops_process_before_init_header(ngx.ctx);
-- 执行插件
m_plugin:tl_ops_process_after_init_header(ngx.ctx);
end
-- body阶段执行
function _M:tl_ops_process_init_body()
-- 执行插件
m_plugin:tl_ops_process_before_init_body(ngx.ctx);
-- 执行插件
m_plugin:tl_ops_process_after_init_body(ngx.ctx);
end
-- log阶段执行
function _M:tl_ops_process_init_log()
-- 执行插件
m_plugin:tl_ops_process_before_init_log(ngx.ctx);
-- 执行插件
m_plugin:tl_ops_process_after_init_log(ngx.ctx);
end
return _M