Skip to content

Commit bc67cb0

Browse files
authored
fix(backend): log extra info during ingestion failure (#1686)
- send current request id when ingestion failure happens due to conflict - send current request timestamp when ingestion failure happens due to conflict - send previous request id when ingestion failure happens due to conflict - send previous request timestamp when ingestion failure happens due to conflict fixes #1682 Signed-off-by: detj <[email protected]>
1 parent d1d4e89 commit bc67cb0

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

backend/api/measure/event.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type attachment struct {
6161
type eventreq struct {
6262
id uuid.UUID
6363
appId uuid.UUID
64+
status status
6465
symbolicate map[uuid.UUID]int
6566
exceptionIds []int
6667
anrIds []int
@@ -69,6 +70,7 @@ type eventreq struct {
6970
events []event.EventField
7071
spans []span.SpanField
7172
attachments map[uuid.UUID]*attachment
73+
createdAt time.Time
7274
}
7375

7476
// status defines the status of processing
@@ -326,6 +328,23 @@ func (e eventreq) getStatus(ctx context.Context) (s *status, err error) {
326328
return
327329
}
328330

331+
// getRequest gets the details of an existing event request.
332+
func (e eventreq) getRequest(ctx context.Context) (r *eventreq, err error) {
333+
r = &eventreq{}
334+
335+
stmt := sqlf.PostgreSQL.From(`event_reqs`).
336+
Select("id").
337+
Select("status").
338+
Select("created_at").
339+
Where("id = ? and app_id = ?", e.id, e.appId)
340+
341+
defer stmt.Close()
342+
343+
err = server.Server.PgPool.QueryRow(ctx, stmt.String(), stmt.Args()...).Scan(&r.id, &r.status, &r.createdAt)
344+
345+
return
346+
}
347+
329348
// start inserts a new pending event request in persistent
330349
// storage.
331350
func (e eventreq) start(ctx context.Context) (err error) {
@@ -1996,6 +2015,7 @@ func PutEvents(c *gin.Context) {
19962015
appId: appId,
19972016
symbolicate: make(map[uuid.UUID]int),
19982017
attachments: make(map[uuid.UUID]*attachment),
2018+
createdAt: time.Now(),
19992019
}
20002020

20012021
if err := eventReq.read(c, appId); err != nil {
@@ -2039,9 +2059,22 @@ func PutEvents(c *gin.Context) {
20392059
switch *rs {
20402060
case pending:
20412061
durStr := fmt.Sprintf("%d", int64(retryAfter.Seconds()))
2062+
prevReq, err := eventReq.getRequest(ctx)
2063+
if err != nil {
2064+
msg := "failed to query event request"
2065+
fmt.Println(msg, err)
2066+
c.JSON(http.StatusInternalServerError, gin.H{
2067+
"error": msg,
2068+
})
2069+
return
2070+
}
20422071
c.Header("Retry-After", durStr)
20432072
c.JSON(http.StatusTooManyRequests, gin.H{
2044-
"warning": fmt.Sprintf("a previous accepted request is in progress, retry after %s seconds", durStr),
2073+
"warning": fmt.Sprintf("a previous accepted request is in progress, retry after %s seconds", durStr),
2074+
"current_request_id": eventReq.id,
2075+
"current_request_timestamp": eventReq.createdAt,
2076+
"previous_request_id": prevReq.id,
2077+
"previous_request_timestamp": prevReq.createdAt,
20452078
})
20462079
return
20472080
case done:

0 commit comments

Comments
 (0)