common

package
v0.0.0-...-3b31870 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConnectionTimeout = 2 * time.Second
	DefaultCount      = 1
)

Variables

View Source
var (
	// DefaultGRPCDialFunc just calls grpc.Dial directly, with no alterations to the arguments.
	DefaultGRPCDialFunc = grpc.DialContext
	//// DefaultWebsocketDialFunc just calls dialer.Dial, with no alterations to the arguments.
	//DefaultWebsocketDialFunc = func(dialer *websocket.Dialer, urlStr string, requestHeader http.Header) (*websocket.Conn, *http.Response, error) {
	//	return dialer.Dial(urlStr, requestHeader)
	//}
	// DefaultHTTPDoFunc just calls client.Do with no alterations to the arguments.
	DefaultHTTPDoFunc = func(client *http.Client, req *http.Request) (*http.Response, error) {
		return client.Do(req)
	}
	// DefaultTCPDialFunc just calls dialer.Dial, with no alterations to the arguments.
	DefaultTCPDialFunc = func(dialer net.Dialer, ctx context.Context, address string) (net.Conn, error) {
		return dialer.DialContext(ctx, "tcp", address)
	}
	// DefaultDialer is provides defaults for all dial functions.
	DefaultDialer = Dialer{
		GRPC: DefaultGRPCDialFunc,

		HTTP: DefaultHTTPDoFunc,
		TCP:  DefaultTCPDialFunc,
	}
)
View Source
var (
	PortLabel = monitoring.MustCreateLabel("port")
	Metrics   = &EchoMetrics{
		HTTPRequests: monitoring.NewSum(
			"istio_echo_http_requests_total",
			"The number of http requests total",
		),
		GrpcRequests: monitoring.NewSum(
			"istio_echo_grpc_requests_total",
			"The number of grpc requests total",
		),
		TCPRequests: monitoring.NewSum(
			"istio_echo_tcp_requests_total",
			"The number of tcp requests total",
		),
	}
)
View Source
var DefaultRequestTimeout = 5 * time.Second
View Source
var ErrResolveNoAddress = fmt.Errorf("no address specified")

ErrResolveNoAddress error occurs when IP address resolution is attempted, but no address was provided.

View Source
var ServerFirstMagicString = "server-first-protocol\n"

Functions

func DurationToMicros

func DurationToMicros(d time.Duration) int64

DurationToMicros converts the given duration to microseconds.

func FillInDefaults

func FillInDefaults(request *proto.ForwardEchoRequest)

FillInDefaults fills in the timeout and count if not specified in the given message.

func GetCount

func GetCount(request *proto.ForwardEchoRequest) int

GetCount returns the count value or DefaultCount if not set.

func GetHeaders

func GetHeaders(request *proto.ForwardEchoRequest) http.Header

GetHeaders returns the headers for the message.

func GetPrivateIPs

func GetPrivateIPs(ctx context.Context) ([]string, bool)

GetPrivateIPs blocks until private IP addresses are available, or a timeout is reached.

func GetTimeout

func GetTimeout(request *proto.ForwardEchoRequest) time.Duration

GetTimeout returns the timeout value as a time.Duration or DefaultRequestTimeout if not set.

func IsIPv6Proxy

func IsIPv6Proxy(ipAddrs []string) bool

IsIPv6Proxy check the addresses slice and returns true for all addresses are valid IPv6 address for all other cases it returns false

func MicrosToDuration

func MicrosToDuration(micros int64) time.Duration

MicrosToDuration converts the given microseconds to a time.Duration.

func ResolveAddr

func ResolveAddr(addr string, lookupIPAddr ...lookupIPAddrType) (string, error)

ResolveAddr resolves an authority address to an IP address. Incoming addr can be an IP address or hostname. If addr is an IPv6 address, the IP part must be enclosed in square brackets.

