feat: dynamic rate limits (#904)

* wip: step run expressions on rate limits

* feat: dynamic rate limits

* chore: v0.47.0

* chore: address changes from PR review

* fix: improved error handling

* address pr review

* better error messages for step run cels, remove debug logs

* fix: hash

---------

Co-authored-by: gabriel ruttner <gabriel.ruttner@gmail.com>
This commit is contained in:
abelanger5
2024-09-26 18:00:34 -04:00
committed by GitHub
parent 5f5e1e8a88
commit a1a10b4073
65 changed files with 9628 additions and 2203 deletions
@@ -100,6 +100,14 @@ WorkflowID:
$ref: "./event.yaml#/WorkflowID"
EventList:
$ref: "./event.yaml#/EventList"
RateLimit:
$ref: "./rate_limits.yaml#/RateLimit"
RateLimitList:
$ref: "./rate_limits.yaml#/RateLimitList"
RateLimitOrderByField:
$ref: "./rate_limits.yaml#/RateLimitOrderByField"
RateLimitOrderByDirection:
$ref: "./rate_limits.yaml#/RateLimitOrderByDirection"
ReplayEventRequest:
$ref: "./event.yaml#/ReplayEventRequest"
CancelEventRequest:
@@ -0,0 +1,51 @@
RateLimit:
properties:
key:
type: string
description: The key for the rate limit.
tenantId:
type: string
description: The ID of the tenant associated with this rate limit.
limitValue:
type: integer
description: The maximum number of requests allowed within the window.
value:
type: integer
description: The current number of requests made within the window.
window:
type: string
description: The window of time in which the limitValue is enforced.
lastRefill:
type: string
format: date-time
example: 2022-12-13T15:06:48.888358-05:00
description: The last time the rate limit was refilled.
required:
- key
- tenantId
- limitValue
- value
- window
- lastRefill
RateLimitList:
properties:
pagination:
$ref: "./metadata.yaml#/PaginationResponse"
rows:
items:
$ref: "#/RateLimit"
type: array
RateLimitOrderByField:
type: string
enum:
- key
- value
- limitValue
RateLimitOrderByDirection:
type: string
enum:
- asc
- desc
+2
View File
@@ -100,6 +100,8 @@ paths:
$ref: "./paths/event/event.yaml#/replayEvents"
/api/v1/tenants/{tenant}/events/cancel:
$ref: "./paths/event/event.yaml#/cancelEvents"
/api/v1/tenants/{tenant}/rate-limits:
$ref: "./paths/rate-limits/rate_limits.yaml#/withTenant"
/api/v1/tenants/{tenant}/members:
$ref: "./paths/tenant/tenant.yaml#/members"
/api/v1/tenants/{tenant}/members/{member}:
@@ -0,0 +1,69 @@
withTenant:
get:
x-resources: ["tenant"]
description: Lists all rate limits for a tenant.
operationId: rate-limit:list
parameters:
- description: The tenant id
in: path
name: tenant
required: true
schema:
type: string
format: uuid
minLength: 36
maxLength: 36
- description: The number to skip
in: query
name: offset
required: false
schema:
type: integer
format: int64
- description: The number to limit by
in: query
name: limit
required: false
schema:
type: integer
format: int64
- description: The search query to filter for
in: query
name: search
required: false
schema:
type: string
- description: What to order by
in: query
name: orderByField
required: false
schema:
$ref: "../../components/schemas/_index.yaml#/RateLimitOrderByField"
- description: The order direction
in: query
name: orderByDirection
required: false
schema:
$ref: "../../components/schemas/_index.yaml#/RateLimitOrderByDirection"
responses:
"200":
content:
application/json:
schema:
$ref: "../../components/schemas/_index.yaml#/RateLimitList"
description: Successfully listed the rate limits
"400":
content:
application/json:
schema:
$ref: "../../components/schemas/_index.yaml#/APIErrors"
description: A malformed or bad request
"403":
content:
application/json:
schema:
$ref: "../../components/schemas/_index.yaml#/APIErrors"
description: Forbidden
summary: List rate limits
tags:
- Rate Limits
+5 -1
View File
@@ -117,7 +117,11 @@ message CreateWorkflowStepOpts {
message CreateStepRateLimit {
string key = 1; // (required) the key for the rate limit
int32 units = 2; // (required) the number of units this step consumes
optional int32 units = 2; // (optional) the number of units this step consumes
optional string key_expr = 3; // (optional) a CEL expression for determining the rate limit key
optional string units_expr = 4; // (optional) a CEL expression for determining the number of units consumed
optional string limit_values_expr = 5; // (optional) a CEL expression for determining the total amount of rate limit units
optional RateLimitDuration duration = 6; // (optional) the default rate limit window to use for dynamic rate limits
}
// ListWorkflowsRequest is the request for ListWorkflows.