Skip to content

Commit 511669a

Browse files
committed
Logs: disable invalid upstream warning when api_backend is null and empty
1 parent 152cd27 commit 511669a

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3939

4040
- Replace luafilesystem-ffi with [luafilesystem](https://github.com/lunarmodules/luafilesystem) [PR #1445](https://github.com/3scale/APIcast/pull/1445) [THREESCALE-10662](https://issues.redhat.com/browse/THREESCALE-10662)
4141

42+
- Fix "Upstream cannot be null" error in APIcast logs [PR #1449](https://github.com/3scale/APIcast/pull/1449) [THREESCALE-5225](https://issues.redhat.com/browse/THREESCALE-5225)
43+
4244
### Added
4345

4446
- Detect number of CPU shares when running on Cgroups V2 [PR #1410](https://github.com/3scale/apicast/pull/1410) [THREESCALE-10167](https://issues.redhat.com/browse/THREESCALE-10167)

gateway/src/apicast/proxy.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ local Usage = require('apicast.usage')
1414
local errors = require('apicast.errors')
1515
local Upstream = require('apicast.upstream')
1616
local escape = require("resty.http.uri_escape")
17+
local cjson = require('cjson')
1718

1819
local assert = assert
1920
local type = type
@@ -175,7 +176,8 @@ function _M.get_upstream(service, context)
175176

176177
-- Due to API as a product, the api_backend is no longer needed because this
177178
-- can be handled by routing policy
178-
if not service.api_backend then
179+
local api_backend = service.api_backend
180+
if not api_backend or api_backend == cjson.null or api_backend == '' then
179181
return nil, nil
180182
end
181183

spec/proxy_spec.lua

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local http_ng_response = require('resty.http_ng.response')
22
local lrucache = require('resty.lrucache')
3+
local cjson = require('cjson')
34

45
local configuration_store = require 'apicast.configuration_store'
56
local Service = require 'apicast.configuration.service'
@@ -64,6 +65,18 @@ describe('Proxy', function()
6465
assert.falsy(err)
6566
end)
6667

68+
it("on no api_backend return empty string and no error", function()
69+
local upstream, err = get_upstream({api_backend = ''})
70+
assert.falsy(upstream)
71+
assert.falsy(err)
72+
end)
73+
74+
it("on no api_backend return null and no error", function()
75+
local upstream, err = get_upstream({api_backend = cjson.null})
76+
assert.falsy(upstream)
77+
assert.falsy(err)
78+
end)
79+
6780
end)
6881

6982
describe('.authorize', function()

0 commit comments

Comments
 (0)