Skip to content

Jmax/LG-12134 Spike use absolute timestamps for rate limiter Redis timeouts.#10009

Merged
jmax-gsa merged 5 commits intomainfrom
jmax/LG-12134-spike-only-redis-timestamps-for-rate-limiter
Feb 12, 2024
Merged

Jmax/LG-12134 Spike use absolute timestamps for rate limiter Redis timeouts.#10009
jmax-gsa merged 5 commits intomainfrom
jmax/LG-12134-spike-only-redis-timestamps-for-rate-limiter

Conversation

@jmax-gsa
Copy link
Copy Markdown
Contributor

@jmax-gsa jmax-gsa commented Jan 30, 2024

🎫 Ticket

Link to the relevant ticket:
LG-12134

🛠 Summary of changes

Changed Redis calls in RateLimiter to always use absolute time values, instead of relative ones.

This change is internal to the timestamp class, and not visible outside it.

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • Verify that all existing specs pass.
  • For each of the rate limiters in Handbook Rate Limiters Page , verify that the documented procedure for triggering each rate limiter still works as described.

@jmax-gsa jmax-gsa marked this pull request as ready for review January 30, 2024 23:52
@jmax-gsa jmax-gsa requested review from a team and mitchellhenke January 30, 2024 23:53
@jmax-gsa jmax-gsa force-pushed the jmax/LG-12134-spike-only-redis-timestamps-for-rate-limiter branch from f6e33a1 to 0d687e7 Compare January 31, 2024 15:48
Copy link
Copy Markdown
Contributor

@matthinz matthinz left a comment

Choose a reason for hiding this comment

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

Am I correct that the goal here is to make it possible to time travel in specs to affect rate limiters (which was not previously possible?)

If so, can you add a test to rate_limiter_spec.rb that fails when expire is used but passes when expireat is used?

@mitchellhenke
Copy link
Copy Markdown
Contributor

Similar to @matthinz's question, does this help situations like the test that initially led to trying the changes here?

@jmax-gsa
Copy link
Copy Markdown
Contributor Author

jmax-gsa commented Feb 8, 2024

Added a spec that fails if the redis calls use expire, but passes (now that we use) expireat

@jmax-gsa
Copy link
Copy Markdown
Contributor Author

jmax-gsa commented Feb 8, 2024

The basic problem stemmed from a mismatch between the Redis and Ruby timestamps.

Our tests allow for a one-second bobble, but between normal timing variations and the fact that we were sometimes using our clock, and sometimes Redis's, the bobble came to more than we tolerate sometimes, resulting in a few flaky specs.

Spec depended on rate limiter timeouts being in Redis-time, rather
than Ruby-time

changelog: Internal,Rate Limiting,Use absolute timestamps in Redis for
improved consistency.
Added spec which fails if we use relative timestamps.
@jmax-gsa jmax-gsa force-pushed the jmax/LG-12134-spike-only-redis-timestamps-for-rate-limiter branch from 2155612 to 91a5492 Compare February 12, 2024 20:40
@jmax-gsa jmax-gsa merged commit eb992e2 into main Feb 12, 2024
@jmax-gsa jmax-gsa deleted the jmax/LG-12134-spike-only-redis-timestamps-for-rate-limiter branch February 12, 2024 21:06
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.

3 participants