Skip to content

Commit

Permalink
Add support for Redis clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
alombarte committed Feb 5, 2025
1 parent f219d7f commit ed50496
Show file tree
Hide file tree
Showing 5 changed files with 403 additions and 3 deletions.
6 changes: 6 additions & 0 deletions test/v2.9/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,12 @@
"name": "shared_instance",
"address": "redis:6379"
}
],
"clusters": [
{
"name": "shared_redis_cluster",
"addresses": ["192.168.1.45:6379", "192.168.1.52:6379"]
}
]
},
"qos/ratelimit/service/redis": {
Expand Down
6 changes: 3 additions & 3 deletions test/v2.9/qos/service_redis_ratelimit.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"description": "All options",
"data": {
"@comment": "Hello",
"connection_pool": "shared_instance",
"connection_name": "shared_instance",
"on_failure_allow": false,
"max_rate": 10,
"capacity": 10,
Expand All @@ -26,15 +26,15 @@
{
"description": "Minimum options max_rate",
"data": {
"connection_pool": "shared_instance",
"connection_name": "shared_instance",
"max_rate": 10
},
"valid": true
},
{
"description": "Minimum options client_max_rate",
"data": {
"connection_pool": "shared_instance",
"connection_name": "shared_instance",
"client_max_rate": 10
},
"valid": true
Expand Down
197 changes: 197 additions & 0 deletions v2.9/krakend.json
Original file line number Diff line number Diff line change
Expand Up @@ -5668,6 +5668,18 @@
"connection_pool",
"client_max_rate"
]
},
{
"required": [
"connection_name",
"max_rate"
]
},
{
"required": [
"connection_name",
"client_max_rate"
]
}
],
"properties": {
Expand All @@ -5688,9 +5700,15 @@
"description": "Number of tokens you add to the [Token Bucket](https://www.krakend.io/docs/throttling/token-bucket/) for each individual user (*user quota*) in the time interval you want (`every`). The remaining tokens in the bucket are the requests a specific user can do. It keeps a counter for every client and endpoint. Keep in mind that every KrakenD instance keeps its counters in memory for **every single client**.\n\nSee: https://www.krakend.io/docs/enterprise/throttling/global-rate-limit/",
"type": "number"
},
"connection_name": {
"title": "Connection Name",
"description": "The connection pool name or cluster name that is used by this ratelimit. The value must match what you configured in the [Redis Connection Pool](/docs/enterprise/service-settings/redis-connection-pools/)",
"type": "string"
},
"connection_pool": {
"title": "Connection Pool Name",
"description": "The connection pool name that is used by this ratelimit. The value must match what you configured in the [Redis Connection Pool](/docs/enterprise/service-settings/redis-connection-pools/)",
"deprecated": true,
"type": "string"
},
"every": {
Expand Down Expand Up @@ -5884,6 +5902,185 @@
"description": "Defines the Redis connection pools available to any functionality requiring Redis.\n\nSee: /docs/enterprise/throttling/global-rate-limit/",
"type": "object",
"properties": {
"clusters": {
"title": "Cluster definitions",
"description": "Defines all the clusters available to Redis functionality. The different components requiring Redis will access the pool based on its name",
"type": "array",
"items": {
"type": "object",
"required": [
"name",
"addresses"
],
"properties": {
"addresses": {
"title": "Addresses",
"description": "The list of redis members that conform the cluster using the format `host:port`. All members must be WRITEABLE",
"examples": [
[
"192.168.1.45:6379",
"192.168.1.52:6379"
]
],
"type": "array",
"items": {
"title": "Redis member",
"description": "The address of a Redis member in the cluster",
"type": "string"
}
},
"client_name": {
"title": "Client name",
"description": "You can set how this connection shows in Redis when listing all the connections `CONN LIST`",
"examples": [
"krakend_pool"
],
"type": "string"
},
"conn_max_idle_time": {
"title": "Connection Max Idle Time",
"description": "The maximum amount of time a connection may be idle. Should be less than server's timeout.Expired connections may be closed lazily before reuse. If <= 0, connections are not closed due to a connection's idle time.",
"default": "30m",
"$ref": "#/definitions/https%3A~1~1www.krakend.io~1schema~1v2.9~1timeunits.json/$defs/timeunit",
"type": "string"
},
"conn_max_life_time": {
"title": "conn_max_life_time",
"description": "The maximum amount of time a connection may be reused. When the attribute is not declared, the connection does not expire",
"$ref": "#/definitions/https%3A~1~1www.krakend.io~1schema~1v2.9~1timeunits.json/$defs/timeunit",
"type": "string"
},
"dial_timeout": {
"title": "Dial Timeout",
"description": "Dial timeout for establishing new connections",
"default": "5s",
"$ref": "#/definitions/https%3A~1~1www.krakend.io~1schema~1v2.9~1timeunits.json/$defs/timeunit",
"type": "string"
},
"max_active_conns": {
"title": "Max active conns",
"description": "Maximum number of connections allocated by the pool at a given time. When zero, there is no limit on the number of connections in the pool.",
"default": 0,
"type": "integer"
},
"max_idle_conns": {
"title": "Max idle conns",
"description": "Maximum number of idle connections. The value `0` means connections not closed",
"default": 0,
"type": "integer"
},
"max_redirects": {
"title": "Max redirects",
"description": "The maximum number of redirects to follow when requesting a key that is in another instance",
"default": 3,
"type": "integer"
},
"max_retries": {
"title": "Max retries",
"description": "The number of times you want to retry a Redis command using a different connection from the pool, applying a random delay between `min_retry_backoff` and `max_retry_backoff`. Use `-1` to never retry (it might not be a good idea)",
"default": 3,
"type": "integer"
},
"max_retry_backoff": {
"title": "Max retry backoff",
"description": "Every retry is executed increasing randomly starting at the `min_retry_backoff` until the `max_retry_backoff` is reached. This is the longest possible time.",
"default": "512ms",
"$ref": "#/definitions/https%3A~1~1www.krakend.io~1schema~1v2.9~1timeunits.json/$defs/timeunit",
"type": "string"
},
"min_idle_conns": {
"title": "min_idle_conns",
"description": "Minimum number of idle connections which is useful when establishing new connection is slow. `0` means connections are not closed.",
"default": 0,
"type": "integer"
},
"min_retry_backoff": {
"description": "Every retry is executed increasing randomly starting at the `min_retry_backoff` until the `max_retry_backoff` is reached. This is the shortest possible time.",
"default": "8ms",
"$ref": "#/definitions/https%3A~1~1www.krakend.io~1schema~1v2.9~1timeunits.json/$defs/timeunit",
"type": "string"
},
"name": {
"title": "Connection name",
"description": "The connection pool name. This is an arbitrary name used to reference this connection in other parts of the configuration needing Redis.",
"examples": [
"shared_instance",
"Redis_for_ratelimit"
],
"type": "string"
},
"opentelemetry": {
"title": "OpenTelemetry",
"description": "The OpenTelemetry configuration establishing how to report Redis connection activity",
"type": "object",
"properties": {
"disable_metrics": {
"title": "Disable metrics",
"description": "Disables any metrics of this Redis pool",
"default": false,
"type": "boolean"
},
"disable_traces": {
"title": "Disable traces",
"description": "Disables any traces of this Redis pool",
"default": false,
"type": "boolean"
},
"traces_static_attributes": {
"title": "Static attributes",
"description": "Static attributes you want to pass for traces.",
"type": "array",
"items": {
"properties": {
"key": {
"title": "Key",
"description": "The key of the static attribute you want to send",
"type": "string"
},
"value": {
"title": "Value",
"description": "The value of the static attribute you want to send",
"type": "string"
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
},
"password": {
"title": "password",
"description": "Sets the password to connect to Redis.",
"type": "string"
},
"pool_size": {
"title": "Pool size",
"description": "The pool size defines the number of concurrent Redis commands that can be executed by this Redis pool. Take into account that this only saves the connection time to the server, but, Redis will still be a non-concurrent service. When `0` it maps to its default 10",
"default": 10,
"type": "integer"
},
"pool_timeout": {
"title": "Pool timeout",
"description": "Amount of time the client waits for a connection if all connections are busy.",
"$ref": "#/definitions/https%3A~1~1www.krakend.io~1schema~1v2.9~1timeunits.json/$defs/timeunit",
"type": "string"
},
"tls": {
"title": "tls",
"description": "An object with any [client TLS configuration](/docs/enterprise/service-settings/tls/#client-tls-settings) to this connection",
"$ref": "#/definitions/https%3A~1~1www.krakend.io~1schema~1v2.9~1client_tls.json",
"type": "object"
},
"user_name": {
"title": "Username",
"description": "The username to connect to Redis",
"type": "string"
}
},
"additionalProperties": false
}
},
"connection_pools": {
"title": "Connection Pools",
"description": "Defines all the connetion pools available to Redis functionality. The different components requiring Redis will access the pool based on its name",
Expand Down
18 changes: 18 additions & 0 deletions v2.9/qos/ratelimit/redis.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
"connection_pool",
"client_max_rate"
]
},
{
"required": [
"connection_name",
"max_rate"
]
},
{
"required": [
"connection_name",
"client_max_rate"
]
}
],
"properties": {
Expand All @@ -35,9 +47,15 @@
"description": "Number of tokens you add to the [Token Bucket](https://www.krakend.io/docs/throttling/token-bucket/) for each individual user (*user quota*) in the time interval you want (`every`). The remaining tokens in the bucket are the requests a specific user can do. It keeps a counter for every client and endpoint. Keep in mind that every KrakenD instance keeps its counters in memory for **every single client**.\n\nSee: https://www.krakend.io/docs/enterprise/throttling/global-rate-limit/",
"type": "number"
},
"connection_name": {
"title": "Connection Name",
"description": "The connection pool name or cluster name that is used by this ratelimit. The value must match what you configured in the [Redis Connection Pool](/docs/enterprise/service-settings/redis-connection-pools/)",
"type": "string"
},
"connection_pool": {
"title": "Connection Pool Name",
"description": "The connection pool name that is used by this ratelimit. The value must match what you configured in the [Redis Connection Pool](/docs/enterprise/service-settings/redis-connection-pools/)",
"deprecated": true,
"type": "string"
},
"every": {
Expand Down
Loading

0 comments on commit ed50496

Please sign in to comment.