In Service Mesh, in order to configure rate limit for a service, users have to face an unusually complex EnvoyFilter
rate limit configuration. To solve this problem, this project introduces SmartLimiter
, which can automatically convert user-submitted SmartLimiter
into EnvoyFilter
. Installation and Use
- easy to use, just submit
SmartLimiter
to achieve the purpose of service rate limit. - adaptive rate limit, dynamic triggering of rate limit rules according to
metric
. - Cover many scenarios, support global shared rate limit, global average rate limit, and single rate limit.
- single rate limit, each load of the service will have its own rate limit counter.
- global shared rate limit, all loads of a service share a single rate limit counter.
- global average rate limit, which distributes the rate limit counters equally among all loads. see function
To get users out of the tedious EnvoyFilter
configuration, we define an easy API
using kubernetes
CRD
mechanism, the SmartLimiter
resource within kubernetes
. After a user submits a SmartLimiter
to a kubernetes
cluster, the SmartLimiter Controler
generates an EnvoyFilter
in conjunction with the SmartLimiter
spec and service metrics.
The main architecture of adaptive rate limit is divided into two parts, one part includes the logical transformation of SmartLimiter
to EnvoyFilter
, and the other part includes the acquisition of monitoring data within the cluster, including service metrics such as CPU
, Memory
, POD
counts, etc., as detailed in architecture
When the total amount of cpu
consumed by all loads of the reviews
service is greater than 10, trigger a rate limit so that each load's port 9080 can only handle 10 requests per second, see example
apiVersion: microservice.slime.io/v1alpha2
kind: SmartLimiter
metadata:
name: review
namespace: default
spec:
sets:
_base:
descriptor:
- action:
fill_interval:
seconds: 1
quota: "10"
strategy: "single"
condition: "{{.v1.cpu.sum}}>10"
target:
port: 9080
- In order to complete the adaptive function, we need to get the basic metrics of the service, so this service depends on
prometheus
, for details on how to build a simpleprometheus
, see prometheus - In order to complete the global shared rate limitation, we need a global counter, we introduced
RLS
, aboutRLS
see RLS