fix(eda): name a source's delivery header in the dashboard instead of a built-in sender list

This commit is contained in:
sam committed 2026-10-06 00:54:20 +11:00
1 parent a355f13a03
commit 0fc8535d87
24 files changed
+942 -667

No files matched your search

@@ -116,7 +116,7 @@ func TestRedeliveryDispatchesOnce(t *testing.T) {
return id
}
original, retry := capture("X-GitHub-Delivery:abc"), capture("X-GitHub-Delivery:abc")
original, retry := capture("delivery-1"), capture("delivery-1")
assertUndispatched(t, eda, 2)
if err := eda.RecordDispatch(ctx, bindingID, 1, original, 0, ""); err != nil {
t.Fatal(err)
@@ -126,7 +126,7 @@ func TestRedeliveryDispatchesOnce(t *testing.T) {
}
assertUndispatched(t, eda, 0)
capture("X-GitHub-Delivery:def")
capture("delivery-2")
capture("")
assertUndispatched(t, eda, 2)
captures, err := eda.ListCaptures(ctx, 10)
@@ -1,10 +1,14 @@
-- captures.delivery names the sender's delivery: its delivery ID header when
-- it sends one, else the capture itself. A retry of one delivery shares it, so
-- sources.delivery_header names the header a source's sender repeats on every
-- retry of one delivery. captures.delivery names the delivery: that header's
-- value when the source sets one and the sender sent it, else the capture
-- itself. A retry of one delivery shares it, so
-- binding_dispatches keyed on it dispatches each delivery once however many
-- times it arrives.
-- +goose Up
ALTER TABLE sources ADD COLUMN delivery_header text NOT NULL DEFAULT '';
ALTER TABLE captures ADD COLUMN delivery text NOT NULL DEFAULT '';
UPDATE captures SET delivery = id;
@@ -19,3 +23,4 @@ DROP INDEX idx_binding_dispatch_once;
CREATE UNIQUE INDEX idx_binding_dispatch_once ON binding_dispatches (binding, capture);
ALTER TABLE binding_dispatches DROP COLUMN delivery;
ALTER TABLE captures DROP COLUMN delivery;
ALTER TABLE sources DROP COLUMN delivery_header;
@@ -357,7 +357,7 @@ func (q *Queries) GetMapping(ctx context.Context, id string) (GetMappingRow, err
}
const getSource = `-- name: GetSource :one
SELECT path, signing, secret, created_at, updated_at, org_id, workspace_id, name FROM sources WHERE path = $1
SELECT path, signing, secret, created_at, updated_at, org_id, workspace_id, name, delivery_header FROM sources WHERE path = $1
`
func (q *Queries) GetSource(ctx context.Context, path string) (Source, error) {
@@ -372,6 +372,7 @@ func (q *Queries) GetSource(ctx context.Context, path string) (Source, error) {
&i.OrgID,
&i.WorkspaceID,
&i.Name,
&i.DeliveryHeader,
)
return i, err
}
@@ -860,7 +861,7 @@ func (q *Queries) ListMappings(ctx context.Context) ([]ListMappingsRow, error) {
}
const listSources = `-- name: ListSources :many
SELECT path, signing, secret, created_at, updated_at, org_id, workspace_id, name FROM sources ORDER BY created_at DESC, path
SELECT path, signing, secret, created_at, updated_at, org_id, workspace_id, name, delivery_header FROM sources ORDER BY created_at DESC, path
`
func (q *Queries) ListSources(ctx context.Context) ([]Source, error) {
@@ -881,6 +882,7 @@ func (q *Queries) ListSources(ctx context.Context) ([]Source, error) {
&i.OrgID,
&i.WorkspaceID,
&i.Name,
&i.DeliveryHeader,
); err != nil {
return nil, err
}
@@ -983,6 +985,23 @@ func (q *Queries) SetBindingDispatchTask(ctx context.Context, arg SetBindingDisp
return err
}
const setSourceDeliveryHeader = `-- name: SetSourceDeliveryHeader :execrows
UPDATE sources SET delivery_header = $2, updated_at = now() WHERE path = $1
`
type SetSourceDeliveryHeaderParams struct {
Path string
DeliveryHeader string
}
func (q *Queries) SetSourceDeliveryHeader(ctx context.Context, arg SetSourceDeliveryHeaderParams) (int64, error) {
result, err := q.db.Exec(ctx, setSourceDeliveryHeader, arg.Path, arg.DeliveryHeader)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const setSourceName = `-- name: SetSourceName :execrows
UPDATE sources SET name = $2, updated_at = now() WHERE path = $1
`
@@ -339,14 +339,15 @@ type Session struct {
}
type Source struct {
Path string
Signing string
Secret string
CreatedAt time.Time
UpdatedAt time.Time
OrgID string
WorkspaceID string
Name string
Path string
Signing string
Secret string
CreatedAt time.Time
UpdatedAt time.Time
OrgID string
WorkspaceID string
Name string
DeliveryHeader string
}
type StepExecution struct {
@@ -153,10 +153,10 @@ SELECT pg_advisory_xact_lock(hashtext('event_types:' || sqlc.arg(source)::text))
INSERT INTO sources (path, signing, secret) VALUES ($1, $2, $3);
-- name: GetSource :one
SELECT path, signing, secret, created_at, updated_at, org_id, workspace_id, name FROM sources WHERE path = $1;
SELECT path, signing, secret, created_at, updated_at, org_id, workspace_id, name, delivery_header FROM sources WHERE path = $1;
-- name: ListSources :many
SELECT path, signing, secret, created_at, updated_at, org_id, workspace_id, name FROM sources ORDER BY created_at DESC, path;
SELECT path, signing, secret, created_at, updated_at, org_id, workspace_id, name, delivery_header FROM sources ORDER BY created_at DESC, path;
-- name: SetSourceSigning :execrows
UPDATE sources SET signing = sqlc.arg(to_signing), updated_at = now()
@@ -168,6 +168,9 @@ UPDATE sources SET secret = $2, updated_at = now() WHERE path = $1;
-- name: SetSourceName :execrows
UPDATE sources SET name = $2, updated_at = now() WHERE path = $1;
-- name: SetSourceDeliveryHeader :execrows
UPDATE sources SET delivery_header = $2, updated_at = now() WHERE path = $1;
-- name: DeleteUnboundSource :execrows
-- A source an armed binding fires on is not deleted: the binding would
-- silently stop receiving events.
+13 -1
View File
@@ -114,6 +114,18 @@ func (s *EDA) SetSourceName(ctx context.Context, path, name string) error {
return nil
}
// SetSourceDeliveryHeader sets the header that names a source's deliveries.
func (s *EDA) SetSourceDeliveryHeader(ctx context.Context, path, header string) error {
n, err := s.q.SetSourceDeliveryHeader(ctx, postgresdb.SetSourceDeliveryHeaderParams{Path: path, DeliveryHeader: header})
if err != nil {
return fmt.Errorf("edastore: set source delivery header: %w", err)
}
if n == 0 {
return storecontract.ErrSourceNotFound
}
return nil
}
// DeleteSource deletes a source no armed binding fires on.
func (s *EDA) DeleteSource(ctx context.Context, path string) error {
n, err := s.q.DeleteUnboundSource(ctx, path)
@@ -155,7 +167,7 @@ func (s *EDA) sourceValue(r postgresdb.Source) (source.Source, error) {
secret = plain
}
return source.Source{
Path: r.Path, Name: r.Name, Signing: source.Signing(r.Signing), Secret: secret,
Path: r.Path, Name: r.Name, DeliveryHeader: r.DeliveryHeader, Signing: source.Signing(r.Signing), Secret: secret,
CreatedAt: r.CreatedAt, UpdatedAt: r.UpdatedAt,
}, nil
}