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

#1590 Use correct interval for request counting #1592

Conversation

sergio-str
Copy link
Contributor

@sergio-str sergio-str commented Aug 1, 2022

Fixes #1590

Incrementing request counter if request time is in the interval
[FirstRequestTime, FirstRequestTime + PeriodTimespan] seems is incorrect. PeriodTimespan is a "ban" period, not a period for request counting. In case of PeriodTimespan interval significantly exceeds Period, Rate Limiting feature counts number of requests longer than expected. It leads to false rate limit exceeding error.

Proposed Changes

Increment request counter when request time within interval
[FirstRequestTime, FirstRequestTime + RateLimitingSettingPeriod] respectively to the Rate Limiting docs.

@raman-m
Copy link
Member

raman-m commented May 11, 2023

Hi Sergii!

Thanks for the solution and interest in the project!

I've resolved one merge conflict. And pipelines are green.
Could we discuss the issue #1590 first plz?

@raman-m raman-m added needs validation Issue has not been replicated or verified yet in progress Someone is working on the issue. Could be someone on the team or off. waiting Waiting for answer to question or feedback from issue raiser labels May 11, 2023
@raman-m raman-m self-requested a review May 11, 2023 13:16
@sergio-str
Copy link
Contributor Author

Yes, sure.

@raman-m raman-m changed the title Use correct interval for request counting #1590 Use correct interval for request counting May 20, 2023
@raman-m
Copy link
Member

raman-m commented May 29, 2023

Sergii,

Now I see that at least your changes don't break current features.
But we have 2 parents in commit Merge branch 'develop' into Rate_linit_counting_interval_fix__issue_#….
I'm not a fan of merge commits with two parents after conflicts resolution, because they make non-linear history in base branch.
You need to put your commits on the top commit from base:develop!

Could I ask you to re-create PR please? Unfortunately your feature branch is broken. Your forked develop branch must be the same as develop branch in source repo!

  • Just backup files please with new changes.
  • Remove current fork, and make new fork to be sure you have the same history as in source repo having all commits up to date
    Or pull down all base:develop commits
  • Don't apply changes in develop, just keep it updated via pull operation always, just for future usage
  • Create new feature branch from develop one, for example, feat/1590
  • Apply new changes from files backup.
  • Create new PR
  • Do not forget to link both PRs (old and new ones) for tracking purposes

As soon as you've created new PR, this PR will be closed as duplicate.
Thanks!

@sergio-str
Copy link
Contributor Author

Hello Raman.
Sorry for significant delay, many things required my attention.
First, let me please confirm that you title and descr update is correct.
As for my implementation, I have a small doubt concerning timing calculation. I need to recheck them, and, perhaps, extend existing tests. Unfortunately I could not promise I will have solved it fast, but I will do all my best to finish with code changes in 2-3 weeks.
Cheers
S.

@raman-m
Copy link
Member

raman-m commented May 30, 2023

No worries, Sergii!
Take some time to finish the solution!
Tom will wait for your fix for a couple of years. 🤣 It's a joke!

@raman-m raman-m added needs feedback Issue is waiting on feedback before acceptance and removed in progress Someone is working on the issue. Could be someone on the team or off. labels May 30, 2023
@raman-m raman-m removed their request for review May 30, 2023 15:55
@raman-m
Copy link
Member

raman-m commented Jun 8, 2023

Sergii,
Please merge PR 1 to update your repo!
After merging let's try to find the best option to update feature branch which has some merge conflicts for rebase-operation...
Thank you!

@raman-m
Copy link
Member

raman-m commented Jun 20, 2023

sergio-str commented on May 29, 2023:

Unfortunately I could not promise I will have solved it fast, but I will do all my best to finish with code changes in 2-3 weeks.

Well... 3 weeks have been passed.
Any progress on that?
May I help you with this PR by some pair programming?

@raman-m raman-m force-pushed the Rate_linit_counting_interval_fix__issue_#1590 branch from a26e1ac to 8910ba1 Compare September 7, 2023 16:18
@raman-m raman-m added bug Identified as a potential bug and removed waiting Waiting for answer to question or feedback from issue raiser labels Sep 7, 2023
@raman-m
Copy link
Member

raman-m commented Sep 7, 2023

The feature branch has been rebased onto ThreeMammals:develop!
Welcome to code review!
I guess we can develop and review the code simultaneously.

@raman-m raman-m requested review from ggnaegi, RaynaldM and raman-m May 4, 2024 16:45
@raman-m
Copy link
Member

raman-m commented May 4, 2024

⚠️ Development Complete❕

@RaynaldM @ggnaegi Could you please review?
The remaining work involves testing the user scenario from #1590. I will add a few tests in the next day or two.
I anticipate that the user scenario tests will be completed by Monday.

The code quality was unexpectedly poor. It pertains to the oldest Ocelot feature, which lacked unit tests but had some rudimentary acceptance tests. Consequently, I decided to refactor the code slightly to enable unit test writing. The test coverage is now satisfactory. This feature was first introduced in PR #37 in 2017.

@ggnaegi
Copy link
Member

ggnaegi commented May 4, 2024

@raman-m Yes, around midnight your time!

Copy link
Member

@ggnaegi ggnaegi left a comment

Choose a reason for hiding this comment

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

Ok, some questions from my side, but then ok. Thanks!

src/Ocelot/RateLimiting/RateLimiting.cs Show resolved Hide resolved
src/Ocelot/RateLimiting/RateLimiting.cs Outdated Show resolved Hide resolved
src/Ocelot/RateLimiting/MemoryCacheRateLimitStorage.cs Outdated Show resolved Hide resolved
src/Ocelot/RateLimiting/IRateLimiting.cs Outdated Show resolved Hide resolved
@raman-m raman-m requested a review from ggnaegi May 5, 2024 11:57
@raman-m
Copy link
Member

raman-m commented May 5, 2024

All code review issues have been resolved! Awaiting your approval, @ggnaegi.
...after implementing the subsequent tests for bug/user scenarios. 😄

Copy link
Member

@raman-m raman-m left a comment

Choose a reason for hiding this comment

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

Approved, but the rest of work is 👇

  • Update feature docs. Done in commit 1ed45d0 ✔️

@raman-m
Copy link
Member

raman-m commented May 7, 2024

Ready for delivery ✅

  • Code review ✔️✔️
  • Team approvals ✔️✔️
  • Unit testing ✔️✔️ → RateLimitingTests and RateLimitingMiddlewareTests
  • Acceptance testing ✔️ → ClientRateLimitingTests
  • Feature docs ✔️ → ratelimiting.rst → commit 1ed45d0 where the entire document was reviewed and revised to reflect the new design

@raman-m raman-m merged commit aef3e6b into ThreeMammals:develop May 7, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identified as a potential bug high High priority Rate Limiting Ocelot feature: Rate Limiting Spring'24 Spring 2024 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rate Limiting works incorrectly if PeriodTimespan value is greater than Period
4 participants