Skip to content

Commit c82b6f2

Browse files
authored
Merge branch 'apache:master' into remove-openldap
2 parents 5cf1be3 + 88da2ec commit c82b6f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1567
-293
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ jobs:
136136
[[ ${{ steps.test_env.outputs.type }} != first ]] && sudo ./ci/init-${{ steps.test_env.outputs.type }}-test-service.sh after
137137
echo "Linux launch services, done."
138138
- name: Start Dubbo Backend
139-
if: matrix.os_name == 'linux_openresty' && steps.test_env.outputs.type == 'plugin'
139+
if: matrix.os_name == 'linux_openresty' && (steps.test_env.outputs.type == 'plugin' || steps.test_env.outputs.type == 'last')
140140
run: |
141141
sudo apt install -y maven
142142
cd t/lib/dubbo-backend

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ install: runtime
375375
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/stream/xrpc/protocols/redis
376376
$(ENV_INSTALL) apisix/stream/xrpc/protocols/redis/*.lua $(ENV_INST_LUADIR)/apisix/stream/xrpc/protocols/redis/
377377

378+
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/stream/xrpc/protocols/dubbo
379+
$(ENV_INSTALL) apisix/stream/xrpc/protocols/dubbo/*.lua $(ENV_INST_LUADIR)/apisix/stream/xrpc/protocols/dubbo/
380+
378381
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/utils
379382
$(ENV_INSTALL) apisix/utils/*.lua $(ENV_INST_LUADIR)/apisix/utils/
380383

apisix/cli/ngx_tpl.lua

+12
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,12 @@ http {
365365
log_format main escape={* http.access_log_format_escape *} '{* http.access_log_format *}';
366366
uninitialized_variable_warn off;
367367
368+
{% if http.access_log_buffer then %}
369+
access_log {* http.access_log *} main buffer={* http.access_log_buffer *} flush=3;
370+
{% else %}
368371
access_log {* http.access_log *} main buffer=16384 flush=3;
369372
{% end %}
373+
{% end %}
370374
open_file_cache max=1000 inactive=60;
371375
client_max_body_size {* http.client_max_body_size *};
372376
keepalive_timeout {* http.keepalive_timeout *};
@@ -631,6 +635,14 @@ http {
631635
proxy_ssl_trusted_certificate {* ssl.ssl_trusted_certificate *};
632636
{% end %}
633637
638+
# opentelemetry_set_ngx_var starts
639+
{% if opentelemetry_set_ngx_var then %}
640+
set $opentelemetry_context_traceparent '';
641+
set $opentelemetry_trace_id '';
642+
set $opentelemetry_span_id '';
643+
{% end %}
644+
# opentelemetry_set_ngx_var ends
645+
634646
# http server configuration snippet starts
635647
{% if http_server_configuration_snippet then %}
636648
{* http_server_configuration_snippet *}

apisix/cli/ops.lua

+5
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,10 @@ Please modify "admin_key" in conf/config.yaml .
542542
end
543543
end
544544

545+
local opentelemetry_set_ngx_var
546+
if enabled_plugins["opentelemetry"] and yaml_conf.plugin_attr["opentelemetry"] then
547+
opentelemetry_set_ngx_var = yaml_conf.plugin_attr["opentelemetry"].set_ngx_var
548+
end
545549
-- Using template.render
546550
local sys_conf = {
547551
lua_path = env.pkg_path_org,
@@ -562,6 +566,7 @@ Please modify "admin_key" in conf/config.yaml .
562566
control_server_addr = control_server_addr,
563567
prometheus_server_addr = prometheus_server_addr,
564568
proxy_mirror_timeouts = proxy_mirror_timeouts,
569+
opentelemetry_set_ngx_var = opentelemetry_set_ngx_var
565570
}
566571

567572
if not yaml_conf.apisix then

apisix/core/response.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ function resp_exit(code, ...)
7070
error("failed to encode data: " .. err, -2)
7171
else
7272
idx = idx + 1
73-
t[idx] = body .. "\n"
73+
t[idx] = body
74+
idx = idx + 1
75+
t[idx] = "\n"
7476
end
7577

7678
elseif v ~= nil then
@@ -80,7 +82,7 @@ function resp_exit(code, ...)
8082
end
8183

8284
if idx > 0 then
83-
ngx_print(concat_tab(t, "", 1, idx))
85+
ngx_print(t)
8486
end
8587

8688
if code then

apisix/http/route.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,16 @@ function _M.create_radixtree_uri_router(routes, uri_routes, with_parameter)
103103
end
104104

105105

106-
function _M.match_uri(uri_router, match_opts, api_ctx)
107-
core.table.clear(match_opts)
106+
function _M.match_uri(uri_router, api_ctx)
107+
local match_opts = core.tablepool.fetch("route_match_opts", 0, 4)
108108
match_opts.method = api_ctx.var.request_method
109109
match_opts.host = api_ctx.var.host
110110
match_opts.remote_addr = api_ctx.var.remote_addr
111111
match_opts.vars = api_ctx.var
112112
match_opts.matched = core.tablepool.fetch("matched_route_record", 0, 4)
113113

114114
local ok = uri_router:dispatch(api_ctx.var.uri, match_opts, api_ctx, match_opts)
115+
core.tablepool.release("route_match_opts", match_opts)
115116
return ok
116117
end
117118

apisix/http/router/radixtree_host_uri.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ local function create_radixtree_router(routes)
142142
return true
143143
end
144144

145-
146-
local match_opts = {}
147145
function _M.match(api_ctx)
148146
local user_routes = _M.user_routes
149147
local _, service_version = get_services()
@@ -162,7 +160,7 @@ end
162160
function _M.matching(api_ctx)
163161
core.log.info("route match mode: radixtree_host_uri")
164162

165-
core.table.clear(match_opts)
163+
local match_opts = core.tablepool.fetch("route_match_opts", 0, 16)
166164
match_opts.method = api_ctx.var.request_method
167165
match_opts.remote_addr = api_ctx.var.remote_addr
168166
match_opts.vars = api_ctx.var
@@ -181,11 +179,13 @@ function _M.matching(api_ctx)
181179
api_ctx.curr_req_matched._host = api_ctx.real_curr_req_matched_host:reverse()
182180
api_ctx.real_curr_req_matched_host = nil
183181
end
182+
core.tablepool.release("route_match_opts", match_opts)
184183
return true
185184
end
186185
end
187186

188187
local ok = only_uri_router:dispatch(api_ctx.var.uri, match_opts, api_ctx, match_opts)
188+
core.tablepool.release("route_match_opts", match_opts)
189189
return ok
190190
end
191191

apisix/http/router/radixtree_uri.lua

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ local _M = {version = 0.2}
2727

2828
local uri_routes = {}
2929
local uri_router
30-
local match_opts = {}
3130
function _M.match(api_ctx)
3231
local user_routes = _M.user_routes
3332
local _, service_version = get_services()
@@ -51,8 +50,7 @@ end
5150

5251
function _M.matching(api_ctx)
5352
core.log.info("route match mode: radixtree_uri")
54-
55-
return base_router.match_uri(uri_router, match_opts, api_ctx)
53+
return base_router.match_uri(uri_router, api_ctx)
5654
end
5755

5856

apisix/http/router/radixtree_uri_with_parameter.lua

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ local _M = {}
2727

2828
local uri_routes = {}
2929
local uri_router
30-
local match_opts = {}
3130
function _M.match(api_ctx)
3231
local user_routes = _M.user_routes
3332
local _, service_version = get_services()
@@ -51,8 +50,7 @@ end
5150

5251
function _M.matching(api_ctx)
5352
core.log.info("route match mode: radixtree_uri_with_parameter")
54-
55-
return base_router.match_uri(uri_router, match_opts, api_ctx)
53+
return base_router.match_uri(uri_router, api_ctx)
5654
end
5755

5856

apisix/plugins/ext-plugin/init.lua

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ local ipairs = ipairs
6565
local pairs = pairs
6666
local tostring = tostring
6767
local type = type
68+
local ngx = ngx
6869

6970

7071
local events_list
@@ -655,6 +656,13 @@ local rpc_handlers = {
655656
end
656657
end
657658

659+
local body_len = rewrite:BodyLength()
660+
if body_len > 0 then
661+
local body = rewrite:BodyAsString()
662+
ngx.req.read_body()
663+
ngx.req.set_body_data(body)
664+
end
665+
658666
local len = rewrite:RespHeadersLength()
659667
if len > 0 then
660668
local rewrite_resp_headers = {}

apisix/plugins/opentelemetry.lua

+17
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ local type = type
4747
local pairs = pairs
4848
local ipairs = ipairs
4949
local unpack = unpack
50+
local string_format = string.format
5051

5152
local lrucache = core.lrucache.new({
5253
type = 'plugin', count = 128, ttl = 24 * 60 * 60,
@@ -112,6 +113,11 @@ local attr_schema = {
112113
},
113114
default = {},
114115
},
116+
set_ngx_var = {
117+
type = "boolean",
118+
description = "set nginx variables",
119+
default = false,
120+
},
115121
},
116122
}
117123

@@ -332,6 +338,17 @@ function _M.rewrite(conf, api_ctx)
332338
kind = span_kind.server,
333339
attributes = attributes,
334340
})
341+
342+
if plugin_info.set_ngx_var then
343+
local span_context = ctx:span():context()
344+
ngx_var.opentelemetry_context_traceparent = string_format("00-%s-%s-%02x",
345+
span_context.trace_id,
346+
span_context.span_id,
347+
span_context.trace_flags)
348+
ngx_var.opentelemetry_trace_id = span_context.trace_id
349+
ngx_var.opentelemetry_span_id = span_context.span_id
350+
end
351+
335352
api_ctx.otel_context_token = ctx:attach()
336353

337354
-- inject trace context into the headers of upstream HTTP request

apisix/plugins/proxy-cache/init.lua

+13-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ local plugin_name = "proxy-cache"
2525

2626
local STRATEGY_DISK = "disk"
2727
local STRATEGY_MEMORY = "memory"
28+
local DEFAULT_CACHE_ZONE = "disk_cache_one"
2829

2930
local schema = {
3031
type = "object",
@@ -33,7 +34,7 @@ local schema = {
3334
type = "string",
3435
minLength = 1,
3536
maxLength = 100,
36-
default = "disk_cache_one",
37+
default = DEFAULT_CACHE_ZONE,
3738
},
3839
cache_strategy = {
3940
type = "string",
@@ -129,14 +130,23 @@ function _M.check_schema(conf)
129130
local found = false
130131
local local_conf = core.config.local_conf()
131132
if local_conf.apisix.proxy_cache then
133+
local err = "cache_zone " .. conf.cache_zone .. " not found"
132134
for _, cache in ipairs(local_conf.apisix.proxy_cache.zones) do
135+
-- cache_zone passed in plugin config matched one of the proxy_cache zones
133136
if cache.name == conf.cache_zone then
134-
found = true
137+
-- check for the mismatch between cache_strategy and corresponding cache zone
138+
if (conf.cache_strategy == STRATEGY_MEMORY and cache.disk_path) or
139+
(conf.cache_strategy == STRATEGY_DISK and not cache.disk_path) then
140+
err = "invalid or empty cache_zone for cache_strategy: "..conf.cache_strategy
141+
else
142+
found = true
143+
end
144+
break
135145
end
136146
end
137147

138148
if found == false then
139-
return false, "cache_zone " .. conf.cache_zone .. " not found"
149+
return false, err
140150
end
141151
end
142152

apisix/plugins/proxy-cache/memory.lua

+11
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ end
3232

3333

3434
function _M:set(key, obj, ttl)
35+
if self.dict == nil then
36+
return nil, "invalid cache_zone provided"
37+
end
38+
3539
local obj_json = core.json.encode(obj)
3640
if not obj_json then
3741
return nil, "could not encode object"
@@ -43,6 +47,10 @@ end
4347

4448

4549
function _M:get(key)
50+
if self.dict == nil then
51+
return nil, "invalid cache_zone provided"
52+
end
53+
4654
-- If the key does not exist or has expired, then res_json will be nil.
4755
local res_json, err = self.dict:get(key)
4856
if not res_json then
@@ -63,6 +71,9 @@ end
6371

6472

6573
function _M:purge(key)
74+
if self.dict == nil then
75+
return nil, "invalid cache_zone provided"
76+
end
6677
self.dict:delete(key)
6778
end
6879

0 commit comments

Comments
 (0)