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

Feature/bypass filter #194

Merged
merged 8 commits into from
Mar 21, 2024
Merged

Feature/bypass filter #194

merged 8 commits into from
Mar 21, 2024

Conversation

umairk79
Copy link
Collaborator

Add capability to bypass calls and not to use limiter algorithm if the provided predicate criteria is met

*/
public abstract static class BypassLimiterBuilder<BuilderT extends BypassLimiterBuilder<BuilderT, ContextT>, ContextT> extends Builder<BuilderT> {

private Predicate<ContextT> bypassResolver = (context) -> false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private Predicate<ContextT> bypassResolver = (context) -> false;
private static final Predicate<ContextT> ALWAYS_FALSE = (context) -> false;
private Predicate<ContextT> bypassResolver = ALWAYS_FALSE;

* @return Chainable builder
*/
public BuilderT bypassLimitResolver(Predicate<ContextT> shouldBypass) {
this.bypassResolver = bypassResolver.or(shouldBypass);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.bypassResolver = bypassResolver.or(shouldBypass);
if(this.bypassResolver == ALWAYS_FALSE) {
this.bypassResolver = shouldBypass;
} else {
this.bypassResolver = bypassResolver.or(shouldBypass);
}

Since this is on the hot path for calls, let's optimize away the default case instead of hoping that the JVM is able to do it later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the builder method. The else condition will be skipped everytime because this.bypassResolver is aways equal to ALWAYS_FALSE in your suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Read your code wrong. Applying suggestion.

.bypassLimitResolver(new ShouldBypassPredicate())
.build();

for (int i = 0; i < 1; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this for-loop runs once 😛

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's meant to run once because the partition for batch calls is 0.1 * 10 = 1, where 10 is the total limit.

Assert.assertEquals(i+1, limiter.getPartition("live").getInflight());
Assert.assertTrue(limiter.acquire("admin").isPresent());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

To be very clear about the behavior, let's add

Suggested change
}
// Verify that bypassed requests are able to proceed even when the limiter is full
Assert.assertFalse(limiter.acquire("live").isPresent());
Assert.assertEquals(10, limiter.getInflight());
Assert.assertTrue(limiter.acquire("admin").isPresent());
Assert.assertEquals(10, limiter.getInflight());
}

I understand that we've effectively covered that above, but this will be easier to understand for someone new to the codebase. It also helps defend against a setup issue (eg: if the limit is increased).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added extra check. This behavior is also validated for simple limiters in another test.

@umairk79 umairk79 requested a review from fedorka March 21, 2024 21:21
@umairk79 umairk79 merged commit 9808a48 into master Mar 21, 2024
1 check passed
github-merge-queue bot pushed a commit to camunda/camunda that referenced this pull request Mar 22, 2024
…mits-core to v0.4.2 (main) (#17049)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[com.netflix.concurrency-limits:concurrency-limits-core](https://togithub.com/Netflix/concurrency-limits)
| `0.4.1` -> `0.4.2` |
[![age](https://developer.mend.io/api/mc/badges/age/maven/com.netflix.concurrency-limits:concurrency-limits-core/0.4.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/com.netflix.concurrency-limits:concurrency-limits-core/0.4.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/com.netflix.concurrency-limits:concurrency-limits-core/0.4.1/0.4.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/com.netflix.concurrency-limits:concurrency-limits-core/0.4.1/0.4.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>Netflix/concurrency-limits
(com.netflix.concurrency-limits:concurrency-limits-core)</summary>

###
[`v0.4.2`](https://togithub.com/Netflix/concurrency-limits/releases/tag/v0.4.2)

[Compare
Source](https://togithub.com/Netflix/concurrency-limits/compare/v0.4.1...v0.4.2)

##### What's Changed

- Allow calls to be bypassed without altering limiter state by
[@&#8203;umairk79](https://togithub.com/umairk79) in
[Netflix/concurrency-limits#194

**Full Changelog**:
Netflix/concurrency-limits@v0.4.1...v0.4.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 10pm every weekday,before 6am
every weekday" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/camunda/zeebe).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjEuMCIsInVwZGF0ZWRJblZlciI6IjM3LjI2MS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
github-merge-queue bot pushed a commit to camunda/camunda that referenced this pull request Mar 28, 2024
…mits-core to v0.5.0 (main) (#17163)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[com.netflix.concurrency-limits:concurrency-limits-core](https://togithub.com/Netflix/concurrency-limits)
| `0.4.2` -> `0.5.0` |
[![age](https://developer.mend.io/api/mc/badges/age/maven/com.netflix.concurrency-limits:concurrency-limits-core/0.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/com.netflix.concurrency-limits:concurrency-limits-core/0.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/com.netflix.concurrency-limits:concurrency-limits-core/0.4.2/0.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/com.netflix.concurrency-limits:concurrency-limits-core/0.4.2/0.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>Netflix/concurrency-limits
(com.netflix.concurrency-limits:concurrency-limits-core)</summary>

###
[`v0.5.0`](https://togithub.com/Netflix/concurrency-limits/releases/tag/v0.5.0)

[Compare
Source](https://togithub.com/Netflix/concurrency-limits/compare/v0.4.2...v0.5.0)

##### What's Changed

- Add feature to allow calls to be bypassed without altering limiter
stater by [@&#8203;umairk79](https://togithub.com/umairk79) in
[Netflix/concurrency-limits#194
and by [@&#8203;fedorka](https://togithub.com/fedorka) in
[Netflix/concurrency-limits#197
- Upgrade nebula oss plugin and gradle to latest version by
[@&#8203;umairk79](https://togithub.com/umairk79) in
[Netflix/concurrency-limits#196

**Full Changelog**:
Netflix/concurrency-limits@v0.4.1...v0.5.0

##### Note: the previously released 0.4.2 inadvertently broke binary
compatibility in the limiter builders and should not be used.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 10pm every weekday,before 6am
every weekday" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/camunda/zeebe).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
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.

None yet

2 participants