packets

package
v0.0.0-...-551a65d Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const NoOrigin = ""

NoOrigin is returned if origin detection is off or failed.

Variables

This section is empty.

Functions

func InitTelemetry

func InitTelemetry(buckets []float64)

InitTelemetry initialize the telemetry.Histogram buckets for the internal telemetry. This will be called once the first dogstatsd server is created since we need the configuration to be fully loaded.

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, 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) *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

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
	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

type Packets

type Packets []*Packet

Packets is a slice of packet pointers

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) *Pool

NewPool creates a new pool with a specified buffer size

func (*Pool) Get

func (p *Pool) Get() interface{}

Get gets a Packet object read for use.

func (*Pool) Put

func (p *Pool) Put(x interface{})

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

type PoolManager

type PoolManager 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(gp genericPool) *PoolManager

NewPoolManager creates a PoolManager to manage the underlying genericPool.

func (*PoolManager) Count

func (p *PoolManager) Count() int

Count returns the number of elements accounted by the PoolManager.

func (*PoolManager) Flush

func (p *PoolManager) Flush()

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

func (*PoolManager) Get

func (p *PoolManager) Get() interface{}

Get gets an object from the pool.

func (*PoolManager) IsPassthru

func (p *PoolManager) IsPassthru() bool

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

func (*PoolManager) Put

func (p *PoolManager) Put(x interface{})

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) SetPassthru

func (p *PoolManager) 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
)

Jump to

Keyboard shortcuts

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