core

package
v2.33.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CTLKern           = 1  // "high kernel": proc, limits
	KernProc          = 14 // struct: process entries
	KernProcPathname  = 12 // path to executable
	SYS_SYSCTL        = 202
	IsContainerKey    = "isContainer"
	GetContainerIDKey = "GetContainerID"
	GetSystemUUIDKey  = "GetSystemUUIDKey"
)
View Source
const (
	MaxPlugins          = 50
	MaxExtensionPlugins = 50
)
View Source
const (
	UNKNOWN                         = "unknown"
	RegistrationPrefix              = "registration."
	RegistrationCompletedTopic      = RegistrationPrefix + "completed"
	CommNginxConfig                 = "nginx.config"
	NginxConfigUpload               = "nginx.config.upload"
	NginxReload                     = "nginx.reload"
	NginxReloadComplete             = "nginx.reload.complete"
	NginxStart                      = "nginx.start"
	NginxStop                       = "nginx.stop"
	NginxPluginConfigured           = "nginx.plugin.config"
	NginxInstancesFound             = "nginx.instances.found"
	NginxMasterProcCreated          = "nginx.master.created"
	NginxMasterProcKilled           = "nginx.master.killed"
	NginxWorkerProcCreated          = "nginx.worker.created"
	NginxWorkerProcKilled           = "nginx.worker.killed"
	NginxDetailProcUpdate           = "nginx.proc.update"
	NginxConfigValidationPending    = "nginx.config.validation.pending"
	NginxConfigValidationFailed     = "nginx.config.validation.failed"
	NginxConfigValidationSucceeded  = "nginx.config.validation.succeeded"
	NginxConfigApplyFailed          = "nginx.config.apply.failed"
	NginxConfigApplySucceeded       = "nginx.config.apply.succeeded"
	CommPrefix                      = "comms."
	CommStatus                      = CommPrefix + "status"
	CommMetrics                     = CommPrefix + "metrics"
	CommRegister                    = CommPrefix + "register"
	CommResponse                    = CommPrefix + "response"
	AgentStarted                    = "agent.started"
	AgentConnected                  = "agent.connected"
	AgentConfig                     = "agent.config"
	AgentConfigChanged              = "agent.config.changed"
	AgentCollectorsUpdate           = "agent.collectors.update"
	MetricReport                    = "metrics.report"
	DataplaneChanged                = "dataplane.changed"
	DataplaneFilesChanged           = "dataplane.fileschanged"
	Events                          = "events"
	FileWatcherEnabled              = "file.watcher.enabled"
	ConfigRollbackResponse          = "config.rollback.response"
	DataplaneSoftwareDetailsUpdated = "dataplane.software.details.updated"
	EnableExtension                 = "enable.extension"
	EnableFeature                   = "enable.feature"
	AgentAPIConfigApplyResponse     = "agent.api.config.apply.response"
)

Variables

This section is empty.

Functions

func AccessLogs

func AccessLogs(p *proto.NginxConfig) map[string]string

AccessLogs returns a list of access logs in the config

func CheckForProcesses

func CheckForProcesses(processesToCheck []string) ([]string, error)

CheckForProcesses takes in a slice of strings that represents the process names to check for then returns a slice of strings of the processes that were checked for and NOT found.

func CreateGrpcClients added in v2.29.0

func CreateGrpcClients(ctx context.Context, loadedConfig *config.Config) (client.Controller, client.Commander, client.MetricReporter)

func EnableWritePermissionForSocket added in v2.24.0

func EnableWritePermissionForSocket(path string) error

func ErrorLogs

func ErrorLogs(p *proto.NginxConfig) map[string]string

ErrorLogs returns a list of error logs in the config

func FileExists

func FileExists(filePath string) (bool, error)

FileExists determines if the specified file given by the file path exists on the system. If the file does NOT exist on the system the bool will be false and the error will be nil, if the error is not nil then it's possible the file might exist but an error verifying it's existence has occurred.

func FilesExists

func FilesExists(filePaths []string) (bool, error)

FilesExists determines if the specified set of files exists on the system. If any of the files do NOT exist on the system the bool will be false and the error will be nil, if the error is not nil then it's possible the files might exist but an error verifying their existence has occurred.

func GenerateNginxID

func GenerateNginxID(format string, a ...interface{}) string

GenerateNginxID used to get the NGINX ID

func HandleSignals added in v2.29.0

func HandleSignals(
	ctx context.Context,
	cmder client.Commander,
	loadedConfig *config.Config,
	env Environment,
	pipe MessagePipeInterface,
	cancel context.CancelFunc,
	controller client.Controller,
)

