Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ APISIX is a cloud-native microservices API gateway, delivering the ultimate perf

### CentOS
#### Dependencies

- OpenResty
```shell
sudo yum install yum-utils
Expand Down Expand Up @@ -76,7 +77,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='{"methods":[
```

```shell
curl -i -H 'host:baidu.com' 127.0.0.1:9080/hello
curl -i -H 'Host: baidu.com' 127.0.0.1:9080/hello
```


Expand Down
1 change: 1 addition & 0 deletions conf/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
etcd:
host: "http://127.0.0.1:2379"
prefix: "/v2/keys/apisix"
timeout: 60

plugins:
Expand Down
2 changes: 1 addition & 1 deletion lua/apisix/balancer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ end

function _M.init_worker()
local err
upstreams_etcd, err = core.config.new("/user_upstreams",
upstreams_etcd, err = core.config.new("/upstreams",
{automatic = true})
if not upstreams_etcd then
error("failed to create etcd instance to fetch upstream: " .. err)
Expand Down
27 changes: 21 additions & 6 deletions lua/apisix/core/config_etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ local _M = {
version = 0.1,
local_conf = fetch_local_conf,
}
local mt = {__index = _M}
local mt = {
__index = _M,
__tostring = function(self)
return " etcd key: " .. self.key
end
}


local function readdir(etcd_cli, key)
Expand Down Expand Up @@ -176,19 +181,29 @@ local function _automatic_fetch(premature, self)
return
end

-- optimize: avoid to use this timer always.
while not exiting() and self.running do
local i = 0
while not exiting() and self.running and i <= 32 do
i = i + 1
local ok, res, err = pcall(self.fetch, self)
if not ok then
err = res
log.error("failed to fetch data from etcd: ", err)
log.error("failed to fetch data from etcd: ", err, ", ",
tostring(self))
ngx_sleep(10)
break

elseif not res and err and err ~= "timeout" then
log.error("failed to fetch data from etcd: ", err)
elseif not res and err and err ~= "timeout"
and err ~= "Key not found" then
log.error("failed to fetch data from etcd: ", err, ", ",
tostring(self))
ngx_sleep(5)
break
end
end

if not exiting() and self.running then
ngx_timer_at(0, _automatic_fetch, self)
end
end


Expand Down
2 changes: 1 addition & 1 deletion lua/apisix/core/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function resp_exit(code, ...)
insert_tab(t, idx, body)
end

else
elseif v ~= nil then
idx = idx + 1
insert_tab(t, idx, v)
end
Expand Down
4 changes: 2 additions & 2 deletions lua/apisix/plugins/limit-count.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ function _M.access(conf, ctx)
if not delay then
local err = remaining
if err == "rejected" then
return core.response.say(conf.rejected_code)
return conf.rejected_code
end

core.log.error("failed to limit req: ", err)
return core.response.say(500)
return 500
end

core.response.set_header("X-RateLimit-Limit", conf.count)
Expand Down
6 changes: 3 additions & 3 deletions lua/apisix/route.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ end

function _M.get()
-- core.log.warn("conf_routes.version: ", conf_routes.version)
return core.lrucache.global("/user_routes", conf_routes.version,
return core.lrucache.global("/routes", conf_routes.version,
create_r3_router, conf_routes.values)
end


function _M.init_worker()
local err
conf_routes, err = core.config.new("/user_routes", {automatic = true})
conf_routes, err = core.config.new("/routes", {automatic = true})
if not conf_routes then
error("failed to create etcd instance to fetch /user_routes "
error("failed to create etcd instance to fetch /routes "
.. "automaticly: " .. err)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lua/apisix/service.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ end

function _M.init_worker()
local err
services, err = core.config.new("/user_services", {automatic = true})
services, err = core.config.new("/services", {automatic = true})
if not services then
error("failed to create etcd instance to fetch upstream: " .. err)
return
Expand Down