flush pushes events to the event queue if they have been living in the queue more than the maximum allowed TTL period.
()
| 200 | // been living in the queue more than the maximum allowed |
| 201 | // TTL period. |
| 202 | func (s *StackwalkDecorator) flush() []error { |
| 203 | s.mux.Lock() |
| 204 | defer s.mux.Unlock() |
| 205 | |
| 206 | if len(s.buckets) == 0 { |
| 207 | return nil |
| 208 | } |
| 209 | |
| 210 | errs := make([]error, 0) |
| 211 | |
| 212 | for id, q := range s.buckets { |
| 213 | n := make([]*Event, 0, len(q)) |
| 214 | for _, evt := range q { |
| 215 | if time.Since(evt.Timestamp) < maxQueueTTLPeriod { |
| 216 | n = append(n, evt) |
| 217 | continue |
| 218 | } |
| 219 | |
| 220 | stackwalkFlushes.Add(1) |
| 221 | err := s.q.push(evt) |
| 222 | if err != nil { |
| 223 | errs = append(errs, err) |
| 224 | } |
| 225 | if stackwalkEnqueued.Value() > 0 { |
| 226 | stackwalkEnqueued.Add(-1) |
| 227 | } |
| 228 | if evt.PS != nil { |
| 229 | stackwalkFlushesProcs.Add(evt.PS.Name, 1) |
| 230 | } |
| 231 | stackwalkFlushesEvents.Add(evt.Name, 1) |
| 232 | } |
| 233 | if len(n) == 0 { |
| 234 | delete(s.buckets, id) |
| 235 | } else { |
| 236 | s.buckets[id] = n |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | return errs |
| 241 | } |