replay

package
v0.0.0-...-1dd94e2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package server implements a component to run the dogstatsd capture/replay

Index

Constants

View Source
const (
	// GUID will be used as the GUID during capture replays
	// This is a magic number chosen for no particular reason other than the fact its
	// quite large an improbable to match an actual Group ID on any given box. We
	// need this number to identify replayed Unix socket ancillary credentials.
	GUID = 999888777
)

Variables

View Source
var CapPool = sync.Pool{
	New: func() interface{} {
		return new(CaptureBuffer)
	},
}

CapPool is a pool of CaptureBuffer

View Source
var (

	//nolint:revive // TODO(AML) Fix revive linter
	ErrHeaderWrite = fmt.Errorf("capture file header could not be fully written to buffer")
)

Functions

func GetUcredsForPid

func GetUcredsForPid(pid int32) []byte

GetUcredsForPid returns the replay ucreds for the specified pid

func MockModule

func MockModule() fxutil.Module

MockModule defines the fx options for the mock component.

func Module

func Module() fxutil.Module

Module defines the fx options for this component.

func OpenFile

func OpenFile(fs afero.Fs, l string, defaultLocation string) (afero.File, string, error)

OpenFile checks that location is acceptable for a capture and creates a new file using given fs implementation.

func Read

func Read(r io.Reader) ([]byte, error)

Read reads the next protobuf packet available in the file and returns it in a byte slice, and an error if any.

func WriteHeader

func WriteHeader(w io.Writer) error

WriteHeader writes the datadog header to the Writer argument to conform to the .dog file format.

Types

type CaptureBuffer

type CaptureBuffer struct {
	Pb          pb.UnixDogstatsdMsg
	Oob         *[]byte
	Pid         int32
	ContainerID string
	Buff        *packets.Packet
}

CaptureBuffer holds pointers to captured packet's buffers (and oob buffer if required) and the protobuf message used for serialization.

type Component

type Component interface {

	// IsOngoing returns whether a capture is ongoing for this TrafficCapture instance.
	IsOngoing() bool

	// StartCapture starts a TrafficCapture and returns an error in the event of an issue.
	StartCapture(p string, d time.Duration, compressed bool) (string, error)

	// StopCapture stops an ongoing TrafficCapture.
	StopCapture()

	// TODO: (components) pool manager should be injected as a component in the future.
	// RegisterSharedPoolManager registers the shared pool manager with the TrafficCapture.
	RegisterSharedPoolManager(p *packets.PoolManager) error

	// TODO: (components) pool manager should be injected as a component in the future.
	// RegisterOOBPoolManager registers the OOB shared pool manager with the TrafficCapture.f
	RegisterOOBPoolManager(p *packets.PoolManager) error

	// Enqueue enqueues a capture buffer so it's written to file.
	Enqueue(msg *CaptureBuffer) bool

	// GetStartUpError returns an error if TrafficCapture failed to start up
	GetStartUpError() error
}

Component is the component type.

func NewServerlessTrafficCapture

func NewServerlessTrafficCapture() Component

TODO: (components) - remove once serverless is an FX app

type Mock

type Mock interface {
	Component
}

Mock implements mock-specific methods.

type TrafficCaptureReader

type TrafficCaptureReader struct {
	Contents []byte

	Version int
	Traffic chan *pb.UnixDogstatsdMsg
	Done    chan struct{}

	sync.Mutex
	// contains filtered or unexported fields
}

TrafficCaptureReader allows reading back a traffic capture and its contents

func NewTrafficCaptureReader

func NewTrafficCaptureReader(path string, depth int, mmap bool) (*TrafficCaptureReader, error)

NewTrafficCaptureReader creates a TrafficCaptureReader instance

func (*TrafficCaptureReader) Close

func (tc *TrafficCaptureReader) Close() error

Close cleans up any resources used by the TrafficCaptureReader, should not normally be called directly.

func (*TrafficCaptureReader) Read

func (tc *TrafficCaptureReader) Read(ready chan struct{})

Read reads the contents of the traffic capture and writes each packet to a channel

func (*TrafficCaptureReader) ReadNext

func (tc *TrafficCaptureReader) ReadNext() (*pb.UnixDogstatsdMsg, error)

ReadNext reads the next packet found in the file and returns the protobuf representation and an error if any.

func (*TrafficCaptureReader) ReadState

func (tc *TrafficCaptureReader) ReadState() (map[int32]string, map[string]*pb.Entity, error)

ReadState reads the tagger state from the end of the capture file. The internal offset of the reader is not modified by this operation.

func (*TrafficCaptureReader) Seek

func (tc *TrafficCaptureReader) Seek(offset uint32)

Seek sets the reader to the specified offset. Please note, the specified offset is relative to the first datagram, not the absolute position in the file, that would include the header. Thus, an offset of 0 would be the first datagram. Use with caution, a bad offset will completely mess up a replay.

func (*TrafficCaptureReader) Shutdown

func (tc *TrafficCaptureReader) Shutdown() error

Shutdown triggers the fuse if there's an ongoing read routine, and closes the reader.

type TrafficCaptureWriter

type TrafficCaptureWriter struct {
	Traffic chan *CaptureBuffer

	// Synchronizes access to ongoing, accepting and closing of Traffic
	sync.RWMutex
	// contains filtered or unexported fields
}

TrafficCaptureWriter allows writing dogstatsd traffic to a file.

func NewTrafficCaptureWriter

func NewTrafficCaptureWriter(depth int) *TrafficCaptureWriter

NewTrafficCaptureWriter creates a TrafficCaptureWriter instance.

func (*TrafficCaptureWriter) Capture

func (tc *TrafficCaptureWriter) Capture(target io.WriteCloser, d time.Duration, compressed bool)

Capture start the traffic capture and writes the packets to file at the specified location and for the specified duration.

func (*TrafficCaptureWriter) Enqueue

func (tc *TrafficCaptureWriter) Enqueue(msg *CaptureBuffer) bool

Enqueue enqueues a capture buffer so it's written to file.

func (*TrafficCaptureWriter) IsOngoing

func (tc *TrafficCaptureWriter) IsOngoing() bool

IsOngoing returns whether a capture is ongoing for this TrafficCaptureWriter instance.

func (*TrafficCaptureWriter) RegisterOOBPoolManager

func (tc *TrafficCaptureWriter) RegisterOOBPoolManager(p *packets.PoolManager) error

RegisterOOBPoolManager registers the OOB shared pool manager with the TrafficCaptureWriter.

func (*TrafficCaptureWriter) RegisterSharedPoolManager

func (tc *TrafficCaptureWriter) RegisterSharedPoolManager(p *packets.PoolManager) error

RegisterSharedPoolManager registers the shared pool manager with the TrafficCaptureWriter.

func (*TrafficCaptureWriter) StopCapture

func (tc *TrafficCaptureWriter) StopCapture()

StopCapture stops the ongoing capture if in process.

func (*TrafficCaptureWriter) Write

func (tc *TrafficCaptureWriter) Write(p []byte) (int, error)

Write writes the byte slice argument to file.

Jump to

Keyboard shortcuts

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