envoy

package
v0.6.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InvalidBaseID used to indicate that the Envoy BaseID has not been set. Attempting
	// to Close this BaseID will have no effect.
	InvalidBaseID = BaseID(math.MaxUint32)
)

Variables

This section is empty.

Functions

func DrainListeners

func DrainListeners(adminPort uint32, inboundonly bool) error

DrainListeners drains inbound listeners of Envoy so that inflight requests can gracefully finish and even continue making outbound calls as needed.

func GetConfigDump

func GetConfigDump(adminPort uint32) (*envoyAdmin.ConfigDump, error)

GetConfigDump polls Envoy admin port for the config dump and returns the response.

func GetServerInfo

func GetServerInfo(adminPort uint32) (*envoyAdmin.ServerInfo, error)

GetServerInfo returns a structure representing a call to /server_info

func Shutdown

func Shutdown(adminPort uint32) error

Shutdown initiates a graceful shutdown of Envoy.

Types

type Agent

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

func NewAgent

func NewAgent(proxy Proxy, terminationDrainDuration, minDrainDuration time.Duration, localhost string,
	adminPort, statusPort, prometheusPort int, exitOnZeroActiveConnections bool) *Agent

NewAgent creates a new proxy agent for the proxy start-up and clean-up functions.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context)

Run starts the envoy and waits until it terminates.

type BaseID

type BaseID uint32

BaseID is an Option that sets the --base-id flag. This is typically only needed when running multiple Envoys on the same machine (common in testing environments).

Envoy will allocate shared memory if provided with a BaseID. This shared memory is used during hot restarts. It is up to the caller to free this memory by calling Close() on the BaseID when appropriate.

func GenerateBaseID

func GenerateBaseID() BaseID

GenerateBaseID is a method copied from Envoy server tests.

Computes a numeric ID to incorporate into the names of shared-memory segments and domain sockets, to help keep them distinct from other tests that might be running concurrently.

func (BaseID) Close

func (bid BaseID) Close() error

Close removes the shared memory allocated by Envoy for this BaseID.

func (BaseID) FlagName

func (bid BaseID) FlagName() FlagName

func (BaseID) FlagValue

func (bid BaseID) FlagValue() string

func (BaseID) GetInternalEnvoyValue

func (bid BaseID) GetInternalEnvoyValue() uint64

GetInternalEnvoyValue returns the value used internally by Envoy.

type ComponentLogLevel

type ComponentLogLevel struct {
	Name  string
	Level LogLevel
}

ComponentLogLevel defines the log level for a single component.

func (ComponentLogLevel) String

func (l ComponentLogLevel) String() string

type ComponentLogLevels

type ComponentLogLevels []ComponentLogLevel

ComponentLogLevels is an Option for multiple component log levels.

func ParseComponentLogLevels

func ParseComponentLogLevels(value string) ComponentLogLevels

ParseComponentLogLevels parses the given envoy --component-log-level value string.

func (ComponentLogLevels) FlagName

func (l ComponentLogLevels) FlagName() FlagName

func (ComponentLogLevels) FlagValue

func (l ComponentLogLevels) FlagValue() string

type Config

type Config struct {
	// Options provides the command-line options to be passed to Envoy.
	Options Options

	// Name of the envoy instance, used for logging only. If not provided, defaults to "envoy".
	Name string

	// BinaryPath the path to the Envoy binary.
	BinaryPath string

	// WorkingDir to be used when running Envoy. If not set, the current working directory is used.
	WorkingDir string

	// AdminPort specifies the administration port for the Envoy server. If not set, will
	// be determined by parsing the Envoy bootstrap configuration file.
	AdminPort uint32

	// SkipBaseIDClose skips calling Close on the BaseID, if one was specified.
	SkipBaseIDClose bool
}

Config for an Envoy Instance.

type Epoch

type Epoch uint32

Epoch sets the --restart-epoch flag, which specifies the epoch used for hot restart.

func (Epoch) FlagName

func (e Epoch) FlagName() FlagName

func (Epoch) FlagValue

func (e Epoch) FlagValue() string

