Skip to content

Commit

Permalink
chore: minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyDluffy6017 committed Nov 3, 2023
2 parents 888b469 + 7edf661 commit cbbfcd5
Show file tree
Hide file tree
Showing 70 changed files with 1,631 additions and 158 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/centos7-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- t/plugin/[a-k]*
- t/plugin/[l-z]*
- t/admin t/cli t/config-center-yaml t/control t/core t/debug t/discovery t/error_page t/misc
- t/node t/pubsub t/router t/script t/secret t/stream-node t/utils t/wasm t/xds-library
- t/node t/pubsub t/router t/script t/secret t/stream-node t/utils t/xds-library

steps:
- name: Check out code
Expand Down Expand Up @@ -94,6 +94,14 @@ jobs:
cd ..
rm -rf $(ls -1 -I apisix-build-tools -I t -I utils -I ci --ignore=Makefile -I "*.rockspec")
- name: Start Dubbo Backend
run: |
sudo apt install -y maven
cd t/lib/dubbo-backend
mvn package
cd dubbo-backend-provider/target
java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java.log &
- name: Build xDS library
if: steps.test_env.outputs.type == 'last'
run: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/close-unresponded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Prune Stale
uses: actions/stale@v8
with:
days-before-issue-stale: 14
days-before-issue-stale: 60
days-before-issue-close: 3
stale-issue-message: >
Due to lack of the reporter's response this issue has been labeled with "no response".
Expand All @@ -35,4 +35,5 @@ jobs:
# Issues with these labels will never be considered stale.
only-labels: 'wait for update'
stale-issue-label: 'no response'
exempt-issue-labels: "don't close"
ascending: true
4 changes: 3 additions & 1 deletion .github/workflows/doc-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:
paths:
- "docs/**"
- "**/*.md"
- ".github/workflows/doc-lint.yml"
pull_request:
branches: [master, "release/**"]
paths:
- "docs/**"
- "**/*.md"
- ".github/workflows/doc-lint.yml"

permissions:
contents: read
Expand All @@ -22,7 +24,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: 🚀 Use Node.js
uses: actions/setup-node@v3.8.1
uses: actions/setup-node@v4.0.0
with:
node-version: "12.x"
- run: npm install -g markdownlint-cli@0.25.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Nodejs env
uses: actions/setup-node@v3.8.1
uses: actions/setup-node@v4.0.0
with:
node-version: '12'

Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/redhat-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- t/plugin/[a-k]*
- t/plugin/[l-z]*
- t/admin t/cli t/config-center-yaml t/control t/core t/debug t/discovery t/error_page t/misc
- t/node t/pubsub t/router t/script t/secret t/stream-node t/utils t/wasm t/xds-library
- t/node t/pubsub t/router t/script t/secret t/stream-node t/utils t/xds-library

steps:
- name: Check out code
Expand Down Expand Up @@ -90,6 +90,14 @@ jobs:
cd ..
rm -rf $(ls -1 -I apisix-build-tools -I t -I utils -I ci --ignore=Makefile -I "*.rockspec")
- name: Start Dubbo Backend
run: |
sudo apt install -y maven
cd t/lib/dubbo-backend
mvn package
cd dubbo-backend-provider/target
java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar > /tmp/java.log &
- name: Build xDS library
if: steps.test_env.outputs.type == 'last'
run: |
Expand Down
20 changes: 20 additions & 0 deletions .requirements
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# 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.
#

APISIX_PACKAGE_NAME=apisix

APISIX_RUNTIME=1.0.1
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ endif
ifeq ($(ENV_OS_NAME), darwin)
ifeq ($(ENV_OS_ARCH), arm64)
ENV_HOMEBREW_PREFIX := /opt/homebrew
ENV_INST_BINDIR := $(ENV_INST_PREFIX)/local/bin
ENV_INST_LUADIR := $(shell which lua | xargs realpath | sed 's/bin\/lua//g')
endif

# OSX archive `._` cache file
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ A wide variety of companies and organizations use APISIX API Gateway for researc
- HONOR
- Horizon Robotics
- iQIYI
- Lenovo
- NASA JPL
- Nayuki
- OPPO
Expand All @@ -226,6 +227,7 @@ A wide variety of companies and organizations use APISIX API Gateway for researc
- Travelsky
- vivo
- Sina Weibo
- WeCity
- WPS
- XPENG
- Zoom
Expand Down
16 changes: 16 additions & 0 deletions apisix/admin/services.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
--
local core = require("apisix.core")
local get_routes = require("apisix.router").http_routes
local get_stream_routes = require("apisix.router").stream_routes
local apisix_upstream = require("apisix.upstream")
local resource = require("apisix.admin.resource")
local schema_plugin = require("apisix.admin.plugins").check_schema
Expand Down Expand Up @@ -99,6 +100,21 @@ local function delete_checker(id)
end
end

