packets

package
v0.0.0-...-8f37b9b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const NoOrigin = ""

NoOrigin is returned if origin detection is off or failed.

View Source
const SizeOfPacket = unsafe.Sizeof(Packet{})

SizeOfPacket is the size of a packet structure in bytes

Variables

This section is empty.

Functions

This section is empty.

Types

type Assembler

type Assembler struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Assembler merges multiple incoming datagrams into one "Packet" object to save space and make number of message in a single "Packet" more predictable

func NewAssembler

func NewAssembler(flushTimer time.Duration, packetsBuffer *Buffer, sharedPacketPoolManager *PoolManager[Packet], packetSourceType SourceType) *Assembler

NewAssembler creates a new Assembler instance using the specified flush duration, buffer and pool manager

func (*Assembler) AddMessage

func (p *Assembler) AddMessage(message []byte)

AddMessage adds a new dogstatsd message to the buffer

func (*Assembler) Close

func (p *Assembler) Close()

Close closes the packet assembler

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is a buffer of packets that will automatically flush to the given output channel when it is full or after a configurable duration.

func NewBuffer

func NewBuffer(bufferSize uint, flushTimer time.Duration, outputChannel chan Packets, listenerID string, telemetryStore *TelemetryStore) *Buffer

NewBuffer creates a new buffer of packets of specified size

func (*Buffer) Append

func (pb *Buffer) Append(packet *Packet)

Append appends a packet to the packet buffer and flushes if the buffer size is to be exceeded.

func (*Buffer) Close

func (pb *Buffer) Close()

Close closes the packet buffer

func (*Buffer) Flush

func (pb *Buffer) Flush()

Flush offers a thread-safe method to force a flush of the appended packets

type Packet

type Packet struct {
	Contents   []byte     // Contents, might contain several messages
	Buffer     []byte     // Underlying buffer for data read
	Origin     string     // Origin container if identified
	ListenerID string     // Listener ID
	Source     SourceType // Type of listener that produced the packet
}

Packet represents a statsd packet ready to process, with its origin metadata if applicable.

As the Packet object is reused in a sync.Pool, we keep the underlying buffer reference to avoid re-sizing the slice before reading

func (*Packet) DataSizeInBytes

func (p *Packet) DataSizeInBytes() int

DataSizeInBytes returns the size of the packet data in bytes

func (*Packet) SizeInBytes

func (p *Packet) SizeInBytes() int

SizeInBytes returns the size of the packet in bytes

type Packets

type Packets []*Packet

Packets is a slice of packet pointers

func (*Packets) DataSizeInBytes

func (ps *Packets) DataSizeInBytes() int

DataSizeInBytes returns the size of the packets data in bytes

func (*Packets) SizeInBytes

func (ps *Packets) SizeInBytes() int

SizeInBytes returns the size of the packets in bytes

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool wraps the sync.Pool class for *Packet type. It allows to avoid allocating one object per packet.

Caution: as objects get reused, byte slices extracted from packet.Contents will change when the object is reused. You need to hold on to the object until you extracted all the information and parsed it into strings/float/int.

Strings extracted with `string(Contents[n:m]) don't share the origin []byte storage, so they will be unaffected.

func NewPool

func NewPool(bufferSize int, packetsTelemetry *TelemetryStore) *Pool

NewPool creates a new pool with a specified buffer size

func (*Pool) Get

func (p *Pool) Get() *Packet

Get gets a Packet object read for use.

func (*Pool) Put

func (p *Pool) Put(packet *Packet)

Put resets the Packet origin and puts it back in the pool.

type PoolManager

type PoolManager[K managedPoolTypes] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

PoolManager helps manage sync pools so multiple references to the same pool objects may be held.

func NewPoolManager

func NewPoolManager[K managedPoolTypes](gp genericPool[K]) *PoolManager[K]

NewPoolManager creates a PoolManager to manage the underlying genericPool.

func (*PoolManager[K]) Count

func (p *PoolManager[K]) Count() int

Count returns the number of elements accounted by the PoolManager.

func (*PoolManager[K]) Flush

func (p *PoolManager[K]) Flush()

Flush flushes all objects back to the object pool, and stops tracking any pending objects.

func (*PoolManager[K]) Get

func (p *PoolManager[K]) Get() *K

Get gets an object from the pool.

func (*PoolManager[K]) IsPassthru

func (p *PoolManager[K]) IsPassthru() bool

IsPassthru returns a boolean telling us if the PoolManager is in passthru mode or not.

func (*PoolManager[K]) Put

func (p *PoolManager[K]) Put(x *K)

Put declares intent to return an object to the pool. In passthru mode the object is immediately returned to the pool, otherwise we wait until the object is put by all (only 2 currently supported) reference holders before actually returning it to the object pool.

func (*PoolManager[K]) SetPassthru

func (p *PoolManager[K]) SetPassthru(b bool)

SetPassthru sets the passthru mode to the specified value. It will flush the sccounting before enabling passthru mode.

type SourceType

type SourceType int

SourceType is the type of listener

const (
	// UDP listener
	UDP SourceType = iota
	// UDS listener
	UDS
	// NamedPipe Windows named pipe listner
	NamedPipe
)

type TelemetryStore

type TelemetryStore struct {
	// contains filtered or unexported fields
}

TelemetryStore holds all the telemetry counters and gauges for the dogstatsd packets

func NewTelemetryStore

func NewTelemetryStore(buckets []float64, telemetrycomp telemetry.Component) *TelemetryStore

NewTelemetryStore returns a new TelemetryStore

func (*TelemetryStore) TelemetryTrackPackets

func (t *TelemetryStore) TelemetryTrackPackets(packets Packets, listenerID string)

TelemetryTrackPackets tracks the number of packets in the channel and the number of bytes

func (*TelemetryStore) TelemetryUntrackPackets

func (t *TelemetryStore) TelemetryUntrackPackets(packets Packets)

TelemetryUntrackPackets untracks the number of packets in the channel and the number of bytes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL