replay

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: 23 Imported by: 0

Documentation

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

Functions

func ContainerIDForPID

func ContainerIDForPID(pid int32) (string, error)

ContainerIDForPID returns the matching container id for a pid, or an error if not found.

func GetUcredsForPid

func GetUcredsForPid(pid int32) []byte

GetUcredsForPid returns the replay ucreds for the specified pid

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 SetPidMap

func SetPidMap(m map[int32]string)

SetPidMap sets the map with the pid - containerID relations

func WriteHeader

func WriteHeader(w *bufio.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 TrafficCapture

type TrafficCapture struct {
	Writer *TrafficCaptureWriter

	sync.RWMutex
}

TrafficCapture allows capturing traffic from our listeners and writing it to file

func NewTrafficCapture

func NewTrafficCapture() (*TrafficCapture, error)

NewTrafficCapture creates a TrafficCapture instance.

func (*TrafficCapture) IsOngoing

func (tc *TrafficCapture) IsOngoing() bool

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

func (*TrafficCapture) Path

func (tc *TrafficCapture) Path() (string, error)

Path returns the path to the underlying TrafficCapture file, and an error if any.

func (*TrafficCapture) Start

func (tc *TrafficCapture) Start(d time.Duration) error

Start starts a TrafficCapture and returns an error in the event of an issue.

func (*TrafficCapture) Stop

func (tc *TrafficCapture) Stop()

Stop stops an ongoing TrafficCapture.

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) (*TrafficCaptureReader, error)

NewTrafficCaptureReader creates a TrafficCaptureReader instance

func (*TrafficCaptureReader) Close

func (tc *TrafficCaptureReader) Close() error

Close cleans up any resources used by the TrafficCaptureReader

func (*TrafficCaptureReader) Read

func (tc *TrafficCaptureReader) Read()

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) 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 {
	File *os.File

	Traffic  chan *CaptureBuffer
	Location string

	sync.RWMutex
	// contains filtered or unexported fields
}

TrafficCaptureWriter allows writing dogstatsd traffic to a file.

func NewTrafficCaptureWriter

func NewTrafficCaptureWriter(l string, depth int) *TrafficCaptureWriter

NewTrafficCaptureWriter creates a TrafficCaptureWriter instance.

func (*TrafficCaptureWriter) Capture

func (tc *TrafficCaptureWriter) Capture(d time.Duration)

Capture start the traffic capture and writes the packets to file 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) Path

func (tc *TrafficCaptureWriter) Path() (string, error)

Path returns the path to file where the traffic capture will be written.

func (*TrafficCaptureWriter) ProcessMessage

func (tc *TrafficCaptureWriter) ProcessMessage(msg *CaptureBuffer) error

ProcessMessage receives a capture buffer and writes it to disk while also tracking the PID map to be persisted to the taggerState. Should not normally be called directly.

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.

func (*TrafficCaptureWriter) WriteHeader

func (tc *TrafficCaptureWriter) WriteHeader() error

WriteHeader writes the .dog file format header to the capture file.

func (*TrafficCaptureWriter) WriteNext

func (tc *TrafficCaptureWriter) WriteNext(msg *CaptureBuffer) error

WriteNext writes the next CaptureBuffer after serializing it to a protobuf format. Continuing writes after an error calling this function would result in a corrupted file

func (*TrafficCaptureWriter) WriteState

func (tc *TrafficCaptureWriter) WriteState() (int, error)

WriteState writes the tagger state to the capture file.

Jump to

Keyboard shortcuts

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