local stream_routes, stream_routes_ver = get_stream_routes()
core.log.info("stream_routes: ", core.json.delay_encode(stream_routes, true))
core.log.info("stream_routes_ver: ", stream_routes_ver)
if stream_routes_ver and stream_routes then
for _, route in ipairs(stream_routes) do
if type(route) == "table" and route.value
and route.value.service_id
and tostring(route.value.service_id) == id then
return 400, {error_msg = "can not delete this service directly,"
.. " stream_route [" .. route.value.id
.. "] is still using it now"}
end
end
end

return nil, nil
end

Expand Down
17 changes: 17 additions & 0 deletions apisix/admin/stream_routes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ local function check_conf(id, conf, need_id, schema)
end
end

local service_id = conf.service_id
if service_id then
local key = "/services/" .. service_id
local res, err = core.etcd.get(key)
if not res then
return nil, {error_msg = "failed to fetch service info by "
.. "service id [" .. service_id .. "]: "
.. err}
end

if res.status ~= 200 then
return nil, {error_msg = "failed to fetch service info by "
.. "service id [" .. service_id .. "], "
.. "response code: " .. res.status}
end
end

local ok, err = stream_route_checker(conf, true)
if not ok then
return nil, {error_msg = err}
Expand Down
10 changes: 9 additions & 1 deletion apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ http {
}
apisix.http_init(args)
-- set apisix_lua_home into constans module
-- set apisix_lua_home into constants module
-- it may be used by plugins to determine the work path of apisix
local constants = require("apisix.constants")
constants.apisix_lua_home = "{*apisix_lua_home*}"
Expand Down Expand Up @@ -643,6 +643,14 @@ http {
{% end %}
# opentelemetry_set_ngx_var ends
# zipkin_set_ngx_var starts
{% if zipkin_set_ngx_var then %}
set $zipkin_context_traceparent '';
set $zipkin_trace_id '';
set $zipkin_span_id '';
{% end %}
# zipkin_set_ngx_var ends
# http server configuration snippet starts
{% if http_server_configuration_snippet then %}
{* http_server_configuration_snippet *}
Expand Down
9 changes: 8 additions & 1 deletion apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,12 @@ Please modify "admin_key" in conf/config.yaml .
if enabled_plugins["opentelemetry"] and yaml_conf.plugin_attr["opentelemetry"] then
opentelemetry_set_ngx_var = yaml_conf.plugin_attr["opentelemetry"].set_ngx_var
end

local zipkin_set_ngx_var
if enabled_plugins["zipkin"] and yaml_conf.plugin_attr["zipkin"] then
zipkin_set_ngx_var = yaml_conf.plugin_attr["zipkin"].set_ngx_var
end

-- Using template.render
local sys_conf = {
lua_path = env.pkg_path_org,
Expand All @@ -566,7 +572,8 @@ Please modify "admin_key" in conf/config.yaml .
control_server_addr = control_server_addr,
prometheus_server_addr = prometheus_server_addr,
proxy_mirror_timeouts = proxy_mirror_timeouts,
opentelemetry_set_ngx_var = opentelemetry_set_ngx_var
opentelemetry_set_ngx_var = opentelemetry_set_ngx_var,
zipkin_set_ngx_var = zipkin_set_ngx_var
}

if not yaml_conf.apisix then
Expand Down
1 change: 1 addition & 0 deletions apisix/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ return {
},
STREAM_ETCD_DIRECTORY = {
["/upstreams"] = true,
["/services"] = true,
["/plugins"] = true,
["/ssls"] = true,
["/stream_routes"] = true,
Expand Down
4 changes: 3 additions & 1 deletion apisix/core/ctx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ do

elseif core_str.has_prefix(key, "post_arg_") then
-- only match default post form
if request.header(nil, "Content-Type") == "application/x-www-form-urlencoded" then
local content_type = request.header(nil, "Content-Type")
if content_type ~= nil and core_str.has_prefix(content_type,
"application/x-www-form-urlencoded") then
local arg_key = sub_str(key, 10)
local args = request.get_post_args()[arg_key]
if args then
Expand Down
3 changes: 2 additions & 1 deletion apisix/discovery/consul/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ local ngx_timer_every = ngx.timer.every
local log = core.log
local json_delay_encode = core.json.delay_encode
local ngx_worker_id = ngx.worker.id
local exiting = ngx.worker.exiting
local thread_spawn = ngx.thread.spawn
local thread_wait = ngx.thread.wait
local thread_kill = ngx.thread.kill
Expand Down Expand Up @@ -276,7 +277,7 @@ end


local function check_keepalive(consul_server, retry_delay)
if consul_server.keepalive then
if consul_server.keepalive and not exiting() then
local ok, err = ngx_timer_at(0, _M.connect, consul_server, retry_delay)
if not ok then
log.error("create ngx_timer_at got error: ", err)
Expand Down
2 changes: 1 addition & 1 deletion apisix/http/service.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function _M.init_worker()
filter = filter,
})
if not services then
error("failed to create etcd instance for fetching upstream: " .. err)
error("failed to create etcd instance for fetching /services: " .. err)
return
end
end
Expand Down
31 changes: 30 additions & 1 deletion apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ end


