Skip to content

Commit 93116f9

Browse files
authored
feat: added max/resp_body_bytes attr to logger plugins (#13034)
1 parent a33a41a commit 93116f9

29 files changed

+1046
-36
lines changed

apisix/plugins/clickhouse-logger.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17-
1817
local bp_manager_mod = require("apisix.utils.batch-processor-manager")
1918
local log_util = require("apisix.utils.log-util")
2019
local plugin = require("apisix.plugin")
@@ -57,7 +56,9 @@ local schema = {
5756
items = {
5857
type = "array"
5958
}
60-
}
59+
},
60+
max_req_body_bytes = {type = "integer", minimum = 1, default = 524288},
61+
max_resp_body_bytes = {type = "integer", minimum = 1, default = 524288},
6162
},
6263
oneOf = {
6364
{required = {"endpoint_addr", "user", "password", "database", "logtable"}},
@@ -174,6 +175,9 @@ local function send_http_data(conf, log_message)
174175
end
175176

176177

178+
_M.access = log_util.check_and_read_req_body
179+
180+
177181
function _M.body_filter(conf, ctx)
178182
log_util.collect_body(conf, ctx)
179183
end

apisix/plugins/elasticsearch-logger.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17-
1817
local core = require("apisix.core")
1918
local http = require("resty.http")
2019
local log_util = require("apisix.utils.log-util")
@@ -104,6 +103,8 @@ local schema = {
104103
type = "array"
105104
}
106105
},
106+
max_req_body_bytes = { type = "integer", minimum = 1, default = 524288 },
107+
max_resp_body_bytes = { type = "integer", minimum = 1, default = 524288 },
107108
},
108109
encrypt_fields = {"auth.password"},
109110
oneOf = {
@@ -214,6 +215,7 @@ local function get_logger_entry(conf, ctx)
214215
core.json.encode(entry) .. "\n"
215216
end
216217

218+
217219
local function fetch_and_update_es_version(conf)
218220
if conf._version then
219221
return
@@ -290,12 +292,16 @@ function _M.body_filter(conf, ctx)
290292
log_util.collect_body(conf, ctx)
291293
end
292294

293-
function _M.access(conf)
295+
296+
function _M.access(conf, ctx)
294297
-- fetch_and_update_es_version will call ES server only the first time
295298
-- so this should not amount to considerable overhead
296299
fetch_and_update_es_version(conf)
300+
301+
log_util.check_and_read_req_body(conf, ctx)
297302
end
298303

304+
299305
function _M.log(conf, ctx)
300306
local metadata = plugin.plugin_metadata(plugin_name)
301307
local max_pending_entries = metadata and metadata.value and

apisix/plugins/file-logger.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17+
1718
local log_util = require("apisix.utils.log-util")
1819
local core = require("apisix.core")
1920
local plugin = require("apisix.plugin")
@@ -49,6 +50,8 @@ local schema = {
4950
type = "array"
5051
}
5152
},
53+
max_req_body_bytes = {type = "integer", minimum = 1, default = 524288},
54+
max_resp_body_bytes = {type = "integer", minimum = 1, default = 524288},
5255
match = {
5356
type = "array",
5457
maxItems = 20,
@@ -204,10 +207,15 @@ local function write_file_data(conf, log_message)
204207
end
205208
end
206209

210+
211+
_M.access = log_util.check_and_read_req_body
212+
213+
207214
function _M.body_filter(conf, ctx)
208215
log_util.collect_body(conf, ctx)
209216
end
210217

218+
211219
function _M.log(conf, ctx)
212220
local entry = log_util.get_log_entry(plugin_name, conf, ctx)
213221
if entry == nil then

apisix/plugins/http-logger.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17-
1817
local bp_manager_mod = require("apisix.utils.batch-processor-manager")
1918
local plugin = require("apisix.plugin")
2019
local log_util = require("apisix.utils.log-util")
@@ -51,6 +50,8 @@ local schema = {
5150
type = "array"
5251
}
5352
},
53+
max_req_body_bytes = {type = "integer", minimum = 1, default = 524288},
54+
max_resp_body_bytes = {type = "integer", minimum = 1, default = 524288},
5455
concat_method = {type = "string", default = "json",
5556
enum = {"json", "new_line"}},
5657
ssl_verify = {type = "boolean", default = false},
@@ -168,6 +169,9 @@ local function send_http_data(conf, log_message)
168169
end
169170

170171

172+
_M.access = log_util.check_and_read_req_body
173+
174+
171175
function _M.body_filter(conf, ctx)
172176
log_util.collect_body(conf, ctx)
173177
end

apisix/plugins/kafka-logger.lua

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17-
local expr = require("resty.expr.v1")
1817
local core = require("apisix.core")
1918
local log_util = require("apisix.utils.log-util")
2019
local producer = require ("resty.kafka.producer")
@@ -24,7 +23,7 @@ local plugin = require("apisix.plugin")
2423
local math = math
2524
local pairs = pairs
2625
local type = type
27-
local req_read_body = ngx.req.read_body
26+
2827
local plugin_name = "kafka-logger"
2928
local batch_processor_manager = bp_manager_mod.new("kafka logger")
3029

@@ -220,30 +219,7 @@ local function send_kafka_data(conf, log_message, prod)
220219
end
221220

222221

223-
function _M.access(conf, ctx)
224-
if conf.include_req_body then
225-
local should_read_body = true
226-
if conf.include_req_body_expr then
227-
if not conf.request_expr then
228-
local request_expr, err = expr.new(conf.include_req_body_expr)
229-
if not request_expr then
230-
core.log.error('generate request expr err ', err)
231-
return
232-
end
233-
conf.request_expr = request_expr
234-
end
235-
236-
local result = conf.request_expr:eval(ctx.var)
237-
238-
if not result then
239-
should_read_body = false
240-
end
241-
end
242-
if should_read_body then
243-
req_read_body()
244-
end
245-
end
246-
end
222+
_M.access = log_util.check_and_read_req_body
247223

248224

249225
function _M.body_filter(conf, ctx)

apisix/plugins/loggly.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ local schema = {
7777
type = "array"
7878
}
7979
},
80+
max_req_body_bytes = {type = "integer", minimum = 1, default = 524288},
81+
max_resp_body_bytes = {type = "integer", minimum = 1, default = 524288},
8082
tags = {
8183
type = "array",
8284
minItems = 1,
@@ -177,6 +179,9 @@ function _M.check_schema(conf, schema_type)
177179
end
178180

179181

182+
_M.access = log_util.check_and_read_req_body
183+
184+
180185
function _M.body_filter(conf, ctx)
181186
log_util.collect_body(conf, ctx)
182187
end

apisix/plugins/loki-logger.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17-
1817
local bp_manager_mod = require("apisix.utils.batch-processor-manager")
1918
local log_util = require("apisix.utils.log-util")
2019
local core = require("apisix.core")
@@ -106,6 +105,8 @@ local schema = {
106105
type = "array"
107106
}
108107
},
108+
max_req_body_bytes = {type = "integer", minimum = 1, default = 524288},
109+
max_resp_body_bytes = {type = "integer", minimum = 1, default = 524288},
109110
},
110111
required = {"endpoint_addrs"}
111112
}
@@ -193,6 +194,9 @@ local function send_http_data(conf, log)
193194
end
194195

195196

197+
_M.access = log_util.check_and_read_req_body
198+
199+
196200
function _M.body_filter(conf, ctx)
197201
log_util.collect_body(conf, ctx)
198202
end

apisix/plugins/rocketmq-logger.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ local schema = {
6868
type = "array"
6969
}
7070
},
71+
max_req_body_bytes = {type = "integer", minimum = 1, default = 524288},
72+
max_resp_body_bytes = {type = "integer", minimum = 1, default = 524288},
7173
},
7274
encrypt_fields = {"secret_key"},
7375
required = {"nameserver_list", "topic"}
@@ -138,6 +140,9 @@ local function send_rocketmq_data(conf, log_message, prod)
138140
end
139141

140142

143+
_M.access = log_util.check_and_read_req_body
144+
145+
141146
function _M.body_filter(conf, ctx)
142147
log_util.collect_body(conf, ctx)
143148
end

apisix/plugins/skywalking-logger.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17-
1817
local bp_manager_mod = require("apisix.utils.batch-processor-manager")
1918
local plugin = require("apisix.plugin")
2019
local log_util = require("apisix.utils.log-util")
@@ -55,6 +54,8 @@ local schema = {
5554
type = "array"
5655
}
5756
},
57+
max_req_body_bytes = {type = "integer", minimum = 1, default = 524288},
58+
max_resp_body_bytes = {type = "integer", minimum = 1, default = 524288},
5859
},
5960
required = {"endpoint_addr"},
6061
}
@@ -139,6 +140,9 @@ local function send_http_data(conf, log_message)
139140
end
140141

141142

143+
_M.access = log_util.check_and_read_req_body
144+
145+
142146
function _M.body_filter(conf, ctx)
143147
log_util.collect_body(conf, ctx)
144148
end

apisix/plugins/sls-logger.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ local schema = {
4848
type = "array"
4949
}
5050
},
51+
max_req_body_bytes = {type = "integer", minimum = 1, default = 524288},
52+
max_resp_body_bytes = {type = "integer", minimum = 1, default = 524288},
5153
timeout = {type = "integer", minimum = 1, default= 5000},
5254
log_format = {type = "object"},
5355
host = {type = "string"},
@@ -158,6 +160,9 @@ local function handle_log(entries)
158160
end
159161

160162

163+
_M.access = log_util.check_and_read_req_body
164+
165+
161166
function _M.body_filter(conf, ctx)
162167
log_util.collect_body(conf, ctx)
163168
end

0 commit comments

Comments
 (0)