Skip to content

Commit

Permalink
Merge pull request #1449 from tkan145/threescale-5225-upstream_cannot…
Browse files Browse the repository at this point in the history
…_be_null

Logs: disable invalid upstream warning when api_backend is null and e…
  • Loading branch information
tkan145 authored Mar 20, 2024
2 parents 152cd27 + 511669a commit d40bd58
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- 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)

- 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)

### Added

- 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)
Expand Down
4 changes: 3 additions & 1 deletion gateway/src/apicast/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local Usage = require('apicast.usage')
local errors = require('apicast.errors')
local Upstream = require('apicast.upstream')
local escape = require("resty.http.uri_escape")
local cjson = require('cjson')

local assert = assert
local type = type
Expand Down Expand Up @@ -175,7 +176,8 @@ function _M.get_upstream(service, context)

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

Expand Down
13 changes: 13 additions & 0 deletions spec/proxy_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local http_ng_response = require('resty.http_ng.response')
local lrucache = require('resty.lrucache')
local cjson = require('cjson')

local configuration_store = require 'apicast.configuration_store'
local Service = require 'apicast.configuration.service'
Expand Down Expand Up @@ -64,6 +65,18 @@ describe('Proxy', function()
assert.falsy(err)
end)

it("on no api_backend return empty string and no error", function()
local upstream, err = get_upstream({api_backend = ''})
assert.falsy(upstream)
assert.falsy(err)
end)

it("on no api_backend return null and no error", function()
local upstream, err = get_upstream({api_backend = cjson.null})
assert.falsy(upstream)
assert.falsy(err)
end)

end)

describe('.authorize', function()
Expand Down

0 comments on commit d40bd58

Please sign in to comment.