Skip to content

Commit 5e1fabb

Browse files
authored
Fix: Webhook responses, event info on context, internal fix for labels matches (#3625)
* feat: add boolean flag for whether or not to return the event as the response payload * feat: add field to indicate whether or not to return the event * fix: wire up receive api * feat: more columns for event trigger idea * feat: start wiring up queries * feat: internal wiring * fix: matches, more wiring * fix: simplify query * fix: more wiring * fix: clean up dag impl for worker labels too * fix: wiring, unwind dag changes * fix: if * feat: add webhook response switch on fe * fix: casing * fix: populator * feat: add fields to assigned action for trigger * feat: send trigger data back over the api to the context * chore: gen py * feat: wire up context in py * feat: update webhooks feature client * feat: ts, go * chore: lint * fix: more wiring for replay * fix: nil handling * chore: gen * chore: attempt to fix flaky test * feat: wire up olap writes * fix: rm changes on the olap side for now * fix: improve the `was_triggered_by_event` prop * chore: gen, fix migration version * chore: versions, changelogs
1 parent a1861dc commit 5e1fabb

53 files changed

Lines changed: 1473 additions & 840 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api-contracts/dispatcher/dispatcher.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ message AssignedAction {
189189

190190
// (optional) the invocation count for durable task events (required for durable events, otherwise null)
191191
optional int32 durable_task_invocation_count = 21;
192+
193+
// (optional) the external id of the event that triggered this workflow run (if any)
194+
optional string triggering_event_external_id = 22;
195+
196+
// (optional) the key of the event that triggered this workflow run (if any)
197+
optional string triggering_event_key = 23;
192198
}
193199

194200
message WorkerListenRequest {

api-contracts/openapi/components/schemas/v1/webhook.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ V1Webhook:
2323
authType:
2424
$ref: "#/V1WebhookAuthType"
2525
description: The type of authentication to use for the webhook
26+
returnEventAsResponsePayload:
27+
type: boolean
28+
description: Whether to return the triggered event as the response payload when this webhook is triggered
2629
required:
2730
- metadata
2831
- tenantId
@@ -141,6 +144,9 @@ V1CreateWebhookRequestBase:
141144
staticPayload:
142145
type: object
143146
description: The static payload to use for the webhook. This is used to send a static payload with the webhook.
147+
returnEventAsResponsePayload:
148+
type: boolean
149+
description: Whether to return the triggered event as the response payload when this webhook is triggered
144150
required:
145151
- name
146152
- sourceName
@@ -212,6 +218,9 @@ V1UpdateWebhookRequest:
212218
staticPayload:
213219
type: object
214220
description: The static payload to use for the webhook. This is used to send a static payload with the webhook.
221+
returnEventAsResponsePayload:
222+
type: boolean
223+
description: Whether to return the triggered event as the response payload when this webhook is triggered
215224

216225
V1WebhookResponse:
217226
type: object

api/v1/server/handlers/v1/webhooks/create.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func (w *V1WebhooksService) constructCreateOpts(tenantId uuid.UUID, request gen.
130130
params.Name = basicAuth.Name
131131
params.Eventkeyexpression = basicAuth.EventKeyExpression
132132
params.ScopeExpression = basicAuth.ScopeExpression
133+
params.ReturnEventAsResponsePayload = returnEventResponsePayloadOrDefault(basicAuth.ReturnEventAsResponsePayload)
133134
if basicAuth.StaticPayload != nil {
134135
payloadBytes, err := json.Marshal(basicAuth.StaticPayload)
135136
if err != nil {
@@ -165,6 +166,7 @@ func (w *V1WebhooksService) constructCreateOpts(tenantId uuid.UUID, request gen.
165166
params.Name = apiKeyAuth.Name
166167
params.Eventkeyexpression = apiKeyAuth.EventKeyExpression
167168
params.ScopeExpression = apiKeyAuth.ScopeExpression
169+
params.ReturnEventAsResponsePayload = returnEventResponsePayloadOrDefault(apiKeyAuth.ReturnEventAsResponsePayload)
168170
if apiKeyAuth.StaticPayload != nil {
169171
payloadBytes, err := json.Marshal(apiKeyAuth.StaticPayload)
170172
if err != nil {
@@ -200,6 +202,7 @@ func (w *V1WebhooksService) constructCreateOpts(tenantId uuid.UUID, request gen.
200202
params.Name = hmacAuth.Name
201203
params.Eventkeyexpression = hmacAuth.EventKeyExpression
202204
params.ScopeExpression = hmacAuth.ScopeExpression
205+
params.ReturnEventAsResponsePayload = returnEventResponsePayloadOrDefault(hmacAuth.ReturnEventAsResponsePayload)
203206
if hmacAuth.StaticPayload != nil {
204207
payloadBytes, err := json.Marshal(hmacAuth.StaticPayload)
205208
if err != nil {
@@ -214,3 +217,11 @@ func (w *V1WebhooksService) constructCreateOpts(tenantId uuid.UUID, request gen.
214217

215218
return params, nil
216219
}
220+
221+
func returnEventResponsePayloadOrDefault(requestReturnEventAsResponsePayload *bool) bool {
222+
if requestReturnEventAsResponsePayload == nil {
223+
return true
224+
}
225+
226+
return *requestReturnEventAsResponsePayload
227+
}

api/v1/server/handlers/v1/webhooks/receive.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ func (w *V1WebhooksService) V1WebhookReceive(ctx echo.Context, request gen.V1Web
327327
return nil, fmt.Errorf("failed to ingest event")
328328
}
329329

330+
if !webhook.ReturnEventAsResponsePayload {
331+
ev = nil
332+
}
333+
330334
res, err := transformers.ToV1WebhookResponse(repository.StringPtr("ok"), nil, ev)
331335
if err != nil {
332336
return nil, fmt.Errorf("failed to transform response: %w", err)

api/v1/server/handlers/v1/webhooks/update.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ func (w *V1WebhooksService) V1WebhookUpdate(ctx echo.Context, request gen.V1Webh
1616
webhook := ctx.Get("v1-webhook").(*sqlcv1.V1IncomingWebhook)
1717

1818
opts := repository.UpdateWebhookOpts{
19-
EventKeyExpression: request.Body.EventKeyExpression,
20-
ScopeExpression: request.Body.ScopeExpression,
19+
EventKeyExpression: request.Body.EventKeyExpression,
20+
ScopeExpression: request.Body.ScopeExpression,
21+
ReturnEventAsResponsePayload: request.Body.ReturnEventAsResponsePayload,
2122
}
2223

2324
if request.Body.StaticPayload != nil {

api/v1/server/oas/gen/openapi.gen.go

Lines changed: 262 additions & 243 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/server/oas/transformers/v1/webhooks.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ func ToV1Webhook(webhook *sqlcv1.V1IncomingWebhook) gen.V1Webhook {
2222
UpdatedAt: webhook.UpdatedAt.Time,
2323
Id: id.String(),
2424
},
25-
TenantId: webhook.TenantID.String(),
26-
EventKeyExpression: webhook.EventKeyExpression,
27-
Name: webhook.Name,
28-
SourceName: gen.V1WebhookSourceName(webhook.SourceName),
25+
TenantId: webhook.TenantID.String(),
26+
EventKeyExpression: webhook.EventKeyExpression,
27+
Name: webhook.Name,
28+
SourceName: gen.V1WebhookSourceName(webhook.SourceName),
29+
ReturnEventAsResponsePayload: &webhook.ReturnEventAsResponsePayload,
2930
}
3031

3132
if webhook.ScopeExpression.Valid {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- +goose Up
2+
-- +goose StatementBegin
3+
ALTER TABLE v1_incoming_webhook ADD COLUMN return_event_as_response_payload BOOLEAN NOT NULL DEFAULT TRUE;
4+
ALTER TABLE v1_task
5+
ADD COLUMN triggering_event_external_id UUID,
6+
ADD COLUMN triggering_event_key TEXT
7+
;
8+
9+
ALTER TABLE v1_match
10+
ADD COLUMN trigger_event_external_id UUID,
11+
ADD COLUMN trigger_event_key TEXT,
12+
ADD COLUMN trigger_desired_worker_labels JSONB
13+
;
14+
-- +goose StatementEnd
15+
16+
-- +goose Down
17+
-- +goose StatementBegin
18+
ALTER TABLE v1_incoming_webhook DROP COLUMN return_event_as_response_payload;
19+
ALTER TABLE v1_task
20+
DROP COLUMN triggering_event_external_id,
21+
DROP COLUMN triggering_event_key
22+
;
23+
24+
ALTER TABLE v1_match
25+
DROP COLUMN trigger_event_external_id,
26+
DROP COLUMN trigger_event_key,
27+
DROP COLUMN trigger_desired_worker_labels
28+
;
29+
-- +goose StatementEnd

frontend/app/src/lib/api/generated/data-contracts.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,8 @@ export interface V1Webhook {
11221122
staticPayload?: object;
11231123
/** The type of authentication to use for the webhook */
11241124
authType: V1WebhookAuthType;
1125+
/** Whether to return the triggered event as the response payload when this webhook is triggered */
1126+
returnEventAsResponsePayload?: boolean;
11251127
}
11261128

11271129
export interface V1WebhookList {
@@ -1140,6 +1142,8 @@ export interface V1CreateWebhookRequestBase {
11401142
scopeExpression?: string;
11411143
/** The static payload to use for the webhook. This is used to send a static payload with the webhook. */
11421144
staticPayload?: object;
1145+
/** Whether to return the triggered event as the response payload when this webhook is triggered */
1146+
returnEventAsResponsePayload?: boolean;
11431147
}
11441148

11451149
export interface V1WebhookBasicAuth {
@@ -1204,6 +1208,8 @@ export interface V1UpdateWebhookRequest {
12041208
scopeExpression?: string;
12051209
/** The static payload to use for the webhook. This is used to send a static payload with the webhook. */
12061210
staticPayload?: object;
1211+
/** Whether to return the triggered event as the response payload when this webhook is triggered */
1212+
returnEventAsResponsePayload?: boolean;
12071213
}
12081214

12091215
export interface V1CELDebugRequest {

frontend/app/src/pages/main/v1/webhooks/hooks/use-webhooks.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export const webhookFormSchema = z.object({
105105
eventKeyExpression: z.string().min(1, 'Event key expression is required'),
106106
scopeExpression: z.string().optional(),
107107
staticPayload: optionalJsonString,
108+
returnEventAsResponsePayload: z.boolean().optional(),
108109
authType: z.nativeEnum(V1WebhookAuthType),
109110
username: z.string().optional(),
110111
password: z.string().optional(),
@@ -122,6 +123,7 @@ export const webhookUpdateFormSchema = z.object({
122123
eventKeyExpression: z.string().min(1, 'Event key expression is required'),
123124
scopeExpression: z.string().optional(),
124125
staticPayload: optionalJsonString,
126+
returnEventAsResponsePayload: z.boolean().optional(),
125127
});
126128

127129
export type WebhookUpdateFormData = z.infer<typeof webhookUpdateFormSchema>;

0 commit comments

Comments
 (0)