priority.go 683 B

123456789101112131415161718192021222324252627
  1. package internal
  2. // Priority allows for a priority sampling of events. When an event
  3. // is created it is given a Priority. Whenever an event pool is
  4. // full and events need to be dropped, the events with the lowest priority
  5. // are dropped.
  6. type Priority float32
  7. // According to spec, Agents SHOULD truncate the value to at most 6
  8. // digits past the decimal point.
  9. const (
  10. priorityFormat = "%.6f"
  11. )
  12. // NewPriority returns a new priority.
  13. func NewPriority() Priority {
  14. return Priority(RandFloat32())
  15. }
  16. // Float32 returns the priority as a float32.
  17. func (p Priority) Float32() float32 {
  18. return float32(p)
  19. }
  20. func (p Priority) isLowerPriority(y Priority) bool {
  21. return p < y
  22. }