Skip to content

Commit

Permalink
fix(backend): log extra info during ingestion failure (#1686)
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
detj authored Jan 3, 2025
1 parent d1d4e89 commit bc67cb0
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion backend/api/measure/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type attachment struct {
type eventreq struct {
id uuid.UUID
appId uuid.UUID
status status
symbolicate map[uuid.UUID]int
exceptionIds []int
anrIds []int
Expand All @@ -69,6 +70,7 @@ type eventreq struct {
events []event.EventField
spans []span.SpanField
attachments map[uuid.UUID]*attachment
createdAt time.Time
}

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

// getRequest gets the details of an existing event request.
func (e eventreq) getRequest(ctx context.Context) (r *eventreq, err error) {
r = &eventreq{}

stmt := sqlf.PostgreSQL.From(`event_reqs`).
Select("id").
Select("status").
Select("created_at").
Where("id = ? and app_id = ?", e.id, e.appId)

defer stmt.Close()

err = server.Server.PgPool.QueryRow(ctx, stmt.String(), stmt.Args()...).Scan(&r.id, &r.status, &r.createdAt)

return
}

// start inserts a new pending event request in persistent
// storage.
func (e eventreq) start(ctx context.Context) (err error) {
Expand Down Expand Up @@ -1996,6 +2015,7 @@ func PutEvents(c *gin.Context) {
appId: appId,
symbolicate: make(map[uuid.UUID]int),
attachments: make(map[uuid.UUID]*attachment),
createdAt: time.Now(),
}

if err := eventReq.read(c, appId); err != nil {
Expand Down Expand Up @@ -2039,9 +2059,22 @@ func PutEvents(c *gin.Context) {
switch *rs {
case pending:
durStr := fmt.Sprintf("%d", int64(retryAfter.Seconds()))
prevReq, err := eventReq.getRequest(ctx)
if err != nil {
msg := "failed to query event request"
fmt.Println(msg, err)
c.JSON(http.StatusInternalServerError, gin.H{
"error": msg,
})
return
}
c.Header("Retry-After", durStr)
c.JSON(http.StatusTooManyRequests, gin.H{
"warning": fmt.Sprintf("a previous accepted request is in progress, retry after %s seconds", durStr),
"warning": fmt.Sprintf("a previous accepted request is in progress, retry after %s seconds", durStr),
"current_request_id": eventReq.id,
"current_request_timestamp": eventReq.createdAt,
"previous_request_id": prevReq.id,
"previous_request_timestamp": prevReq.createdAt,
})
return
case done:
Expand Down

0 comments on commit bc67cb0

Please sign in to comment.