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

fix(routes): many requests for outdated routes by rate limiting #675

Merged
merged 1 commit into from
Jul 5, 2024

Conversation

apricote
Copy link
Member

@apricote apricote commented Jul 2, 2024

Fixes #673

In routes.ListRoutes() we have to find the matching server/node for every route in the network. We find the server by utilizing a cache that maps every private IP to the corresponding server.

This cache has a feature that refreshes the list of servers if an entry can not be found. This is sensible, as the server might have been just created. This is also fatal, as this refresh happens for every single cache access. If there are a lot of routes in the network that do not belong to any server, we refresh the cache many times for each ListRoutes(). This is even more serious, as ListRoutes() is being called every 10-30 seconds (see #395).

This commit introduces a rate.Limiter in the AllServersCache which only allows the refresh to happen every 30 seconds.

@apricote apricote added the bug Something isn't working label Jul 2, 2024
@apricote apricote self-assigned this Jul 2, 2024
Copy link

codecov bot commented Jul 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.26%. Comparing base (d018087) to head (7a3e3f4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #675      +/-   ##
==========================================
+ Coverage   72.10%   72.26%   +0.16%     
==========================================
  Files          32       32              
  Lines        2667     2668       +1     
==========================================
+ Hits         1923     1928       +5     
+ Misses        555      552       -3     
+ Partials      189      188       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Base automatically changed from routes-cache-refactor to main July 5, 2024 13:11
@apricote apricote marked this pull request as ready for review July 5, 2024 13:25
@apricote apricote requested a review from a team as a code owner July 5, 2024 13:25
Copy link
Member

@jooola jooola left a comment

Choose a reason for hiding this comment

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

I am a bit afraid of the unknown side effects of this workaround. I think we can merge this, but we might need to come up with a better fix in the future.

Fixes #673

In `routes.ListRoutes()` we have to find the matching server/node for
every route in the network. We find the server by utilizing a cache that
maps every private IP to the corresponding server.

This cache has a feature that refreshes the list of servers if an entry
can not be found. This is sensible, as the server might have been just
created. This is also fatal, as this refresh happens for every single
cache access. If there are a lot of routes in the network that do not
belong to any server, we refresh the cache many times for each
`ListRoutes()`. This is even more serious, as `ListRoutes()` is being
called every 10-30 seconds (see #395).

This commit introduces a `rate.Limiter` in the `AllServersCache` which
only allows the refresh to happen every 30 seconds.
@jooola
Copy link
Member

jooola commented Jul 5, 2024

I rebased onto main to resolve the go.mod conflict.

@apricote
Copy link
Member Author

apricote commented Jul 5, 2024

The primary side effect here is that new nodes might need additional 30s until routes are setup, if the project already had wonky routes.

@apricote apricote merged commit e283b7d into main Jul 5, 2024
8 checks passed
@apricote apricote deleted the routes-cache branch July 5, 2024 16:20
apricote pushed a commit that referenced this pull request Jul 8, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.20.0](v1.19.0...v1.20.0)
(2024-07-08)


### Features

* add support & tests for Kubernetes 1.29
([#600](#600))
([e8fabda](e8fabda))
* add support & tests for Kubernetes 1.30
([#679](#679))
([0748b6e](0748b6e))
* drop tests for kubernetes v1.25
([#597](#597))
([58261ec](58261ec))
* drop tests for kubernetes v1.26
([#680](#680))
([9c4be01](9c4be01))
* emit Kubernetes events for error conditions
([#598](#598))
([e8f9199](e8f9199))
* **helm,manifests:** only specify container args instead of command
([#691](#691))
([2ba4058](2ba4058))
* **helm:** allow setting affinity for deployment
([#686](#686))
([1a8ea95](1a8ea95))
* read HCLOUD_TOKEN from file
([#652](#652))
([a4343b8](a4343b8))


### Bug Fixes

* **routes:** many requests for outdated routes by rate limiting
([#675](#675))
([e283b7d](e283b7d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Too many API requests for outdated routes in the network
2 participants