type FactoryFunc

type FactoryFunc func(cfg Config) (Instance, error)

FactoryFunc is a function that manufactures Envoy Instances.

type FlagName

type FlagName string

FlagName is the raw flag name passed to envoy.

func (FlagName) String

func (n FlagName) String() string

type IPVersion

type IPVersion string

IPVersion is an enumeration for IP versions for the --local-address-ip-version flag.

const (
	IPV4 IPVersion = "v4"
	IPV6 IPVersion = "v6"
)

type Instance

type Instance interface {
	// Config returns the configuration for this Instance.
	Config() Config

	// BaseID used to start Envoy. If not set, returns InvalidBaseID.
	BaseID() BaseID

	// Epoch used to start Envoy. If it was not set, defaults to 0.
	Epoch() Epoch

	// Start the Envoy Instance. The process will be killed if the given context is canceled.
	//
	// If this Instance was created via NewInstanceForHotRestart, this method will block until the parent
	// Instance terminates or goes "live". This is due to the fact that hot restart will fail if the previous
	// envoy process is still initializing.
	Start(ctx context.Context) Instance

	// NewInstanceForHotRestart creates a new Envoy Instance that is configured for a hot restart of this
	// Instance (i.e. epoch is incremented). During a hot restart of Envoy, the old process is drained and
	// traffic is shifted over to the new process.
	//
	// The caller must Start the returned instance to initiate the hot restart.
	//
	// If a new Instance is successfully created, it assumes ownership of the Envoy shared memory segment
	// used for hot restart. This means that when this Instance exits, it will no longer destroy
	// the shared memory segment, regardless of the value of SkipBaseIDClose.
	//
	// If this Instance hasn't been started, calling this method does nothing and simply returns
	// this Instance since there is nothing to restart.
	//
	// This method may only be called once on a given Instance. Subsequent calls will return an error.
	NewInstanceForHotRestart() (Instance, error)

	// WaitUntilLive polls the Envoy ServerInfo endpoint and waits for it to transition to "live". If the
	// wait times out, returns the last known error or context.DeadlineExceeded if no error occurred within the
	// specified duration.
	WaitLive() Waitable

	// AdminPort gets the administration port for Envoy.
	AdminPort() uint32

	// GetServerInfo returns a structure representing a call to /server_info
	GetServerInfo() (*envoyAdmin.ServerInfo, error)

	// GetConfigDump polls Envoy admin port for the config dump and returns the response.
	GetConfigDump() (*envoyAdmin.ConfigDump, error)

	// Wait for the Instance to terminate.
	Wait() Waitable

	// Kill the process, if running.
	Kill() error

	// KillAndWait is a helper that calls Kill and then waits for the process to terminate.
	KillAndWait() Waitable

	// Shutdown initiates the graceful termination of Envoy. Returns immediately and does not
	// wait for the process to exit.
	Shutdown() error

	// ShutdownAndWait is a helper that calls Shutdown and waits for the process to terminate.
	ShutdownAndWait() Waitable

	// DrainListeners drains listeners of Envoy so that inflight requests
	// can gracefully finish and even continue making outbound calls as needed.
	DrainListeners() error
}

Instance of an Envoy process.

func New

func New(cfg Config) (Instance, error)

New creates a new Envoy Instance with the given options.

type LogLevel

type LogLevel string

LogLevel is an Option that sets the Envoy log level.

const (
	LogLevelTrace    LogLevel = "trace"
	LogLevelDebug    LogLevel = "debug"
	LogLevelInfo     LogLevel = "info"
	LogLevelWarning  LogLevel = "warning"
	LogLevelCritical LogLevel = "critical"
	LogLevelOff      LogLevel = "off"
)

func (LogLevel) FlagName

func (l LogLevel) FlagName() FlagName

func (LogLevel) FlagValue

func (l LogLevel) FlagValue() string

type Option

type Option interface {
	// FlagName returns the flag name used on the command line.
	FlagName() FlagName

	// FlagValue returns the flag value used on the command line. Can be empty for boolean flags.
	FlagValue() string
	// contains filtered or unexported methods
}

