Skip to content

Commit

Permalink
Changes how configuration is applied
Browse files Browse the repository at this point in the history
  • Loading branch information
acanimal committed Aug 4, 2015
1 parent bacf892 commit 431675e
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 238 deletions.
89 changes: 38 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,29 @@
# Simple Rate Limiter Filter

A basic rate limiter implementation filter for [Clyde](https://github.com/acanimal/clyde) API gateway, which allows to limit the provider's rate consume.
A basic rate limiter implementation filter for [Clyde](https://github.com/acanimal/clyde) API gateway, which allows to limit the rate consume.

> Implementation is based on [limiter](https://github.com/jhurliman/node-rate-limiter) module.
<!-- MarkdownTOC -->

- [Configuration](#configuration)
- [Examples](#examples)
- [Limit global access to 100 req/sec](#limit-global-access-to-100-reqsec)
- [Limit access to a provider to 100 req/sec](#limit-access-to-a-provider-to-100-reqsec)
- [Limit access to a provider to 100 req/sec and to the `userA` consumer rate limited to 20 req/sec](#limit-access-to-a-provider-to-100-reqsec-and-to-the-usera-consumer-rate-limited-to-20-reqsec)
- [Notes:](#notes)
- [License](#license)
- Configuration
- Examples
- Notes
- License

<!-- /MarkdownTOC -->

## Configuration

Rate limiter filter is extremely flexible and allows limit:
* Global access to the Clyde server.
* Global access by a given consumer.
* Access to a given provider.
* Access to a given provider by a given consumer.
* or chain all the previous limitations.

The filter accepts the configuration properties:
Rate limiter filter is extremely flexible and allows limit access globally or per consumer. The filter accepts the configuration properties:

* `global`: Specifies the limits to be applied globally. It must be an object with the properties:
- `tokens`: Number of allowed access
- `interval`: Interval within the previous accesses are allowed. Allowed values are: `sec/second`, `min/minute`, `hr/hour` and `day`.

* `consumers`: Specifies the global limits per consumers. For each consumer and object with `tokens` and `interval` properties must be specified.

* `providers`: Specifies the limits for each providers. It must be an object with the properties:
- `global`: Indicates limits applied to the provider (no matter which consumer).
- `consumers`: Indicates the limits per consumer.

At least one property must be specified, that is, at least `global`, `consumers` or `providers` must be set.

At least one property must be specified, that is, at least `global` or `consumers` must be set.

## Examples

Expand All @@ -48,8 +33,8 @@ At least one property must be specified, that is, at least `global`, `consumers`
{
"prefilters" : [
{
"id" : "rate-limit",
"path" : "simple-rate-limit",
"id" : "rate-limiter",
"path" : "clydeio-simple-rate-limiter",
"config" : {
"global" : {
"tokens" : 100,
Expand All @@ -58,6 +43,8 @@ At least one property must be specified, that is, at least `global`, `consumers`
...
}
}
],
"provider": [
...
]
}
Expand All @@ -67,24 +54,24 @@ At least one property must be specified, that is, at least `global`, `consumers`

```javascript
{
"prefilters" : [
providers: [
{
"id" : "rate-limit",
"path" : "simple-rate-limit",
"config" : {
"providers" : {
"providerId" : {
"id": "idProvider",
"context": "/provider",
"target": "http://provider_server",
"prefilters" : [
{
"id" : "rate-limiter",
"path" : "clydeio-simple-rate-limit",
"config" : {
"global" : {
"tokens" : 100,
"interval" : "second"
}
},
...
},
...
}
}
}
]
}
...
]
}
```
Expand All @@ -93,13 +80,16 @@ At least one property must be specified, that is, at least `global`, `consumers`

```javascript
{
"prefilters" : [
providers: [
{
"id" : "rate-limit",
"path" : "simple-rate-limit",
"config" : {
"providers" : {
"providerId" : {
"id": "idProvider",
"context": "/provider",
"target": "http://provider_server",
"prefilters" : [
{
"id" : "rate-limiter",
"path" : "clydeio-simple-rate-limit",
"config" : {
"global" : {
"tokens" : 100,
"interval" : "second"
Expand All @@ -109,22 +99,19 @@ At least one property must be specified, that is, at least `global`, `consumers`
"tokens" : 20,
"interval" : "second"
}
}
},
...
},
...
}
}
}
}
]
}
...
]
}
```

## Notes:
## Notes

* It has no sense configure the rate limiter filter as a global or provider's postfilter.
* Limits are applied in the order: global, consumers and providers. Be aware when chaining limits.
* Limits are applied in the order: global and consumers. Be aware when chaining limits.


# License
Expand Down
Loading

0 comments on commit 431675e

Please sign in to comment.