Skip to content

Commit

Permalink
fix: do not stop sampling processor when failing to delete trace even…
Browse files Browse the repository at this point in the history
…ts (#12509)

* fix: do not stop sampling processor when failing to delete trace events

The sampling processor should never stop when apm-server is running. Instead log
an error on Warn level and skip the current event.

* fix: handle ErrTxnTooBig when deleting trace events

(cherry picked from commit 6f0be72)
  • Loading branch information
kruskall authored and mergify[bot] committed Feb 15, 2024
1 parent fd30b42 commit 23ac871
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions x-pack/apm-server/sampling/eventstorage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ func estimateSize(e *badger.Entry) int64 {
// DeleteTraceEvent deletes the trace event from storage.
func (rw *ReadWriter) DeleteTraceEvent(traceID, id string) error {
key := append(append([]byte(traceID), ':'), id...)
err := rw.txn.Delete(key)
// If the transaction is already too big to accommodate the new entry, flush
// the existing transaction and set the entry on a new one, otherwise,
// returns early.
if err != badger.ErrTxnTooBig {
return err
}
if err := rw.Flush(); err != nil {
return err
}

return rw.txn.Delete(key)
}

Expand Down
4 changes: 2 additions & 2 deletions x-pack/apm-server/sampling/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,11 @@ func (p *Processor) Run() error {
switch event.Type() {
case modelpb.TransactionEventType:
if err := p.eventStore.DeleteTraceEvent(event.Trace.Id, event.Transaction.Id); err != nil {
return errors.Wrap(err, "failed to delete transaction from local storage")
p.logger.With(logp.Error(err)).Warn("failed to delete transaction from local storage")
}
case modelpb.SpanEventType:
if err := p.eventStore.DeleteTraceEvent(event.Trace.Id, event.Span.Id); err != nil {
return errors.Wrap(err, "failed to delete span from local storage")
p.logger.With(logp.Error(err)).Warn("failed to delete span from local storage")
}
}
}
Expand Down

0 comments on commit 23ac871

Please sign in to comment.