github.com/newrelic/go-agent@v3.26.0+incompatible/internal/priority.go (about)

     1  // Copyright 2020 New Relic Corporation. All rights reserved.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package internal
     5  
     6  // Priority allows for a priority sampling of events.  When an event
     7  // is created it is given a Priority.  Whenever an event pool is
     8  // full and events need to be dropped, the events with the lowest priority
     9  // are dropped.
    10  type Priority float32
    11  
    12  // According to spec, Agents SHOULD truncate the value to at most 6
    13  // digits past the decimal point.
    14  const (
    15  	priorityFormat = "%.6f"
    16  )
    17  
    18  // NewPriority returns a new priority.
    19  func NewPriority() Priority {
    20  	return Priority(RandFloat32())
    21  }
    22  
    23  // Float32 returns the priority as a float32.
    24  func (p Priority) Float32() float32 {
    25  	return float32(p)
    26  }
    27  
    28  func (p Priority) isLowerPriority(y Priority) bool {
    29  	return p < y
    30  }