diff --git a/apisix/core/ctx.lua b/apisix/core/ctx.lua index 47b6bef8584e..0ece8c8c761b 100644 --- a/apisix/core/ctx.lua +++ b/apisix/core/ctx.lua @@ -217,6 +217,11 @@ do route_name = true, service_id = true, service_name = true, + resp_response_size = function(ctx) + return (ngx.ctx.api_ctx.var.upstream_response_length ~= '0' and ngx.ctx.api_ctx.var.upstream_response_length) + or (ngx.ctx.api_ctx.var.body_bytes_sent ~= '0' and ngx.ctx.api_ctx.var.body_bytes_sent) + or ngx.ctx.api_ctx.var.upstream_bytes_received + end, } local mt = { diff --git a/apisix/core/etcd.lua b/apisix/core/etcd.lua index b52517cd40b5..7637e7333f73 100644 --- a/apisix/core/etcd.lua +++ b/apisix/core/etcd.lua @@ -554,7 +554,9 @@ function _M.delete(key) return nil, err end - res.headers["X-Etcd-Index"] = res.body.header.revision + if res.body.header then + res.headers["X-Etcd-Index"] = res.body.header.revision + end if not res.body.deleted then return not_found(res), nil diff --git a/apisix/plugin.lua b/apisix/plugin.lua index a7d55db7375c..3715b814c0ee 100644 --- a/apisix/plugin.lua +++ b/apisix/plugin.lua @@ -692,6 +692,12 @@ function _M.merge_consumer_route(route_conf, consumer_conf, consumer_group_conf, local new_conf = merged_route(flag, api_ctx.conf_version, merge_consumer_route, route_conf, consumer_conf, consumer_group_conf) + -- some plugins like limit-count don't care if consumer changes + -- all consumers should share the same counter + api_ctx.conf_type_without_consumer = api_ctx.conf_type + api_ctx.conf_version_without_consumer = api_ctx.conf_version + api_ctx.conf_id_without_consumer = api_ctx.conf_id + api_ctx.conf_type = api_ctx.conf_type .. "&consumer" api_ctx.conf_version = api_ctx.conf_version .. "&" .. api_ctx.consumer_ver diff --git a/apisix/plugins/limit-count/init.lua b/apisix/plugins/limit-count/init.lua index 58fbf7969e2a..d8c8d30c7e3a 100644 --- a/apisix/plugins/limit-count/init.lua +++ b/apisix/plugins/limit-count/init.lua @@ -222,7 +222,9 @@ local function gen_limit_key(conf, ctx, key) -- Here we use plugin-level conf version to prevent the counter from being resetting -- because of the change elsewhere. -- A route which reuses a previous route's ID will inherits its counter. - local new_key = ctx.conf_type .. ctx.conf_id .. ':' .. apisix_plugin.conf_version(conf) + local conf_type = ctx.conf_type_without_consumer or ctx.conf_type + local conf_id = ctx.conf_id_without_consumer or ctx.conf_id + local new_key = conf_type .. conf_id .. ':' .. apisix_plugin.conf_version(conf) .. ':' .. key if conf._vid then -- conf has _vid means it's from workflow plugin, add _vid to the key diff --git a/apisix/utils/log-util.lua b/apisix/utils/log-util.lua index 4aecf290e4ee..1df687c7bcfd 100644 --- a/apisix/utils/log-util.lua +++ b/apisix/utils/log-util.lua @@ -55,12 +55,67 @@ local function gen_log_format(format) return log_format end -local function get_custom_format_log(ctx, format) + +local function get_request_body(conf, ctx) + local res = {} + + if conf.include_req_body then + + local log_request_body = true + + if conf.include_req_body_expr then + + if not conf.request_expr then + local request_expr, err = expr.new(conf.include_req_body_expr) + if not request_expr then + core.log.error('generate request expr err ' .. err) + return res + end + conf.request_expr = request_expr + end + + local result = conf.request_expr:eval(ctx.var) + + if not result then + log_request_body = false + end + end + + if log_request_body then + local body = req_get_body_data() + if body then + res.request_body = body + return res + else + local body_file = ngx.req.get_body_file() + if body_file then + res.request_body_file = body_file + return res + end + end + end + end + + return res +end + + +local function get_custom_format_log(ctx, format, conf) local log_format = lru_log_format(format or "", nil, gen_log_format, format) local entry = core.table.new(0, core.table.nkeys(log_format)) for k, var_attr in pairs(log_format) do if var_attr[1] then - entry[k] = ctx.var[var_attr[2]] + if var_attr[2] == "response_body" then + entry[k] = ctx.resp_body + elseif var_attr[2] == "request_body" then + local request_data = get_request_body(conf, ctx) + entry[k] = request_data.request_body + elseif var_attr[2] == "request_body_file" then + local request_data = get_request_body(conf, ctx) + entry[k] = request_data.request_body_file + else + entry[k] = ctx.var[var_attr[2]] + end else entry[k] = var_attr[2] end @@ -163,40 +218,9 @@ local function get_full_log(ngx, conf) log.response.body = ctx.resp_body end - if conf.include_req_body then - - local log_request_body = true - - if conf.include_req_body_expr then - - if not conf.request_expr then - local request_expr, err = expr.new(conf.include_req_body_expr) - if not request_expr then - core.log.error('generate request expr err ' .. err) - return log - end - conf.request_expr = request_expr - end - - local result = conf.request_expr:eval(ctx.var) - - if not result then - log_request_body = false - end - end - - if log_request_body then - local body = req_get_body_data() - if body then - log.request.body = body - else - local body_file = ngx.req.get_body_file() - if body_file then - log.request.body_file = body_file - end - end - end - end + local request_data = get_request_body(conf, ctx) + log.request.body = request_data.request_body + log.request.body_file = request_data.request_body_file return log end @@ -222,7 +246,7 @@ function _M.get_log_entry(plugin_name, conf, ctx) if conf.log_format or has_meta_log_format then customized = true - entry = get_custom_format_log(ctx, conf.log_format or metadata.value.log_format) + entry = get_custom_format_log(ctx, conf.log_format or metadata.value.log_format, conf) else if is_http then entry = get_full_log(ngx, conf) diff --git a/rockspec/apisix-3.2.2.1-0.rockspec b/rockspec/apisix-3.2.2.1-0.rockspec new file mode 100644 index 000000000000..e3cdc7ff79eb --- /dev/null +++ b/rockspec/apisix-3.2.2.1-0.rockspec @@ -0,0 +1,103 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +package = "apisix" +version = "3.2.2.1-0" +supported_platforms = {"linux", "macosx"} + +source = { + url = "git://github.com/apache/apisix", + branch = "3.2.2", +} + +description = { + summary = "Apache APISIX is a cloud-native microservices API gateway, delivering the ultimate performance, security, open source and scalable platform for all your APIs and microservices.", + homepage = "https://github.com/apache/apisix", + license = "Apache License 2.0", +} + +dependencies = { + "lua-resty-ctxdump = 0.1-0", + "api7-lua-resty-dns-client = 7.0.1", + "lua-resty-template = 2.0", + "lua-resty-etcd = 1.10.4", + "api7-lua-resty-http = 0.2.0", + "lua-resty-balancer = 0.04", + "lua-resty-ngxvar = 0.5.2", + "lua-resty-jit-uuid = 0.0.7", + "lua-resty-healthcheck-api7 = 2.2.2", + "api7-lua-resty-jwt = 0.2.5", + "lua-resty-hmac-ffi = 0.05", + "lua-resty-cookie = 0.1.0", + "lua-resty-session = 3.10", + "opentracing-openresty = 0.1", + "lua-resty-radixtree = 2.8.2", + "lua-protobuf = 0.4.1", + "lua-resty-openidc = 1.7.5", + "luafilesystem = 1.7.0-2", + "api7-lua-tinyyaml = 0.4.2", + "nginx-lua-prometheus = 0.20220527", + "jsonschema = 0.9.8", + "lua-resty-ipmatcher = 0.6.1", + "lua-resty-kafka = 0.20-0", + "lua-resty-logger-socket = 2.0.1-0", + "skywalking-nginx-lua = 0.6.0", + "base64 = 1.5-2", + "binaryheap = 0.4", + "api7-dkjson = 0.1.1", + "resty-redis-cluster = 1.02-4", + "lua-resty-expr = 1.3.2", + "graphql = 0.0.2", + "argparse = 0.7.1-1", + "luasocket = 3.1.0-1", + "luasec = 0.9-1", + "lua-resty-consul = 0.3-2", + "penlight = 1.9.2-1", + "ext-plugin-proto = 0.6.0", + "casbin = 1.41.5", + "api7-snowflake = 2.0-1", + "inspect == 3.1.1", + "lualdap = 1.2.6-1", + "lua-resty-rocketmq = 0.3.0-0", + "opentelemetry-lua = 0.2-3", + "net-url = 0.9-1", + "xml2lua = 1.5-2", + "nanoid = 0.1-1", + "lua-resty-mediador = 0.1.2-1", + "lua-resty-ldap = 0.1.0-0" +} + +build = { + type = "make", + build_variables = { + CFLAGS="$(CFLAGS)", + LIBFLAG="$(LIBFLAG)", + LUA_LIBDIR="$(LUA_LIBDIR)", + LUA_BINDIR="$(LUA_BINDIR)", + LUA_INCDIR="$(LUA_INCDIR)", + LUA="$(LUA)", + OPENSSL_INCDIR="$(OPENSSL_INCDIR)", + OPENSSL_LIBDIR="$(OPENSSL_LIBDIR)", + }, + install_variables = { + ENV_INST_PREFIX="$(PREFIX)", + ENV_INST_BINDIR="$(BINDIR)", + ENV_INST_LIBDIR="$(LIBDIR)", + ENV_INST_LUADIR="$(LUADIR)", + ENV_INST_CONFDIR="$(CONFDIR)", + }, +}