handleSignals handles signals to attempt graceful shutdown for now it also handles sending the agent stopped event because as of today we don't have a mechanism for synchronizing tasks between multiple plugins from outside a plugin

func SliceContainsString

func SliceContainsString(slice []string, toFind string) (bool, int)

SliceContainsString takes in a slice of strings and a string to check for within the supplied slice of strings, then returns a bool indicating if the the specified string was found and the index where it was found. If the specified string was not found then the index returned is -1.

func ValidateMessages

func ValidateMessages(t *testing.T, messagePipe *MockMessagePipe, msgTopics []string)

Types

type ConfigApplyMarker

type ConfigApplyMarker interface {
	MarkAndSave(string) error
	RemoveFromNotExists(string)
}

type DiskUsage added in v2.30.0

type DiskUsage struct {
	Total          float64
	Used           float64
	Free           float64
	UsedPercentage float64
}

type Environment

type Environment interface {
	NewHostInfo(agentVersion string, tags *[]string, configDirs string, clearCache bool) *proto.HostInfo
	// NewHostInfoWithContext(agentVersion string, tags *[]string, configDirs string, clearCache bool) *proto.HostInfo
	GetHostname() (hostname string)
	GetSystemUUID() (hostId string)
	ReadDirectory(dir string, ext string) ([]string, error)
	WriteFiles(backup ConfigApplyMarker, files []*proto.File, prefix string, allowedDirs map[string]struct{}) error
	WriteFile(backup ConfigApplyMarker, file *proto.File, confPath string) error
	DeleteFile(backup ConfigApplyMarker, fileName string) error
	Processes() (result []*Process)
	FileStat(path string) (os.FileInfo, error)
	Disks() ([]*proto.DiskPartition, error)
	DiskDevices() ([]string, error)
	DiskUsage(mountPoint string) (*DiskUsage, error)
	GetContainerID() (string, error)
	GetNetOverflow() (float64, error)
	IsContainer() bool
	Virtualization() (string, string)
}

type EnvironmentType

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

func (*EnvironmentType) DeleteFile added in v2.29.0

func (env *EnvironmentType) DeleteFile(backup ConfigApplyMarker, fileName string) error

func (*EnvironmentType) DiskDevices

func (env *EnvironmentType) DiskDevices() ([]string, error)

DiskDevices returns a list of Disk Devices known by the system. Loop and other virtual devices are filtered out

func (*EnvironmentType) DiskUsage added in v2.30.0

func (env *EnvironmentType) DiskUsage(mountPoint string) (*DiskUsage, error)

func (*EnvironmentType) Disks added in v2.30.0

func (env *EnvironmentType) Disks() (partitions []*proto.DiskPartition, err error)

func (*EnvironmentType) FileStat

func (env *EnvironmentType) FileStat(path string) (os.FileInfo, error)

func (*EnvironmentType) GetContainerID

func (env *EnvironmentType) GetContainerID() (string, error)

GetContainerID returns the ID of the current environment if running in a container

func (*EnvironmentType) GetHostname

func (env *EnvironmentType) GetHostname() string

func (*EnvironmentType) GetNetOverflow

func (env *EnvironmentType) GetNetOverflow() (float64, error)

func (*EnvironmentType) GetSystemUUID

func (env *EnvironmentType) GetSystemUUID() string

func (*EnvironmentType) IsContainer

func (env *EnvironmentType) IsContainer() bool

func (*EnvironmentType) NewHostInfo

func (env *EnvironmentType) NewHostInfo(agentVersion string, tags *[]string, configDirs string, clearCache bool) *proto.HostInfo

func (*EnvironmentType) NewHostInfoWithContext added in v2.28.0

func (env *EnvironmentType) NewHostInfoWithContext(ctx context.Context, agentVersion string, tags *[]string, configDirs string, clearCache bool) *proto.HostInfo

func (*EnvironmentType) Processes

func (env *EnvironmentType) Processes() (result []*Process)

Processes returns a slice of nginx master and nginx worker processes currently running

func (*EnvironmentType) ReadDirectory

func (env *EnvironmentType) ReadDirectory(dir string, ext string) ([]string, error)

func (*EnvironmentType) Virtualization added in v2.33.0

func (env *EnvironmentType) Virtualization() (string, string)

func (*EnvironmentType) WriteFile added in v2.29.0

func (env *EnvironmentType) WriteFile(backup ConfigApplyMarker, file *proto.File, confPath string) error

WriteFile writes the provided file content to disk. If the file.GetName() returns an absolute path, it'll be written to the path. Otherwise, it'll be written to the path relative to the provided confPath.

func (*EnvironmentType) WriteFiles

func (env *EnvironmentType) WriteFiles(backup ConfigApplyMarker, files []*proto.File, confPath string, allowedDirs map[string]struct{}) error

type ExtensionPlugin added in v2.24.0

type ExtensionPlugin = Plugin

type Info

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

func NewInfo

func NewInfo(name string, version string) *Info

func (*Info) Name

func (info *Info) Name() string

func (*Info) Version

func (info *Info) Version() string

type Message

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

func NewMessage

func NewMessage(topic string, data Payload) *Message

func (*Message) Data

func (m *Message) Data() Payload

func (*Message) Exact

func (m *Message) Exact(topic string) bool

func (*Message) Match

func (m *Message) Match(topic string) bool

func (*Message) Topic

func (m *Message) Topic() string

type MessagePipe

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

func NewMessagePipe

func NewMessagePipe(ctx context.Context, size int) *MessagePipe

func (*MessagePipe) Cancel

func (p *MessagePipe) Cancel() context.CancelFunc

func (*MessagePipe) Context

func (p *MessagePipe) Context() context.Context

func (*MessagePipe) DeRegister added in v2.26.0

func (p *MessagePipe) DeRegister(pluginNames []string) error

func (*MessagePipe) GetExtensionPlugins added in v2.24.0

func (p *MessagePipe) GetExtensionPlugins() []ExtensionPlugin

func (*MessagePipe) GetPlugins

func (p *MessagePipe) GetPlugins() []Plugin

func (*MessagePipe) IsPluginAlreadyRegistered added in v2.26.0

func (p *MessagePipe) IsPluginAlreadyRegistered(pluginName string) bool

func (*MessagePipe) Process

func (p *MessagePipe) Process(messages ...*Message)

func (*MessagePipe) Register

func (p *MessagePipe) Register(size int, plugins []Plugin, extensionPlugins []ExtensionPlugin) error

func (*MessagePipe) Run

func (p *MessagePipe) Run()

type MessagePipeInterface

type MessagePipeInterface interface {
	Register(int, []Plugin, []ExtensionPlugin) error
	DeRegister(plugins []string) error
	Process(...*Message)
	Run()
	Context() context.Context
	GetPlugins() []Plugin
	GetExtensionPlugins() []ExtensionPlugin
	IsPluginAlreadyRegistered(string) bool
}

func InitializePipe added in v2.29.0

func InitializePipe(ctx context.Context, corePlugins []Plugin, extensionPlugins []ExtensionPlugin, size int) MessagePipeInterface

type MockMessagePipe

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

MockMessagePipe is a mock message pipe

func NewMockMessagePipe

func NewMockMessagePipe(ctx context.Context) *MockMessagePipe

func SetupMockMessagePipe

func SetupMockMessagePipe(t *testing.T, ctx context.Context, plugins []Plugin, extensionPlugins []ExtensionPlugin) *MockMessagePipe

func (*MockMessagePipe) ClearMessages

func (p *MockMessagePipe) ClearMessages()

func (*MockMessagePipe) Context

func (p *MockMessagePipe) Context() context.Context

func (*MockMessagePipe) DeRegister added in v2.26.0

func (p *MockMessagePipe) DeRegister(pluginNames []string) error

func (*MockMessagePipe) GetExtensionPlugins added in v2.24.0

func (p *MockMessagePipe) GetExtensionPlugins() []ExtensionPlugin

func (*MockMessagePipe) GetMessages

func (p *MockMessagePipe) GetMessages() []*Message

func (*MockMessagePipe) GetPlugins

func (p *MockMessagePipe) GetPlugins() []Plugin

func (*MockMessagePipe) GetProcessedMessages

func (p *MockMessagePipe) GetProcessedMessages() []*Message

func (*MockMessagePipe) IsPluginAlreadyRegistered added in v2.26.0

func (p *MockMessagePipe) IsPluginAlreadyRegistered(pluginName string) bool

func (*MockMessagePipe) Process

func (p *MockMessagePipe) Process(msgs ...*Message)

func (*MockMessagePipe) Register

func (p *MockMessagePipe) Register(size int, plugins []Plugin, extensionPlugins []ExtensionPlugin) error

func (*MockMessagePipe) Run

func (p *MockMessagePipe) Run()

func (*MockMessagePipe) RunWithoutInit