Option for an Envoy Instance.

func Concurrency

func Concurrency(concurrency uint16) Option

Concurrency sets the --concurrency flag, which sets the number of worker threads to run.

func ConfigPath

func ConfigPath(path string) Option

ConfigPath sets the --config-path flag, which provides Envoy with the to the v2 bootstrap configuration file. If not set, ConfigYaml is required.

func ConfigYaml

func ConfigYaml(yaml string) Option

ConfigYaml sets the --config-yaml flag, which provides Envoy with the a YAML string for a v2 bootstrap configuration. If ConfigPath is also set, the values in this YAML string will override and merge with the bootstrap loaded from ConfigPath.

func DisableHotRestart

func DisableHotRestart(disable bool) Option

DisableHotRestart sets the --disable-hot-restart flag.

func DrainDuration

func DrainDuration(duration time.Duration) Option

DrainDuration sets the --drain-time-s flag, which defines the amount of time that Envoy will drain connections during a hot restart.

func LocalAddressIPVersion

func LocalAddressIPVersion(v IPVersion) Option

LocalAddressIPVersion sets the --local-address-ip-version flag, which sets the IP address version used for the local IP address. The default is V4.

func LogFormat

func LogFormat(format string) Option

LogFormat sets the --log-format flag, which specifies the format string to use for log messages.

func LogPath

func LogPath(path string) Option

LogPath sets the --log-path flag, which specifies the output file for logs. If not set logs will be written to stderr.

func ParentShutdownDuration

func ParentShutdownDuration(duration time.Duration) Option

ParentShutdownDuration sets the --parent-shutdown-time-s flag, which defines the amount of time that Envoy will wait before shutting down the parent process during a hot restart

func ServiceCluster

func ServiceCluster(c string) Option

ServiceCluster sets the --service-cluster flag, which defines the local service cluster name where Envoy is running

func ServiceNode

func ServiceNode(n string) Option

ServiceNode sets the --service-node flag, which defines the local service node name where Envoy is running

type Options

type Options []Option

func NewOptions

func NewOptions(args ...string) (Options, error)

NewOptions creates new Options from the given raw Envoy arguments. Returns an error if a problem was encountered while parsing the arguments.

func (Options) ToArgs

func (options Options) ToArgs() []string

ToArgs creates the command line arguments for the list of options.

func (Options) Validate

func (options Options) Validate() error

Validate the Options.

type Proxy

type Proxy interface {
	// Run command for an epoch, and abort channel
	Run(int, <-chan error) error

	// Drains the current epoch.
	Drain() error

	// Cleanup command for an epoch
	Cleanup(int)

	// UpdateConfig writes a new config file
	UpdateConfig(config []byte) error
}

Proxy defines command interface for a proxy

func NewProxy

func NewProxy(cfg ProxyConfig) Proxy

NewProxy creates an instance of the proxy control commands

type ProxyConfig

type ProxyConfig struct {
	LogLevel          string
	ComponentLogLevel string
	NodeIPs           []string
	Sidecar           bool
	LogAsJSON         bool
	// TODO: outlier log path configuration belongs to mesh ProxyConfig
	OutlierLogPath string

	BinaryPath             string
	ConfigPath             string
	ConfigCleanup          bool
	AdminPort              int32
	DrainDuration          *durationpb.Duration
	ParentShutdownDuration *durationpb.Duration
	Concurrency            int32

	// For unit testing, in combination with NoEnvoy prevents agent.Run from blocking
	TestOnly    bool
	AgentIsRoot bool
}

Envoy binary flags

type Waitable

type Waitable interface {
	// WithTimeout specifies an upper bound on the wait time.
	WithTimeout(timeout time.Duration) Waitable

	// Do performs the wait. By default, waits indefinitely. To specify an upper bound on
	// the wait time, use WithTimeout. If the wait times out, returns the last known error
	// for retried operations or context.DeadlineExceeded if no previous error was encountered.
	Do() error
}

Waitable specifies a waitable operation.

Jump to

Keyboard shortcuts

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