istio: Index | Files | Directories

package common

import ""


Package Files

dialer.go metrics.go model.go util.go websocket.go


const (
    ConnectionTimeout     = 2 * time.Second
    DefaultRequestTimeout = 15 * time.Second
    DefaultCount          = 1


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,
        Websocket: DefaultWebsocketDialFunc,
        HTTP:      DefaultHTTPDoFunc,
        TCP:       DefaultTCPDialFunc,
var (
    PortLabel = monitoring.MustCreateLabel("port")
    Metrics   = &EchoMetrics{
        HTTPRequests: monitoring.NewSum(
            "The number of http requests total",
        GrpcRequests: monitoring.NewSum(
            "The number of grpc requests total",
        TCPRequests: monitoring.NewSum(
            "The number of tcp requests total",
var ServerFirstMagicString = "server-first-protocol\n"

func DurationToMicros Uses

func DurationToMicros(d time.Duration) int64

DurationToMicros converts the given duration to microseconds.

func FillInDefaults Uses

func FillInDefaults(request *proto.ForwardEchoRequest)

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

func GetCount Uses

func GetCount(request *proto.ForwardEchoRequest) int

GetCount returns the count value or DefaultCount if not set.

func GetHeaders Uses

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

GetHeaders returns the headers for the message.

func GetTimeout Uses

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

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

func IsWebSocketRequest Uses

func IsWebSocketRequest(r *http.Request) bool

IsWebSocketRequest indicates whether the request contains the header that triggers an upgrade to the WebSocket protocol.

func MicrosToDuration Uses

func MicrosToDuration(micros int64) time.Duration

MicrosToDuration converts the given microseconds to a time.Duration.

func SetWebSocketHeader Uses

func SetWebSocketHeader(headers http.Header)

SetWebSocketHeader sets the header on the request which will trigger an upgrade to the WebSocket protocol.

type Dialer Uses

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 Uses

func (d Dialer) FillInDefaults() Dialer

FillInDefaults fills in any missing dial functions with defaults

type EchoMetrics Uses

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

type GRPCDialFunc Uses

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

GRPCDialFunc a function for establishing a GRPC connection.

type HTTPDoFunc Uses

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

HTTPDoFunc a function for executing an HTTP request.

type Port Uses

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

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 Uses

type PortList []*Port

PortList is a set of ports

type TCPDialFunc Uses

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

TCPDialFunc a function for establishing a TCP connection.

type TLSSettings Uses

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 (, so
    // any DNS certs will not validate.
    Hostname string

TLSSettings defines TLS configuration for Echo server

type WebsocketDialFunc Uses

type WebsocketDialFunc func(dialer *websocket.Dialer, urlStr string, requestHeader http.Header) (*websocket.Conn, *http.Response, error)

WebsocketDialFunc a function for establishing a Websocket connection.



Package common imports 9 packages (graph) and is imported by 10 packages. Updated 2020-12-21. Refresh now. Tools for package owners.