func (p *MockMessagePipe) RunWithoutInit()

type NginxBinary

type NginxBinary interface {
	Start(nginxId, bin string) error
	Stop(processId, bin string) error
	Reload(processId, bin string) error
	ValidateConfig(processId, bin, configLocation string, config *proto.NginxConfig, configApply *sdk.ConfigApply) error
	GetNginxDetailsFromProcess(nginxProcess *Process) *proto.NginxDetails
	GetNginxDetailsByID(nginxID string) *proto.NginxDetails
	GetNginxIDForProcess(nginxProcess *Process) string
	GetNginxDetailsMapFromProcesses(nginxProcesses []*Process) map[string]*proto.NginxDetails
	UpdateNginxDetailsFromProcesses(nginxProcesses []*Process)
	WriteConfig(config *proto.NginxConfig) (*sdk.ConfigApply, error)
	ReadConfig(path, nginxId, systemId string) (*proto.NginxConfig, error)
	UpdateLogs(existingLogs map[string]string, newLogs map[string]string) bool
	GetAccessLogs() map[string]string
	GetErrorLogs() map[string]string
	GetChildProcesses() map[string][]*proto.NginxDetails
}

type NginxBinaryType

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

func NewNginxBinary

func NewNginxBinary(env Environment, config *config.Config) *NginxBinaryType

func (*NginxBinaryType) GetAccessLogs added in v2.20.0

func (n *NginxBinaryType) GetAccessLogs() map[string]string

func (*NginxBinaryType) GetChildProcesses

func (n *NginxBinaryType) GetChildProcesses() map[string][]*proto.NginxDetails

func (*NginxBinaryType) GetErrorLogs added in v2.20.0

func (n *NginxBinaryType) GetErrorLogs() map[string]string

func (*NginxBinaryType) GetNginxDetailsByID

func (n *NginxBinaryType) GetNginxDetailsByID(nginxID string) *proto.NginxDetails

func (*NginxBinaryType) GetNginxDetailsFromProcess

func (n *NginxBinaryType) GetNginxDetailsFromProcess(nginxProcess *Process) *proto.NginxDetails

func (*NginxBinaryType) GetNginxDetailsMapFromProcesses

func (n *NginxBinaryType) GetNginxDetailsMapFromProcesses(nginxProcesses []*Process) map[string]*proto.NginxDetails

func (*NginxBinaryType) GetNginxIDForProcess

func (n *NginxBinaryType) GetNginxIDForProcess(nginxProcess *Process) string

func (*NginxBinaryType) ReadConfig

func (n *NginxBinaryType) ReadConfig(confFile, nginxId, systemId string) (*proto.NginxConfig, error)

func (*NginxBinaryType) Reload

func (n *NginxBinaryType) Reload(processId, bin string) error

Reload NGINX.

func (*NginxBinaryType) SkipLog

func (n *NginxBinaryType) SkipLog(filename string) bool

SkipLog checks if a logfile should be omitted from analysis

func (*NginxBinaryType) Start

func (n *NginxBinaryType) Start(nginxId, bin string) error

Start starts NGINX.

func (*NginxBinaryType) Stop

func (n *NginxBinaryType) Stop(processId, bin string) error

Stop stops an instance of NGINX.

func (*NginxBinaryType) UpdateLogs

func (n *NginxBinaryType) UpdateLogs(existingLogs map[string]string, newLogs map[string]string) bool

func (*NginxBinaryType) UpdateNginxDetailsFromProcesses

func (n *NginxBinaryType) UpdateNginxDetailsFromProcesses(nginxProcesses []*Process)

func (*NginxBinaryType) ValidateConfig

func (n *NginxBinaryType) ValidateConfig(processId, bin, configLocation string, config *proto.NginxConfig, configApply *sdk.ConfigApply) error

ValidateConfig tests the config with nginx -t -c configLocation.

func (*NginxBinaryType) WriteConfig

func (n *NginxBinaryType) WriteConfig(config *proto.NginxConfig) (*sdk.ConfigApply, error)

type Payload

type Payload interface{}

type Plugin

type Plugin interface {
	Init(MessagePipeInterface)
	Close()
	Process(*Message)
	Info() *Info
	Subscriptions() []string
}

type Process

type Process struct {
	Pid        int32
	Name       string
	CreateTime int64
	Status     string
	IsRunning  bool
	IsMaster   bool
	Path       string
	User       string
	ParentPid  int32
	Command    string
}

type Shell added in v2.25.0

type Shell interface {
	Exec(cmd string, arg ...string) ([]byte, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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