Skip to content

Commit c9a9aa5

Browse files
committed
fix: attempt response schema
1 parent 8135e0d commit c9a9aa5

File tree

5 files changed

+41
-41
lines changed

5 files changed

+41
-41
lines changed

cmd/e2e/delivery_pipeline_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (s *basicSuite) TestDeliveryPipeline_PublishDeliversToWebhook() {
2727
s.Require().GreaterOrEqual(len(attempts), 1)
2828
first := attempts[0]
2929
s.NotEmpty(first["id"])
30-
s.Equal(dest.ID, first["destination"])
30+
s.Equal(dest.ID, first["destination_id"])
3131
s.NotEmpty(first["status"])
3232
}
3333

cmd/e2e/log_queries_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func (s *basicSuite) TestLogQueries_Attempts() {
7575

7676
first := resp.Models[0]
7777
s.NotEmpty(first["id"])
78-
s.NotEmpty(first["event"])
79-
s.Equal(setup.destinationID, first["destination"])
78+
s.NotEmpty(first["event_id"])
79+
s.Equal(setup.destinationID, first["destination_id"])
8080
s.NotEmpty(first["status"])
8181
s.NotEmpty(first["delivered_at"])
8282
s.Equal(float64(0), first["attempt_number"])

docs/apis/openapi.yaml

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,18 +1805,19 @@ components:
18051805
type: boolean
18061806
description: Whether this attempt was manually triggered (e.g., a retry initiated by a user).
18071807
example: false
1808+
event_id:
1809+
type: string
1810+
description: The ID of the associated event.
1811+
example: "evt_123"
1812+
destination_id:
1813+
type: string
1814+
description: The destination ID this attempt was sent to.
1815+
example: "des_456"
18081816
event:
18091817
oneOf:
1810-
- type: string
1811-
description: Event ID (default, no expansion).
1812-
example: "evt_123"
18131818
- $ref: "#/components/schemas/EventSummary"
18141819
- $ref: "#/components/schemas/EventFull"
1815-
description: The associated event. Returns event ID by default, or included event object when include=event or include=event.data.
1816-
destination:
1817-
type: string
1818-
description: The destination ID this attempt was sent to.
1819-
example: "des_456"
1820+
description: The associated event object. Only present when include=event or include=event.data.
18201821
EventSummary:
18211822
type: object
18221823
description: Event object without data (returned when include=event).
@@ -2584,15 +2585,15 @@ paths:
25842585
delivered_at: "2024-01-01T00:00:05Z"
25852586
code: "200"
25862587
attempt_number: 1
2587-
event: "evt_123"
2588-
destination: "des_456"
2588+
event_id: "evt_123"
2589+
destination_id: "des_456"
25892590
- id: "att_124"
25902591
status: "failed"
25912592
delivered_at: "2024-01-02T10:00:01Z"
25922593
code: "503"
25932594
attempt_number: 2
2594-
event: "evt_789"
2595-
destination: "des_789"
2595+
event_id: "evt_789"
2596+
destination_id: "des_789"
25962597
pagination:
25972598
order_by: "time"
25982599
dir: "desc"
@@ -2608,13 +2609,14 @@ paths:
26082609
delivered_at: "2024-01-01T00:00:05Z"
26092610
code: "200"
26102611
attempt_number: 1
2612+
event_id: "evt_123"
2613+
destination_id: "des_456"
26112614
event:
26122615
id: "evt_123"
26132616
topic: "user.created"
26142617
time: "2024-01-01T00:00:00Z"
26152618
eligible_for_retry: false
26162619
metadata: { "source": "crm" }
2617-
destination: "des_456"
26182620
pagination:
26192621
order_by: "time"
26202622
dir: "desc"
@@ -3141,15 +3143,15 @@ paths:
31413143
delivered_at: "2024-01-01T00:00:05Z"
31423144
code: "200"
31433145
attempt_number: 1
3144-
event: "evt_123"
3145-
destination: "des_456"
3146+
event_id: "evt_123"
3147+
destination_id: "des_456"
31463148
- id: "atm_124"
31473149
status: "failed"
31483150
delivered_at: "2024-01-02T10:00:01Z"
31493151
code: "503"
31503152
attempt_number: 2
3151-
event: "evt_789"
3152-
destination: "des_456"
3153+
event_id: "evt_789"
3154+
destination_id: "des_456"
31533155
pagination:
31543156
order_by: "time"
31553157
dir: "desc"
@@ -3220,8 +3222,8 @@ paths:
32203222
delivered_at: "2024-01-01T00:00:05Z"
32213223
code: "200"
32223224
attempt_number: 1
3223-
event: "evt_123"
3224-
destination: "des_456"
3225+
event_id: "evt_123"
3226+
destination_id: "des_456"
32253227
"404":
32263228
description: Tenant, Destination, or Attempt not found.
32273229

@@ -3679,15 +3681,15 @@ paths:
36793681
delivered_at: "2024-01-01T00:00:05Z"
36803682
code: "200"
36813683
attempt_number: 1
3682-
event: "evt_123"
3683-
destination: "des_456"
3684+
event_id: "evt_123"
3685+
destination_id: "des_456"
36843686
- id: "att_124"
36853687
status: "failed"
36863688
delivered_at: "2024-01-02T10:00:01Z"
36873689
code: "503"
36883690
attempt_number: 2
3689-
event: "evt_789"
3690-
destination: "des_456"
3691+
event_id: "evt_789"
3692+
destination_id: "des_456"
36913693
pagination:
36923694
order_by: "time"
36933695
dir: "desc"
@@ -3703,13 +3705,14 @@ paths:
37033705
delivered_at: "2024-01-01T00:00:05Z"
37043706
code: "200"
37053707
attempt_number: 1
3708+
event_id: "evt_123"
3709+
destination_id: "des_456"
37063710
event:
37073711
id: "evt_123"
37083712
topic: "user.created"
37093713
time: "2024-01-01T00:00:00Z"
37103714
eligible_for_retry: false
37113715
metadata: { "source": "crm" }
3712-
destination: "des_456"
37133716
pagination:
37143717
order_by: "time"
37153718
dir: "desc"
@@ -3774,8 +3777,8 @@ paths:
37743777
delivered_at: "2024-01-01T00:00:05Z"
37753778
code: "200"
37763779
attempt_number: 1
3777-
event: "evt_123"
3778-
destination: "des_456"
3780+
event_id: "evt_123"
3781+
destination_id: "des_456"
37793782
AttemptWithIncludeExample:
37803783
summary: Response with include=event.data,response_data
37813784
value:
@@ -3788,14 +3791,15 @@ paths:
37883791
body: '{"status":"ok"}'
37893792
headers: { "content-type": "application/json" }
37903793
attempt_number: 1
3794+
event_id: "evt_123"
3795+
destination_id: "des_456"
37913796
event:
37923797
id: "evt_123"
37933798
topic: "user.created"
37943799
time: "2024-01-01T00:00:00Z"
37953800
eligible_for_retry: false
37963801
metadata: { "source": "crm" }
37973802
data: { "user_id": "userid", "status": "active" }
3798-
destination: "des_456"
37993803
"404":
38003804
description: Tenant or Attempt not found.
38013805

internal/apirouter/log_handlers.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ type APIAttempt struct {
9393
AttemptNumber int `json:"attempt_number"`
9494
Manual bool `json:"manual"`
9595

96-
// Expandable fields - string (ID) or object depending on expand
97-
Event interface{} `json:"event"`
98-
99-
Destination string `json:"destination"`
96+
EventID string `json:"event_id"`
97+
DestinationID string `json:"destination_id"`
98+
Event interface{} `json:"event,omitempty"`
10099
}
101100

102101
// APIEventSummary is the event object when expand=event (without data)
@@ -149,7 +148,8 @@ func toAPIAttempt(ar *logstore.AttemptRecord, opts IncludeOptions) APIAttempt {
149148
Code: ar.Attempt.Code,
150149
AttemptNumber: ar.Attempt.AttemptNumber,
151150
Manual: ar.Attempt.Manual,
152-
Destination: ar.Attempt.DestinationID,
151+
EventID: ar.Attempt.EventID,
152+
DestinationID: ar.Attempt.DestinationID,
153153
}
154154

155155
if opts.ResponseData {
@@ -174,11 +174,7 @@ func toAPIAttempt(ar *logstore.AttemptRecord, opts IncludeOptions) APIAttempt {
174174
EligibleForRetry: ar.Event.EligibleForRetry,
175175
Metadata: ar.Event.Metadata,
176176
}
177-
} else {
178-
api.Event = ar.Event.ID
179177
}
180-
} else {
181-
api.Event = ar.Attempt.EventID
182178
}
183179

184180
return api

internal/apirouter/log_handlers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ func TestAPI_Attempts(t *testing.T) {
10051005
var result apirouter.AttemptPaginatedResult
10061006
require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &result))
10071007
assert.Len(t, result.Models, 1)
1008-
assert.Equal(t, "d1", result.Models[0].Destination)
1008+
assert.Equal(t, "d1", result.Models[0].DestinationID)
10091009
})
10101010

10111011
t.Run("excludes attempts from other tenants same destination", func(t *testing.T) {
@@ -1110,7 +1110,7 @@ func TestAPI_Attempts(t *testing.T) {
11101110
var attempt apirouter.APIAttempt
11111111
require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &attempt))
11121112
assert.Equal(t, "a1", attempt.ID)
1113-
assert.Equal(t, "d1", attempt.Destination)
1113+
assert.Equal(t, "d1", attempt.DestinationID)
11141114
})
11151115

11161116
t.Run("attempt belonging to different destination returns 404", func(t *testing.T) {

0 commit comments

Comments
 (0)