observer

package
v1.3.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Define a counter metric for data event statistics
	DataEventStats = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace:   consts.MetricsNamespace,
		Name:        "data_events_total",
		Help:        "The number of data events by type. For internal use only.",
		ConstLabels: nil,
	}, []string{"event"})

	DataEventSizeHist = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Namespace:   consts.MetricsNamespace,
		Name:        "data_event_size",
		Help:        "The size of received data events.",
		Buckets:     prometheus.LinearBuckets(1000, 2000, 20),
		ConstLabels: nil,
	}, []string{"op"})
)
View Source
var (
	RingbufReceived = prometheus.NewCounter(prometheus.CounterOpts{
		Namespace:   consts.MetricsNamespace,
		Subsystem:   subsystem,
		Name:        "ringbuf_events_received_total",
		Help:        "Number of perf events Tetragon ring buffer received.",
		ConstLabels: nil,
	})
	RingbufLost = prometheus.NewCounter(prometheus.CounterOpts{
		Namespace:   consts.MetricsNamespace,
		Subsystem:   subsystem,
		Name:        "ringbuf_events_lost_total",
		Help:        "Number of perf events Tetragon ring buffer lost.",
		ConstLabels: nil,
	})
	RingbufErrors = prometheus.NewCounter(prometheus.CounterOpts{
		Namespace:   consts.MetricsNamespace,
		Subsystem:   subsystem,
		Name:        "ringbuf_errors_total",
		Help:        "Number of errors when reading Tetragon ring buffer.",
		ConstLabels: nil,
	})
)
View Source
var DataEventTypeStrings = map[DataEventType]string{
	DataEventReceived:   "Received",
	DataEventAdded:      "Added",
	DataEventAppended:   "Appended",
	DataEventMatched:    "Matched",
	DataEventNotMatched: "NotMatched",
	DataEventBad:        "Bad",
}

Functions

func AllListeners

func AllListeners(msg notify.Message)

func DataAdd

func DataAdd(id dataapi.DataEventId, msgData []byte) error

func DataEventMetricInc added in v1.3.2

func DataEventMetricInc(event DataEventType)

Increment a data event metric for an event type and location

func DataEventMetricSizeBad added in v1.3.2

func DataEventMetricSizeBad(size uint32)

func DataEventMetricSizeOk added in v1.3.2

func DataEventMetricSizeOk(size uint32)

func DataGet

func DataGet(desc dataapi.DataEventDesc) ([]byte, error)

func DataPurge

func DataPurge()

func GetSensorManager added in v1.3.2

func GetSensorManager() *sensors.Manager

func HandlePerfData

func HandlePerfData(data []byte) (byte, []Event, *HandlePerfError)

HandlePerfData returns the events from raw bytes NB: It is made public so that it can be used in testing.

func InitDataCache

func InitDataCache(size int) error

func InitMetrics added in v1.3.2

func InitMetrics()

func NewBPFCollector added in v1.3.2

func NewBPFCollector() metrics.CollectorWithInit

func RegisterEventHandlerAtInit

func RegisterEventHandlerAtInit(ev uint8, handler func(r *bytes.Reader) ([]Event, error))

func RegisterHealthMetrics added in v1.3.2

func RegisterHealthMetrics(group metrics.Group)

func RegisterMetrics added in v1.3.2

func RegisterMetrics(group metrics.Group)

func RemoveSensors added in v1.3.2

func RemoveSensors(ctx context.Context)

func ResetSensorManager added in v1.3.2

func ResetSensorManager()

ResetSensorManager resets the global sensorManager variable to nil. Intended only for testing.

func SetSensorManager added in v1.3.2

func SetSensorManager(sm *sensors.Manager) error

Types

type Channel

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

Channel is a Listener that gob encodes events and sends them to a network connection.

func NewChannel

func NewChannel(conn net.Conn) *Channel

NewChannel initializes Channel.

func (Channel) Close

func (o Channel) Close() error

Close implements Listener.Notify.

func (Channel) Notify

func (o Channel) Notify(msg interface{}) error

Notify implements Listener.Notify.

type DataEventOp added in v1.3.2

type DataEventOp int
const (
	DataEventOpOk DataEventOp = iota
	DataEventOpBad
)

func (DataEventOp) String added in v1.3.2

func (e DataEventOp) String() string

type DataEventType added in v1.3.2

type DataEventType int
const (
	DataEventReceived DataEventType = iota
	DataEventAdded
	DataEventAppended
	DataEventMatched
	DataEventNotMatched
	DataEventBad
)

type Event

type Event notify.Message

func HandleData

func HandleData(r *bytes.Reader) ([]Event, error)

type HandlePerfError added in v1.3.2

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

func (*HandlePerfError) Error added in v1.3.2

func (e *HandlePerfError) Error() string

func (*HandlePerfError) Unwrap added in v1.3.2

func (e *HandlePerfError) Unwrap() error

type Listener

type Listener interface {
	// Notify gets called for each events from ObserverKprobe.
	Notify(msg notify.Message) error

	// Close the listener.
	io.Closer
}

Listener defines the interface to receive events from Observer. Listeners will merge and complete out-of-order events before they're passed to human-readable sinks such as the printer or GRPC encoder.

type Observer

type Observer struct {
	PerfConfig *bpf.PerfEventConfig
	// contains filtered or unexported fields
}

Observer represents the link between the BPF perf ring and the listeners. It manages the perf ring and receive events from it. It ensures that the BPF event we are receiving from the kernel is complete. The listeners are notified of their corresponding events.

func NewObserver

func NewObserver() *Observer

func (*Observer) AddListener

func (k *Observer) AddListener(listener Listener)

func (*Observer) InitSensorManager

func (k *Observer) InitSensorManager() error

InitSensorManager starts the sensor controller

func (*Observer) LogPinnedBpf

func (k *Observer) LogPinnedBpf(observerDir string)

Log Active pinned BPF resources

func (*Observer) PrintStats

func (k *Observer) PrintStats()

func (*Observer) ReadErrorEvents

func (k *Observer) ReadErrorEvents() uint64

func (*Observer) ReadLostEvents

func (k *Observer) ReadLostEvents() uint64

func (*Observer) ReadReceivedEvents

func (k *Observer) ReadReceivedEvents() uint64

func (*Observer) Remove

func (k *Observer) Remove()

func (*Observer) RemoveListener

func (k *Observer) RemoveListener(listener Listener)

func (*Observer) RunEvents added in v1.3.2

func (k *Observer) RunEvents(stopCtx context.Context, ready func()) error

func (*Observer) Start

func (k *Observer) Start(ctx context.Context) error

Start starts the observer

func (*Observer) StartReady added in v1.3.2

func (k *Observer) StartReady(ctx context.Context, ready func()) error

func (*Observer) UpdateRuntimeConf

func (k *Observer) UpdateRuntimeConf(bpfDir string) error

UpdateRuntimeConf() Gathers information about Tetragon runtime environment and updates BPF map TetragonConfMap

The observer needs to do this to discover and properly operate on the right cgroup context. Use this function in your tests to allow Pod and Containers association to work.

The environment and cgroup configuration discovery may fail for several reasons, in such cases errors will be logged. On errors we also print a warning that advanced Cgroups tracking will be disabled which might affect process association with kubernetes pods and containers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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