hub

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// if we have an alternate root setting, and the endpoints start with
	// "$root", use the AltRoot as the CWD for any further lookups, whether
	// that be for /proc, or for configurations.
	//
	// mainly here for development reasons, if you're able to see your k8s
	// node via /proc/<pid>/root, you can set the AltRoot to this, and
	// namespace lookups will look at /proc/<pid>/root/proc/...
	// cri socket will look at /proc/<pid>/root/path/to/cri.sock
	// etc...
	AltRoot string
	// The kube CRI socket needed for resolving kernel namespaces to containers
	CRIEndpoint string
	// If running out-of-cluster, this is the local k8s configuration
	K8SEndpoint string
	// The namespace in which to monitor for pods, if empty we watch all
	// namespaces.
	K8SNamespace string
	// The raw BPF probe object loaded via assets (go-bindata) or via file
	BPFObject []byte
}

type Hub

type Hub struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Hub maintains the global kernel probe and all the underlying filters and event message routing.

func NewHub

func NewHub(config *Config, observer topology.Observer) (*Hub, error)

NewHub creates and initializes a Hub context for reading and writing data to the kernel probe and routing them to the clients that care.

func (*Hub) AttachPath

func (h *Hub) AttachPath(name string, paths []string, cb func(string, *event.TraceEvent)) pubsub.Unsubscriber

AttachPath will subscribe the caller to a stream which is a subset of data sent to a specific job.

func (*Hub) AttachTrace

func (h *Hub) AttachTrace(t *v1alpha1.Trace, cb func(n string, ev *event.TraceEvent)) pubsub.Unsubscriber

AttachTrace will subscribe the caller to a stream which has the output of a specific job.

func (*Hub) DeleteTrace

func (h *Hub) DeleteTrace(t *v1alpha1.Trace) error

DeleteTrace will stop all the runninb jobs that are associated with this Trace specification. using the job-id, we iterate over each context and if there are no other jobs trying to use the syscall and pod associated with this, the kernel filters are removed.

func (*Hub) MustRun

func (h *Hub) MustRun(ctx context.Context)

func (*Hub) MustRunJob

func (h *Hub) MustRunJob(job *Job)

MustRunJob calls hub.RunJob but exits on any errors

func (*Hub) Probe

func (h *Hub) Probe() *kernel.Probe

Probe returns the Hub's current kernel.Probe context

func (*Hub) PushJob

func (h *Hub) PushJob(job *Job, ns, nr int)

PushJob insert a namespace+nr specific job as a value of a list in two buckets; the first being the `nsmap`, a mapping of pidNamespace + syscall_NR to lists of jobs, and an `idmap`, a mapping of jobID's to jobs.

We keep these lists like this so that if two jobs that have overlapping rules (e.g., rule-A=syscall_A,syscall_B, rule-B=syscall_A,syscall_C) we don't accidentally delete a running check for `syscall_A` if `rule-B` is removed.

func (*Hub) Run

func (h *Hub) Run(ctx context.Context) error

Run starts up and runs the global kernel probe and maintains various state. For each event that is recv'd via the bpf, we decode it (`Ingest`), find all jobs associated with this message, and publish the event to the streams tied to the jobs.

func (*Hub) RunJob

func (h *Hub) RunJob(job *Job) error

RunJob runs a job on the Hub

func (*Hub) RunTrace

func (h *Hub) RunTrace(t *v1alpha1.Trace) error

RunTrace runs a TraceJob on the hub

func (*Hub) Topology

func (h *Hub) Topology() *topology.Topology

Topology returns this Hub's current underlying topology context

func (*Hub) WriteEvent

func (h *Hub) WriteEvent(ev *event.TraceEvent)

WriteEvent writes a single TraceEvent to all subscribers

type Job

type Job struct {
	*v1alpha1.Trace
	// contains filtered or unexported fields
}

Job maintains the general rules for which a trace runs under.

func NewJob

func NewJob(t *v1alpha1.Trace) *Job

NewJob returns a Job for the trace

func (*Job) AddContainer

func (j *Job) AddContainer(pod, name string)

AddContainer tells the job to monitor a very specific container in a specific pod.

func (*Job) Duration

func (j *Job) Duration() time.Duration

Duration returns how long this job has been running as seen by kube.

func (*Job) JobID

func (j *Job) JobID() string

JobID returns the raw job-id associated with this job

func (*Job) MonitoredHosts

func (j *Job) MonitoredHosts(all bool) []string

MonitoredHosts returns a list of hosts that have been monitored by this job. If `all` is `false`, then ony containers that are currently being monitored will return, otherwise it will return every host that has ever matched this job.

func (*Job) RemoveContainer

func (j *Job) RemoveContainer(pod, name string)

RemoveContainer removes the watch for a specific container in a specific pod

func (*Job) Run

func (j *Job) Run(h *Hub, done chan bool) error

Run will run a job inside the Hub. The primary goal of this function is to read topology events using the LabelMatch, and for each pod that matches, create the kernel filter if needed, and append the JobContext to the list of running jobs in the Hub.

func (*Job) TraceSpec

func (j *Job) TraceSpec() *v1alpha1.TraceSpec

TraceSpec returns the `TraceSpec` defined for this `Job`

func (*Job) TraceStatus

func (j *Job) TraceStatus() *v1alpha1.TraceStatus

TraceStatus returns the status of this Job

func (*Job) WriteEvent

func (j *Job) WriteEvent(h *Hub, ev *event.TraceEvent)

WriteEvent writes event `ev` to all listeners of this `Job`

type JobContext

type JobContext struct {
	*Job
	// contains filtered or unexported fields
}

JobContext is a structure that is used to store all the kernel filtering information per pid-namespace.

When we reference a "POD" in this code, we use the PID namespace of the underlying container to key off of. Since multiple jobs can have some of the same syscalls and hosts being monitored, we create a list of all possible rules, but only filter in the kernel what is needed.

For example: say we have two "jobs". "Job-A", and "Job-B". Job-A monitors "app=nginx" with the syscalls "open"/"close" Job-B monitors "type=webserver" with the syscalls "open"

app=nginx matches 'host-A' and 'host-B'
type=webserver matches 'host-A' and 'host-Z'

If we were to blindly delete Job-B, (meaning removing the filters for 'Host-A' and syscall "open"), we would also delete the filter that is being used for 'Job-A'. So we just make sure we don't delete from the actual kernel filter until our lists are empty.

type JobList

type JobList struct {
	*list.List
}

JobList is a wrapper around a simple linked-list for groups of JobContexts

Jump to

Keyboard shortcuts

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