File: priority.go

package info (click to toggle)
golang-github-newrelic-go-agent 3.15.2-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 8,356 kB
  • sloc: sh: 65; makefile: 6
file content (30 lines) | stat: -rw-r--r-- 785 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package internal

// Priority allows for a priority sampling of events.  When an event
// is created it is given a Priority.  Whenever an event pool is
// full and events need to be dropped, the events with the lowest priority
// are dropped.
type Priority float32

// According to spec, Agents SHOULD truncate the value to at most 6
// digits past the decimal point.
const (
	priorityFormat = "%.6f"
)

// NewPriority returns a new priority.
func NewPriority() Priority {
	return Priority(RandFloat32())
}

// Float32 returns the priority as a float32.
func (p Priority) Float32() float32 {
	return float32(p)
}

func (p Priority) isLowerPriority(y Priority) bool {
	return p < y
}