@@ -121,27 +121,30 @@ func NewAntispam(ctx context.Context, badgerPath string, opts AntispamOpts) (*An
121121 case <- ticker .C :
122122 }
123123
124- runsInTick = 0
125- again:
126- start := time .Now ()
127- runsInTick ++
128- err := db .RunValueLogGC (0.7 )
129- status := "success"
130- if err != nil {
131- // We're done, export the number of runs we did.
132- gcRunsPerTick .Record (ctx , runsInTick )
133- if errors .Is (err , badger .ErrNoRewrite ) {
134- status = "no_rewrite"
135- } else {
136- status = "failure"
124+ _ = otel .TraceErr (ctx , "tessera.antispam.badger.garbage_collect" , tracer , func (ctx context.Context , span trace.Span ) error {
125+ runsInTick = 0
126+
127+ var err error
128+ for err == nil {
129+ start := time .Now ()
130+ runsInTick ++
131+ err = db .RunValueLogGC (0.7 )
132+ status := "success"
133+ if err != nil {
134+ // We're done, export the number of runs we did.
135+ gcRunsPerTick .Record (ctx , runsInTick )
136+ if errors .Is (err , badger .ErrNoRewrite ) {
137+ status = "no_rewrite"
138+ } else {
139+ status = "failure"
140+ }
141+ }
142+ attr := metric .WithAttributes (gcStatusKey .String (status ))
143+ gcCounter .Add (ctx , 1 , attr )
144+ gcDuration .Record (ctx , float64 (time .Since (start ).Milliseconds ()), attr )
137145 }
138- }
139- attr := metric .WithAttributes (gcStatusKey .String (status ))
140- gcCounter .Add (ctx , 1 , attr )
141- gcDuration .Record (ctx , float64 (time .Since (start ).Milliseconds ()), attr )
142- if err == nil {
143- goto again
144- }
146+ return nil
147+ }, trace .WithAttributes (otel .PeriodicKey .Bool (true )))
145148 }
146149 }()
147150
0 commit comments