Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[THREESCALE-10130] APIcast using stale configuration for a deleted Product #1488

Conversation

tkan145
Copy link
Contributor

@tkan145 tkan145 commented Jul 22, 2024

What

Fix https://issues.redhat.com/browse/THREESCALE-10130

Verification steps

  • Install 3scale and create two Product A and B
  • Checkout this branch
  • Start development environment
make development
make dependencies
  • Start APIcast with THREESCALE_PORTAL_ENDPOINT=https://<token>@<provider domain>
THREESCALE_DEPLOYMENT_ENV=staging APICAST_LOG_LEVEL=debug APICAST_WORKER=1 APICAST_CONFIGURATION_LOADER=boot APICAST_CONFIGURATION_CACHE=60 THREESCALE_PORTAL_ENDPOINT=https://token@3scale-admin.example.com ./bin/apicast
  • Send requests
# capture apicast IP
APICAST_IP=$(docker inspect apicast_build_0-development-1 | yq e -P '.[0].NetworkSettings.Networks.apicast_build_0_default.IPAddress' -)

curl -v -k -H "Host: example.productA.com:443" -H "Accept: application/json" http://${APICAST_IP}:8080/user_key=<user_key>

curl -v -k -H "Host: example.productB.com:443" -H "Accept: application/json" http://${APICAST_IP}:8080/user_key=<user_key>
  • Both responses should be HTTP/1.1 200 OK
  • Now visit 3scale admin portal and delete ProductB.
  • Wait for APIcast to reload the configuration
  • Send request to ProductA, response should be HTTP/1.1 200 OK
  • Send request to ProductB, response should be HTTP/1.1 404 Not Found
< HTTP/1.1 404 Not Found
< Server: openresty
< Date: Tue, 23 Jul 2024 04:41:21 GMT
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Connection: keep-alive

@tkan145 tkan145 requested a review from a team as a code owner July 22, 2024 05:26
@tkan145 tkan145 force-pushed the THREESCALE-10130-invalid-stale-configuration-cache branch from 1569782 to 03291b5 Compare July 23, 2024 04:54
@tkan145 tkan145 changed the title [WIP] [THREESCALE 10130] APIcast using stale configuration for a deleted Product [THREESCALE 10130] APIcast using stale configuration for a deleted Product Jul 23, 2024
@tkan145 tkan145 changed the title [THREESCALE 10130] APIcast using stale configuration for a deleted Product [THREESCALE-10130] APIcast using stale configuration for a deleted Product Jul 23, 2024
@tkan145 tkan145 requested a review from kevprice83 July 23, 2024 08:09
@tkan145
Copy link
Contributor Author

tkan145 commented Jul 23, 2024

@kevprice83 can you also have a look at this PR?

Please ignore the CHANGELOG conflict, I will rebase later

@@ -229,7 +235,7 @@ local function lazy_load_config(configuration, host)
if not config then
ngx.log(ngx.WARN, 'failed to get config for host: ', host)
end
_M.configure(configuration, config)
_M.configure(configuration, config, host)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

host ? shouldn't be true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. Lazy mode will not return the stale configuration so we don't really need to clear the cache.

@eguzki
Copy link
Member

eguzki commented Aug 26, 2024

verification steps working as expected

When reloading the configuration, APIcast only updates the services
that present in the new configuration and leaves the old/deleted services
in the cache. When a new request is sent to the deleted service, APIcast
will reuse the stale configuration in the cache, leading to unexpected
behavior.

This PR ensures that APIcast always resets the cache when reloading
the configuration
@tkan145 tkan145 force-pushed the THREESCALE-10130-invalid-stale-configuration-cache branch from 03291b5 to e77139d Compare August 28, 2024 06:58
@@ -165,16 +165,18 @@ function _M.store(self, config, ttl)
return config
end

function _M.reset(self, cache_size)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the cache_size is never being used

@tkan145 tkan145 merged commit fddfd07 into 3scale:master Aug 29, 2024
14 checks passed
@tkan145 tkan145 deleted the THREESCALE-10130-invalid-stale-configuration-cache branch August 29, 2024 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants