About Ocelot's advanced Rate Limiting functionality #2391
-
|
Hi, I have the following question.
My aim is to limit the use of a specific route that contains a dynamic placeholder. For example consider "UpstreamPathTemplate": "/shop/bigdiscounts/{orderId}", My question is twofold:
Thanks in advice. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
Maurizio, thanks for asking the question. What's your LinkedIn? I don't see a forked repo un your GH repos. As far as I understood, you started to use Ocelot.
The Rate Limiting feature is agnostic to placeholders, since the rate limiting cache key (caching counter value for a route) includes the upstream path as part of the caching key. Here are the parts that the load balancing key consists of: Ocelot/src/Ocelot/Configuration/Creator/RouteKeyCreator.cs Lines 22 to 39 in e324bba Finally, each route has a unique load balancing key; thus, each route has a dedicated rate limiter.
If you have one route containing a If you meant that the sum of all counters for all routes containing a and the next step is injecting custom middleware into Ocelot pipeline here: you see this middleware can't be overridden, but this restriction can be easily eliminated by patching the Ocelot pipeline configuration. I can't provide you with a complete and workable solution since development takes time, so I'm letting you develop in your own forked repository (please fork the repo and develop).
No, it won't. The rate limiter keeps counters in the cache, which is a memory cache by default and is added to the DI container: But there is good news, since there is a DistributedCacheRateLimitStorage class that can be added to DI. Thus, you can build a cluster of Ocelot instances, which will use the same rate limiting distributed storage (databases).
Ocelot has no database, and it should not, due to Ocelot's major responsibility, which is routing and transforming traffic as a reverse proxy or as an API gateway. Tracking each request and keeping request data in a database will significantly degrade gateway performance. If you want to attach a distributed database, you must do the following:
After these manipulations, your rate limiting will support clustering (using shared distributed caches). |
Beta Was this translation helpful? Give feedback.
-
Regarding overriding the middleware... A week ago I merged interesting PR #2387, which provides the ability to override So, we could override |
Beta Was this translation helpful? Give feedback.
Maurizio, thanks for asking the question. What's your LinkedIn?
I don't see a forked repo un your GH repos. As far as I understood, you started to use Ocelot.
It would be worth seeing the complete configuration, aka
ocelot.jsonfile.The Rate Limiting feature is agnostic to placeholders, since the rate limiting cache key (caching counter value for a route) includes the upstream path as part of the caching key.
Ocelot/src/Ocelot/RateLimiting/RateLimitingMiddleware.cs
Line 107 in e324bba