...

Package bpm

import "github.com/chaos-mesh/chaos-mesh/pkg/bpm"
Overview
Index

Overview ▾

Index ▾

Constants
func GetNsPath(pid uint32, typ NsType) string
type BackgroundProcessManager
    func StartBackgroundProcessManager(registry prometheus.Registerer, rootLogger logr.Logger) *BackgroundProcessManager
    func (m *BackgroundProcessManager) GetIdentifiers() []string
    func (m *BackgroundProcessManager) GetPipes(uid string) (Pipes, bool)
    func (m *BackgroundProcessManager) GetUID(pair ProcessPair) (string, bool)
    func (m *BackgroundProcessManager) KillBackgroundProcess(ctx context.Context, uid string) error
    func (m *BackgroundProcessManager) Shutdown(ctx context.Context)
    func (m *BackgroundProcessManager) StartProcess(ctx context.Context, cmd *ManagedCommand) (*Process, error)
type CommandBuilder
    func DefaultProcessBuilder(cmd string, args ...string) *CommandBuilder
    func (b *CommandBuilder) Build(ctx context.Context) *ManagedCommand
    func (b *CommandBuilder) EnableLocalMnt() *CommandBuilder
    func (b *CommandBuilder) EnablePause() *CommandBuilder
    func (b *CommandBuilder) SetContext(ctx context.Context) *CommandBuilder
    func (b *CommandBuilder) SetEnv(key, value string) *CommandBuilder
    func (b *CommandBuilder) SetIdentifier(id string) *CommandBuilder
    func (b *CommandBuilder) SetNS(pid uint32, typ NsType) *CommandBuilder
    func (b *CommandBuilder) SetNSOpt(options []nsOption) *CommandBuilder
    func (b *CommandBuilder) SetOOMScoreAdj(scoreAdj int) *CommandBuilder
    func (b *CommandBuilder) SetStderr(stderr io.ReadWriteCloser) *CommandBuilder
    func (b *CommandBuilder) SetStdin(stdin io.ReadWriteCloser) *CommandBuilder
    func (b *CommandBuilder) SetStdout(stdout io.ReadWriteCloser) *CommandBuilder
type ManagedCommand
type NsType
type Pipes
type Process
    func (p *Process) Stopped() <-chan struct{}
type ProcessPair

Package files

bpm.go build_linux.go metrics.go

Constants

const (
    DefaultProcPrefix = "/proc"
)

func GetNsPath

func GetNsPath(pid uint32, typ NsType) string

GetNsPath returns corresponding namespace path

type BackgroundProcessManager

BackgroundProcessManager manages all background processes

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

func StartBackgroundProcessManager

func StartBackgroundProcessManager(registry prometheus.Registerer, rootLogger logr.Logger) *BackgroundProcessManager

StartBackgroundProcessManager creates a background process manager

func (*BackgroundProcessManager) GetIdentifiers

func (m *BackgroundProcessManager) GetIdentifiers() []string

GetIdentifiers finds all identifiers in BPM

func (*BackgroundProcessManager) GetPipes

func (m *BackgroundProcessManager) GetPipes(uid string) (Pipes, bool)

func (*BackgroundProcessManager) GetUID

func (m *BackgroundProcessManager) GetUID(pair ProcessPair) (string, bool)

func (*BackgroundProcessManager) KillBackgroundProcess

func (m *BackgroundProcessManager) KillBackgroundProcess(ctx context.Context, uid string) error

KillBackgroundProcess sends SIGTERM to process

func (*BackgroundProcessManager) Shutdown

func (m *BackgroundProcessManager) Shutdown(ctx context.Context)

func (*BackgroundProcessManager) StartProcess

func (m *BackgroundProcessManager) StartProcess(ctx context.Context, cmd *ManagedCommand) (*Process, error)

StartProcess manages a process in manager

type CommandBuilder

CommandBuilder builds a exec.Cmd for daemon

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

func DefaultProcessBuilder

