client

package
v0.0.0-...-48a44ca Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TypeURLTag holds the type URL for the context.
	TypeURLTag tag.Key
	// ErrorCodeTag holds the gRPC error code for the context.
	ErrorCodeTag tag.Key
	// ErrorTag holds the error string for the context.
	ErrorTag tag.Key
)

Functions

This section is empty.

Types

type Change

type Change struct {
	TypeURL string
	Objects []*Object
}

Change is a collection of configuration objects of the same protobuf type.

type Client

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

Client is a client implementation of the Mesh Configuration Protocol (MCP). It is responsible for the following:

  • Maintaining the bidirectional grpc stream with the server. The stream will be reestablished on transient network failures. The provided grpc connection (mcpClient) is assumed to handle (re)dialing the server.
  • Handling all aspects of the MCP exchange for the supported message types, e.g. request/response, ACK/NACK, nonce, versioning,

- Decoding the received configuration updates and providing them to the user via a batched set of changes.

func New

func New(mcpClient mcp.AggregatedMeshConfigServiceClient, supportedTypeURLs []string, updater Updater, id string, metadata map[string]string, reporter MetricReporter) *Client

New creates a new instance of the MCP client for the specified message types.

func (*Client) ID

func (c *Client) ID() string

ID is the node id for this client.

func (*Client) Metadata

func (c *Client) Metadata() map[string]string

Metadata that is originally supplied when creating this client.

func (*Client) Run

func (c *Client) Run(ctx context.Context)

Run starts the run loop for request and receiving configuration updates from the server. This function blocks and should typically be run in a goroutine. The client will continue to attempt to re-establish the stream with the server indefinitely. The function exits when the provided context is canceled.

func (*Client) SnapshotRequestInfo

func (c *Client) SnapshotRequestInfo() []RecentRequestInfo

SnapshotRequestInfo returns a snapshot of the last known set of request results.

func (*Client) SupportedTypeURLs

func (c *Client) SupportedTypeURLs() []string

SupportedTypeURLs returns the TypeURLs that this client requests.

type MetricReporter

type MetricReporter interface {
	RecordSendError(err error, code codes.Code)
	RecordRecvError(err error, code codes.Code)
	RecordRequestAck(typeURL string)
	RecordRequestNack(typeURL string, err error)
	RecordStreamCreateSuccess()
}

MetricReporter is used to report metrics for an MCP client.

type Object

type Object struct {
	TypeURL  string
	Metadata *mcp.Metadata
	Resource proto.Message
}

Object contains a decoded versioned object with metadata received from the server.

type RecentRequestInfo

type RecentRequestInfo struct {
	Time    time.Time
	Request *mcp.MeshConfigRequest
}

RecentRequestInfo is metadata about a request that the client has sent.

func (RecentRequestInfo) Acked

func (r RecentRequestInfo) Acked() bool

Acked indicates whether the message was an ack or not.

type StatsContext

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

StatsContext enables metric collection backed by OpenCensus.

func NewStatsContext

func NewStatsContext(prefix string) *StatsContext

NewStatsContext creates a new context for recording metrics using OpenCensus. The specified prefix is prepended to all metric names and must be a non-empty string.

func (*StatsContext) RecordRecvError

func (s *StatsContext) RecordRecvError(err error, code codes.Code)

RecordRecvError records an error during a network recv with its error string and code.

func (*StatsContext) RecordRequestAck

func (s *StatsContext) RecordRequestAck(typeURL string)

RecordRequestAck records an ACK message for a type URL on a connection.

func (*StatsContext) RecordRequestNack

func (s *StatsContext) RecordRequestNack(typeURL string, err error)

RecordRequestNack records a NACK message for a type URL on a connection.

func (*StatsContext) RecordSendError

func (s *StatsContext) RecordSendError(err error, code codes.Code)

RecordSendError records an error during a network send with its error string and code.

func (*StatsContext) RecordStreamCreateSuccess

func (s *StatsContext) RecordStreamCreateSuccess()

RecordStreamCreateSuccess records a successful stream connection.

type Updater

type Updater interface {
	// Apply is invoked when the client receives new configuration updates
	// from the server. The caller should return an error if any of the provided
	// configuration resources are invalid or cannot be applied. The client will
	// propagate errors back to the server accordingly.
	Apply(*Change) error
}

Updater provides configuration changes in batches of the same protobuf message type.

Jump to

Keyboard shortcuts

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