Skip to content

Commit abd142e

Browse files
committed
docs: dedicated section for rate limiting
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 2318d4a commit abd142e

File tree

4 files changed

+52
-47
lines changed

4 files changed

+52
-47
lines changed

docs/content/en/docs/documentation/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This section contains detailed documentation for all Java Operator SDK features
1414
- **[Dependent Resources & Workflows](dependent-resource-and-workflows/)** - Managing resource relationships
1515
- **[Configuration](configuration/)** - Customizing operator behavior
1616
- **[Error Handling & Retries](error-handling-retries/)** - Managing failures gracefully
17+
- **[Rate Limiting](rate-limiting/)** - Controlling reconciliation frequency per resource
1718

1819
## Advanced Features
1920

docs/content/en/docs/documentation/eventing.md

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Event sources and related topics
3-
weight: 47
3+
weight: 48
44
---
55

66
## Handling Related Events with Event Sources
@@ -251,51 +251,6 @@ or any non-positive number.
251251
The automatic retries are not affected by this feature so a reconciliation will be re-triggered
252252
on error, according to the specified retry policy, regardless of this maximum interval setting.
253253

254-
## Rate Limiting
255-
256-
It is possible to rate limit reconciliation on a per-resource basis. The rate limit also takes
257-
precedence over retry/re-schedule configurations: for example, even if a retry was scheduled for
258-
the next second but this request would make the resource go over its rate limit, the next
259-
reconciliation will be postponed according to the rate limiting rules. Note that the
260-
reconciliation is never cancelled, it will just be executed as early as possible based on rate
261-
limitations.
262-
263-
Rate limiting is by default turned **off**, since correct configuration depends on the reconciler
264-
implementation, in particular, on how long a typical reconciliation takes.
265-
(The parallelism of reconciliation itself can be
266-
limited [`ConfigurationService`](https://github.com/java-operator-sdk/java-operator-sdk/blob/ce4d996ee073ebef5715737995fc3d33f4751275/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L120-L120)
267-
by configuring the `ExecutorService` appropriately.)
268-
269-
A default rate limiter implementation is provided, see:
270-
[`PeriodRateLimiter`](https://github.com/java-operator-sdk/java-operator-sdk/blob/ce4d996ee073ebef5715737995fc3d33f4751275/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/rate/PeriodRateLimiter.java#L14-L14)
271-
.
272-
Users can override it by implementing their own
273-
[`RateLimiter`](https://github.com/java-operator-sdk/java-operator-sdk/blob/ce4d996ee073ebef5715737995fc3d33f4751275/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/rate/RateLimiter.java)
274-
and specifying this custom implementation using the `rateLimiter` field of the
275-
`@ControllerConfiguration` annotation. Similarly to the `Retry` implementations,
276-
`RateLimiter` implementations must provide an accessible, no-arg constructor for instantiation
277-
purposes and can further be automatically configured from your own, provided annotation provided
278-
your `RateLimiter` implementation also implements the `AnnotationConfigurable` interface,
279-
parameterized by your custom annotation type.
280-
281-
To configure the default rate limiter use the `@RateLimited` annotation on your
282-
`Reconciler` class. The following configuration limits each resource to reconcile at most twice
283-
within a 3 second interval:
284-
285-
```java
286-
287-
@RateLimited(maxReconciliations = 2, within = 3, unit = TimeUnit.SECONDS)
288-
@ControllerConfiguration
289-
public class MyReconciler implements Reconciler<MyCR> {
290-
291-
}
292-
```
293-
294-
Thus, if a given resource was reconciled twice in one second, no further reconciliation for this
295-
resource will happen before two seconds have elapsed. Note that, since rate is limited on a
296-
per-resource basis, other resources can still be reconciled at the same time, as long, of course,
297-
that they stay within their own rate limits.
298-
299254
## Optimizing Caches
300255

301256
One of the ideas around the operator pattern is that all the relevant resources are cached, thus reconciliation is
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Rate limiting
3+
weight: 47
4+
---
5+
6+
It is possible to rate limit reconciliation on a per-resource basis. The rate limit also takes
7+
precedence over retry/re-schedule configurations: for example, even if retry would re-schedule a reconciliation
8+
but this request would make the resource go over its rate limit, the next
9+
reconciliation will be postponed according to the rate limiting rules. Note that the
10+
reconciliation is never canceled, it will just be executed as early as possible based on rate
11+
limitations.
12+
13+
Rate limiting is by default turned **off**, since correct configuration depends on the reconciler
14+
implementation, in particular, on how long a typical reconciliation takes.
15+
(The parallelism of reconciliation itself can be limited via
16+
[`ConfigurationService`](https://github.com/java-operator-sdk/java-operator-sdk/blob/ce4d996ee073ebef5715737995fc3d33f4751275/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L120-L120)
17+
by configuring the `ExecutorService` appropriately.)
18+
19+
We provide a generic rate limiter implementation:
20+
[`PeriodRateLimiter`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/rate/PeriodRateLimiter.java)
21+
.
22+
You can provide your own rate limiter by implementing the [`RateLimiter`](https://github.com/java-operator-sdk/java-operator-sdk/blob/ce4d996ee073ebef5715737995fc3d33f4751275/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/rate/RateLimiter.java)
23+
interface.
24+
25+
You can set this custom implementation using explicit [configuration](./operations/configuration.md) or using the `rateLimiter`
26+
field of the `@ControllerConfiguration` annotation.
27+
For the annotation approach, similarly to `Retry` implementations,
28+
`RateLimiter` implementations must provide an accessible, no-arg constructor for instantiation
29+
purposes and can further be automatically configured from your own annotation, provided that
30+
your `RateLimiter` implementation also implements the `AnnotationConfigurable` interface,
31+
parameterized by your custom annotation type.
32+
33+
To configure the default rate limiter, use the `@RateLimited` annotation on your
34+
`Reconciler` class. The following configuration limits each resource to reconcile at most twice
35+
within a 3 second interval:
36+
37+
```java
38+
39+
@RateLimited(maxReconciliations = 2, within = 3, unit = TimeUnit.SECONDS)
40+
@ControllerConfiguration
41+
public class MyReconciler implements Reconciler<MyCR> {
42+
43+
}
44+
```
45+
46+
Thus, if a given resource was reconciled twice in one second, no further reconciliation for this
47+
resource will happen before two seconds have elapsed. Note that, since rate is limited on a
48+
per-resource basis, other resources can still be reconciled at the same time, as long, of course,
49+
that they stay within their own rate limits.

docs/content/en/docs/documentation/working-with-es-caches.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Working with EventSource caches
3-
weight: 48
3+
weight: 49
44
---
55

66
As described in [Event sources and related topics](eventing.md), event sources serve as the backbone

0 commit comments

Comments
 (0)