LookupIPAddr() may return multiple IP addresses, of which this function returns the first IPv4 entry. To use this function in an IPv6 only environment, either provide an IPv6 address or ensure the hostname resolves to only IPv6 addresses.

Types

type Dialer

type Dialer struct {
	GRPC GRPCDialFunc
	//Websocket WebsocketDialFunc
	HTTP HTTPDoFunc
	TCP  TCPDialFunc
}

Dialer is a replaceable set of functions for creating client-side connections for various protocols, allowing a test application to intercept the connection creation.

func (Dialer) FillInDefaults

func (d Dialer) FillInDefaults() Dialer

FillInDefaults fills in any missing dial functions with defaults

type EchoMetrics

type EchoMetrics struct {
	HTTPRequests monitoring.Metric
	GrpcRequests monitoring.Metric
	TCPRequests  monitoring.Metric
}

type Failer

type Failer interface {
	Fail()
	FailNow()
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Log(args ...interface{})
	Logf(format string, args ...interface{})
	TempDir() string
	Helper()
	Cleanup(func())
}

Failer is an interface to be provided to test functions of the form XXXOrFail. This is a substitute for testing.TB, which cannot be implemented outside of the testing package.

type GRPCDialFunc

type GRPCDialFunc func(ctx context.Context, address string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

GRPCDialFunc a function for establishing a GRPC connection.

type HTTPDoFunc

type HTTPDoFunc func(client *http.Client, req *http.Request) (*http.Response, error)

HTTPDoFunc a function for executing an HTTP request.

type Port

type Port struct {
	// Name ascribes a human readable name for the port object. When a
	// service has multiple ports, the name field is mandatory
	Name string

	// Port number where the service can be reached. Does not necessarily
	// map to the corresponding port numbers for the instances behind the
	// service.
	Port int

	// Protocol to be used for the port.
	Protocol protocol.Instance

	// TLS determines if the port will use TLS.
	TLS bool

	// ServerFirst if a port will be server first
	ServerFirst bool

	// InstanceIP determines if echo will listen on the instance IP, or wildcard
	InstanceIP bool

	// LocalhostIP determines if echo will listen on the localhost IP; otherwise, it will listen on wildcard
	LocalhostIP bool

	// XDSServer, for gRPC servers, will use the xds.NewGRPCServer constructor to rely on XDS configuration.
	// If this flag is set but the environment variable feature gates aren't, we should fail due to gRPC internals.
	XDSServer bool

	// XDSTestBootstrap allows settings per-endpoint bootstrap without using the GRPC_XDS_BOOTSTRAP env var
	XDSTestBootstrap []byte

	// XDSReadinessTLS determines if the XDS server should expect a TLS server, used for readiness probes
	XDSReadinessTLS bool
}

Port represents a network port where a service is listening for connections. The port should be annotated with the type of protocol used by the port.

type PortList

type PortList []*Port

PortList is a set of ports

type TCPDialFunc

type TCPDialFunc func(dialer net.Dialer, ctx context.Context, address string) (net.Conn, error)

TCPDialFunc a function for establishing a TCP connection.

type TLSSettings

type TLSSettings struct {
	// If not empty, RootCert supplies the extra root cert that will be appended to the system cert pool.
	RootCert   string
	ClientCert string
	Key        string
	// If provided, override the host name used for the connection
	// This needed for integration tests, as we are connecting using a port-forward (127.0.0.1), so
	// any DNS certs will not validate.
	Hostname string
	// If set to true, the cert will be provisioned by proxy, and extra cert volume will be mounted.
	ProxyProvision bool
	// AcceptAnyALPN, if true, will make the server accept ANY ALPNs. This comes at the expense of
	// allowing h2 negotiation and being able to detect the negotiated ALPN (as there is none), because
	// Golang doesn't like us doing this (https://github.com/golang/go/issues/46310).
	// This is useful when the server is simulating Envoy which does unconventional things with ALPN.
	AcceptAnyALPN bool
}

TLSSettings defines TLS configuration for Echo server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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