func DefaultProcessBuilder(cmd string, args ...string) *CommandBuilder

DefaultProcessBuilder returns the default process builder

func (*CommandBuilder) Build

func (b *CommandBuilder) Build(ctx context.Context) *ManagedCommand

Build builds the command the ctx argument passes the context information to this function e.g. the corresponding resource name.

func (*CommandBuilder) EnableLocalMnt

func (b *CommandBuilder) EnableLocalMnt() *CommandBuilder

func (*CommandBuilder) EnablePause

func (b *CommandBuilder) EnablePause() *CommandBuilder

EnablePause enables pause for process

func (*CommandBuilder) SetContext

func (b *CommandBuilder) SetContext(ctx context.Context) *CommandBuilder

SetContext sets context for process

func (*CommandBuilder) SetEnv

func (b *CommandBuilder) SetEnv(key, value string) *CommandBuilder

SetEnv sets the environment variables of the process

func (*CommandBuilder) SetIdentifier

func (b *CommandBuilder) SetIdentifier(id string) *CommandBuilder

SetIdentifier sets the identifier of the process

The identifier is used to identify the process in BPM, to confirm only one identified process is running. If one identified process is already running, new processes with the same identifier will be blocked by lock.

func (*CommandBuilder) SetNS

func (b *CommandBuilder) SetNS(pid uint32, typ NsType) *CommandBuilder

SetNS sets the namespace of the process

func (*CommandBuilder) SetNSOpt

func (b *CommandBuilder) SetNSOpt(options []nsOption) *CommandBuilder

SetNSOpt sets the namespace of the process

func (*CommandBuilder) SetOOMScoreAdj

func (b *CommandBuilder) SetOOMScoreAdj(scoreAdj int) *CommandBuilder

SetOOMScoreAdj sets the oom_score_adj for a process oom_score_adj ranges from -1000 to 1000

func (*CommandBuilder) SetStderr

func (b *CommandBuilder) SetStderr(stderr io.ReadWriteCloser) *CommandBuilder

SetStderr sets stderr for process

func (*CommandBuilder) SetStdin

func (b *CommandBuilder) SetStdin(stdin io.ReadWriteCloser) *CommandBuilder

SetStdin sets stdin for process

func (*CommandBuilder) SetStdout

func (b *CommandBuilder) SetStdout(stdout io.ReadWriteCloser) *CommandBuilder

SetStdout sets stdout for process

type ManagedCommand

ManagedCommand is a process which can be managed by backgroundProcessManager

type ManagedCommand struct {
    *exec.Cmd

    // If the identifier is not nil, process manager should make sure no other
    // process with this identifier is running when executing this command
    Identifier *string
}

type NsType

type NsType string
const (
    MountNS NsType = "mnt"
    // uts namespace is not supported yet
    // UtsNS   NsType = "uts"
    IpcNS NsType = "ipc"
    NetNS NsType = "net"
    PidNS NsType = "pid"
)

type Pipes

pipes that will be connected to the command's stdin/stdout

type Pipes struct {
    Stdin  io.WriteCloser
    Stdout io.ReadCloser
}

type Process

type Process struct {
    Uid string

    // TODO: remove in v3.x
    // store create time, to keep compatible with v2.x
    Pair ProcessPair

    Cmd   *ManagedCommand
    Pipes Pipes
    // contains filtered or unexported fields
}

func (*Process) Stopped

func (p *Process) Stopped() <-chan struct{}

type ProcessPair

ProcessPair is an identifier for process Keep compatible with v2.x TODO: remove in v3.x

Currently, the bpm locate managed processes by both PID and create time, because the OS may reuse PID, we must check the create time to avoid locating the wrong process.

However, the two-step locating is messy and the create time may be imprecise (we have fixed a [relevant bug](https://github.com/shirou/gopsutil/pull/1204)). In future version, we should completely remove the two-step locating and identify managed processes by UID only.

type ProcessPair struct {
    Pid        int
    CreateTime int64
}