function _M.http_exit_worker()
-- TODO: we can support stream plugin later - currently there is not `destory` method
-- TODO: we can support stream plugin later - currently there is not `destroy` method
-- in stream plugins
plugin.exit_worker()
require("apisix.plugins.ext-plugin.init").exit_worker()
Expand Down Expand Up @@ -1021,6 +1021,7 @@ function _M.stream_init_worker()
plugin.init_worker()
xrpc.init_worker()
router.stream_init_worker()
require("apisix.http.service").init_worker()
apisix_upstream.init_worker()

local we = require("resty.worker.events")
Expand Down Expand Up @@ -1078,6 +1079,34 @@ function _M.stream_preread_phase()

api_ctx.matched_upstream = upstream

elseif matched_route.value.service_id then
local service = service_fetch(matched_route.value.service_id)
if not service then
core.log.error("failed to fetch service configuration by ",
"id: ", matched_route.value.service_id)
return core.response.exit(404)
end

matched_route = plugin.merge_service_stream_route(service, matched_route)
api_ctx.matched_route = matched_route
api_ctx.conf_type = "stream_route&service"
api_ctx.conf_version = matched_route.modifiedIndex .. "&" .. service.modifiedIndex
api_ctx.conf_id = matched_route.value.id .. "&" .. service.value.id
api_ctx.service_id = service.value.id
api_ctx.service_name = service.value.name
api_ctx.matched_upstream = matched_route.value.upstream
if matched_route.value.upstream_id and not matched_route.value.upstream then
local upstream = apisix_upstream.get_by_id(matched_route.value.upstream_id)
if not upstream then
if is_http then
return core.response.exit(502)
end

return ngx_exit(1)
end

api_ctx.matched_upstream = upstream
end
else
if matched_route.has_domain then
local err
Expand Down
46 changes: 46 additions & 0 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ local stream_local_plugins_hash = core.table.new(0, 32)
local merged_route = core.lrucache.new({
ttl = 300, count = 512
})
local merged_stream_route = core.lrucache.new({
ttl = 300, count = 512
})
local expr_lrucache = core.lrucache.new({
ttl = 300, count = 512
})
Expand Down Expand Up @@ -637,6 +640,49 @@ function _M.merge_service_route(service_conf, route_conf)
end


local function merge_service_stream_route(service_conf, route_conf)
-- because many fields in Service are not supported by stream route,
-- so we copy the stream route as base object
local new_conf = core.table.deepcopy(route_conf)
if service_conf.value.plugins then
for name, conf in pairs(service_conf.value.plugins) do
if not new_conf.value.plugins then
new_conf.value.plugins = {}
end

if not new_conf.value.plugins[name] then
new_conf.value.plugins[name] = conf
end
end
end

new_conf.value.service_id = nil

if not new_conf.value.upstream and service_conf.value.upstream then
new_conf.value.upstream = service_conf.value.upstream
end

if not new_conf.value.upstream_id and service_conf.value.upstream_id then
new_conf.value.upstream_id = service_conf.value.upstream_id
end

return new_conf
end


function _M.merge_service_stream_route(service_conf, route_conf)
core.log.info("service conf: ", core.json.delay_encode(service_conf, true))
core.log.info(" stream route conf: ", core.json.delay_encode(route_conf, true))

local version = route_conf.modifiedIndex .. "#" .. service_conf.modifiedIndex
local route_service_key = route_conf.value.id .. "#"
.. version
return merged_stream_route(route_service_key, version,
merge_service_stream_route,
service_conf, route_conf)
end


local function merge_consumer_route(route_conf, consumer_conf, consumer_group_conf)
if not consumer_conf.plugins or
core.table.nkeys(consumer_conf.plugins) == 0
Expand Down
Loading

0 comments on commit cbbfcd5

Please sign in to comment.