listeners

package
v0.0.0-...-914b764 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

README

package listeners

This package handles the network transmission for statsd protocols and returns packets to be processed by the dogstatsd package.

Packet

Packet is a statsd packet that might contain several statsd messages in it's Contents field. If origin detection is supported and enabled, the Origin field will hold the container id ready for tag resolution. If not, the field holds an empty string.

StatsdListener

StatsdListener is the common interface, currently implemented by:

  • UDPListener: handles the historical UDP protocol,
  • UDSListener: handles the host-local UDS protocol with optional origin detection, see the wiki for more info.

Origin Detection is Linux only

As our client implementations rely on Unix Credentials being added automatically by the Linux kernel, this feature is Linux only for now. If needed, server and client side could be updated and tested with other unices.

Documentation

Index

Constants

View Source
const NoOrigin = ""

NoOrigin is returned if origin detection is off or failed.

Variables

This section is empty.

Functions

This section is empty.

Types

type Packet

type Packet struct {
	Contents []byte // Contents, might contain several messages

	Origin string // Origin container if identified
	// contains filtered or unexported fields
}

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 PacketPool

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

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

func NewPacketPool(bufferSize int) *PacketPool

NewPacketPool creates a new pool with a specified buffer size

func (*PacketPool) Get

func (p *PacketPool) Get() *Packet

Get gets a Packet object read for use.

func (*PacketPool) Put

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

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

type Packets

type Packets []*Packet

Packets is a slice of packet pointers

type StatsdListener

type StatsdListener interface {
	Listen()
	Stop()
}

StatsdListener opens a communication channel to get statsd packets in.

type UDPListener

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

UDPListener implements the StatsdListener interface for UDP protocol. It listens to a given UDP address and sends back packets ready to be processed. Origin detection is not implemented for UDP.

func NewUDPListener

func NewUDPListener(packetOut chan Packets, sharedPacketPool *PacketPool) (*UDPListener, error)

NewUDPListener returns an idle UDP Statsd listener

func (*UDPListener) Listen

func (l *UDPListener) Listen()

Listen runs the intake loop. Should be called in its own goroutine

func (*UDPListener) Stop

func (l *UDPListener) Stop()

Stop closes the UDP connection and stops listening

type UDSListener

type UDSListener struct {
	OriginDetection bool
	// contains filtered or unexported fields
}

UDSListener implements the StatsdListener interface for Unix Domain Socket datagram protocol. It listens to a given socket path and sends back packets ready to be processed. Origin detection will be implemented for UDS.

func NewUDSListener

func NewUDSListener(packetOut chan Packets, sharedPacketPool *PacketPool) (*UDSListener, error)

NewUDSListener returns an idle UDS Statsd listener

func (*UDSListener) Listen

func (l *UDSListener) Listen()

Listen runs the intake loop. Should be called in its own goroutine

func (*UDSListener) Stop

func (l *UDSListener) Stop()

Stop closes the UDS connection and stops listening

Jump to

Keyboard shortcuts

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