runtime

package
v1.5.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// PidFile specifies the location of the PID file for the Nginx process.
	PidFile = "/var/run/nginx/nginx.pid"
	// PidFileTimeout defines the timeout duration for accessing the PID file.
	PidFileTimeout = 10000 * time.Millisecond
	// NginxReloadTimeout sets the timeout duration for reloading the Nginx configuration.
	NginxReloadTimeout = 60000 * time.Millisecond
)

Variables

This section is empty.

Functions

func CreatePlusClient added in v1.2.0

func CreatePlusClient() (*client.NginxClient, error)

CreatePlusClient returns a client for communicating with the NGINX Plus API.

func GetSocketClient added in v1.2.0

func GetSocketClient(sockPath string) http.Client

GetSocketClient gets an http.Client with a unix socket transport.

Types

type CheckFileFunc added in v1.5.0

type CheckFileFunc func(string) (fs.FileInfo, error)

type Manager

type Manager interface {
	// Reload reloads NGINX configuration. It is a blocking operation.
	Reload(ctx context.Context, configVersion int) error
	// IsPlus returns whether or not we are running NGINX plus.
	IsPlus() bool
	// UpdateHTTPServers uses the NGINX Plus API to update HTTP servers.
	// Only usable if running NGINX Plus.
	UpdateHTTPServers(string, []ngxclient.UpstreamServer) error
	// GetUpstreams uses the NGINX Plus API to get the upstreams.
	// Only usable if running NGINX Plus.
	GetUpstreams() (ngxclient.Upstreams, error)
}

Manager manages the runtime of NGINX.

type ManagerImpl

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

ManagerImpl implements Manager.

func NewManagerImpl

func NewManagerImpl(
	ngxPlusClient NginxPlusClient,
	collector MetricsCollector,
	logger logr.Logger,
	processHandler ProcessHandler,
	verifyClient nginxConfigVerifier,
) *ManagerImpl

NewManagerImpl creates a new ManagerImpl.

func (*ManagerImpl) GetUpstreams added in v1.2.0

func (m *ManagerImpl) GetUpstreams() (ngxclient.Upstreams, error)

GetUpstreams uses the NGINX Plus API to get the upstreams. Only usable if running NGINX Plus.

func (*ManagerImpl) IsPlus added in v1.2.0

func (m *ManagerImpl) IsPlus() bool

IsPlus returns whether or not we are running NGINX plus.

func (*ManagerImpl) Reload

func (m *ManagerImpl) Reload(ctx context.Context, configVersion int) error

func (*ManagerImpl) UpdateHTTPServers added in v1.2.0

func (m *ManagerImpl) UpdateHTTPServers(upstream string, servers []ngxclient.UpstreamServer) error

UpdateHTTPServers uses the NGINX Plus API to update HTTP upstream servers. Only usable if running NGINX Plus.

type MetricsCollector

type MetricsCollector interface {
	IncReloadCount()
	IncReloadErrors()
	ObserveLastReloadTime(ms time.Duration)
}

MetricsCollector is an interface for the metrics of the NGINX runtime manager.

type NginxPlusClient added in v1.5.0

type NginxPlusClient interface {
	UpdateHTTPServers(
		upstream string,
		servers []ngxclient.UpstreamServer,
	) (
		added []ngxclient.UpstreamServer,
		deleted []ngxclient.UpstreamServer,
		updated []ngxclient.UpstreamServer,
		err error,
	)
	GetUpstreams() (*ngxclient.Upstreams, error)
}

type ProcessHandler added in v1.5.0

type ProcessHandler interface {
	FindMainProcess(
		ctx context.Context,
		timeout time.Duration,
	) (int, error)
	ReadFile(file string) ([]byte, error)
	Kill(pid int) error
}

type ProcessHandlerImpl added in v1.5.0

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

func NewProcessHandlerImpl added in v1.5.0

func NewProcessHandlerImpl(readFile ReadFileFunc, checkFile CheckFileFunc) *ProcessHandlerImpl

func (*ProcessHandlerImpl) FindMainProcess added in v1.5.0

func (p *ProcessHandlerImpl) FindMainProcess(
	ctx context.Context,
	timeout time.Duration,
) (int, error)

func (*ProcessHandlerImpl) Kill added in v1.5.0

func (p *ProcessHandlerImpl) Kill(pid int) error

func (*ProcessHandlerImpl) ReadFile added in v1.5.0

func (p *ProcessHandlerImpl) ReadFile(file string) ([]byte, error)

type ReadFileFunc added in v1.5.0

type ReadFileFunc func(string) ([]byte, error)

type VerifyClient added in v1.5.0

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

VerifyClient is a client for verifying the config version.

func NewVerifyClient added in v1.5.0

func NewVerifyClient(timeout time.Duration) *VerifyClient

NewVerifyClient returns a new client pointed at the config version socket.

func (*VerifyClient) EnsureConfigVersion added in v1.5.0

func (c *VerifyClient) EnsureConfigVersion(ctx context.Context, expectedVersion int) error

func (*VerifyClient) GetConfigVersion added in v1.5.0

func (c *VerifyClient) GetConfigVersion() (int, error)

GetConfigVersion gets the version number that we put in the nginx config to verify that we're using the correct config.

func (*VerifyClient) WaitForCorrectVersion added in v1.5.0

func (c *VerifyClient) WaitForCorrectVersion(
	ctx context.Context,
	expectedVersion int,
	childProcFile string,
	previousChildProcesses []byte,
	readFile ReadFileFunc,
) error

WaitForCorrectVersion first ensures any new worker processes have been started, and then calls the config version endpoint until it gets the expectedVersion, which ensures that a new worker process has been started for that config version.

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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