atcclient

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package atcclient implements a client for the Roxy Air Traffic Control protocol.

Index

Constants

View Source
const ReportInterval = 1 * time.Second

ReportInterval is the time interval between reports sent within ServerAnnounce and ClientAssign.

Variables

This section is empty.

Functions

func CancelWatchIsServing added in v0.5.0

func CancelWatchIsServing(id WatchID)

CancelWatchIsServing cancels a previous call to WatchIsServing.

func GetCostCounter added in v0.5.0

func GetCostCounter() uint64

GetCostCounter captures a snapshot of the cost counter.

func HasUniqueID added in v0.6.0

func HasUniqueID() bool

HasUniqueID returns true iff the ATC Unique ID could be loaded or persisted.

The program must call SetUniqueFile in main() before calling this function.

func IsServing added in v0.5.0

func IsServing() bool

IsServing returns true if the ATC client is currently serving.

For a server, "serving" means accepting inbound traffic. For a client, "serving" means actively generating non-trivial outbound traffic.

func SetIsServing added in v0.5.0

func SetIsServing(isServing bool)

SetIsServing modifies the serving status.

func SetUniqueFile added in v0.6.0

func SetUniqueFile(path string)

SetUniqueFile specifies the path to the state file where UniqueID is stored.

func Spend added in v0.4.6

func Spend(cost uint)

Spend records that a query just happened and the cost value of that query.

(For clients, this represents demand created by outgoing requests. For servers, this represents supply consumed by incoming requests.)

The cost must be a number between 0 and 65536, inclusive.

func UniqueID added in v0.6.0

func UniqueID() (string, error)

UniqueID returns the ATC Unique ID associated with this program.

The program must call SetUniqueFile in main() before calling this function.

Types

type ATCClient

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

ATCClient is a client for communicating with the Roxy Air Traffic Controller service.

Each ATC tower is responsible for a set of (ServiceName, ShardNumber) tuples, which are exclusive to that tower. The client automatically determines which tower it needs to speak with, by asking any tower within the service to provide instructions.

func New

func New(cc *grpc.ClientConn, tlsConfig *tls.Config) (*ATCClient, error)

New constructs and returns a new ATCClient. The cc argument is a gRPC ClientConn configured to speak to any/all ATC towers. The tlsConfig argument specifies the TLS client configuration to use when speaking to individual ATC towers, or nil for gRPC with no TLS.

func (*ATCClient) ClientAssign

func (c *ATCClient) ClientAssign(
	ctx context.Context,
	first *roxy_v0.ClientData,
) (
	context.CancelFunc,
	<-chan []*roxy_v0.Event,
	<-chan error,
	error,
)

ClientAssign starts a subscription for assignment Events. If the method returns with no error, then the caller must call the returned CancelFunc when it is no longer interested in receiving Events, and the caller is also responsible for draining both channels in a timely manner.

func (*ATCClient) Close

func (c *ATCClient) Close() error

Close closes all gRPC channels and blocks until all resources are freed.

func (*ATCClient) Dial

Dial returns a gRPC ClientConn connected directly to the given ATC tower.

The caller should _not_ call Close() on it. It is owned by the ATCClient and will be re-used until the ATCClient itself is Close()'d.

func (*ATCClient) Find

func (c *ATCClient) Find(
	ctx context.Context,
	key Key,
	useCache bool,
) (
	*net.TCPAddr,
	error,
)

Find queries any ATC tower for information about which ATC tower is responsible for the given (ServiceName, ShardNumber) tuple. If useCache is false, then the local cache will not be consulted.

func (*ATCClient) Lookup

func (c *ATCClient) Lookup(
	ctx context.Context,
	key Key,
) (
	*roxy_v0.LookupResponse,
	error,
)

Lookup queries any ATC tower for information about the given service or shard. Unlike with most other uses of Key, setting HasShardNumber to false is a wildcard lookup that returns information about all shards (if the service is sharded), rather than an assertion that the service is not sharded.

func (*ATCClient) LookupClients added in v0.5.1

func (c *ATCClient) LookupClients(
	ctx context.Context,
	key Key,
	uniqueID string,
) (
	*roxy_v0.LookupClientsResponse,
	error,
)

LookupClients queries any ATC tower for information about the active clients of a given shard.

func (*ATCClient) LookupServers added in v0.5.1

func (c *ATCClient) LookupServers(
	ctx context.Context,
	key Key,
	uniqueID string,
) (
	*roxy_v0.LookupServersResponse,
	error,
)

LookupServers queries any ATC tower for information about the active servers of a given shard.

func (*ATCClient) ServerAnnounce

func (c *ATCClient) ServerAnnounce(
	ctx context.Context,
	first *roxy_v0.ServerData,
) (
	context.CancelFunc,
	<-chan error,
	error,
)

ServerAnnounce starts announcing that a new server is available for the given (ServiceName, ShardNumber) tuple. If the method returns with no error, then the caller must call the returned CancelFunc when the announcement should be withdrawn, and the caller must also ensure that the returned error channel is drained in a timely manner. The error channel will be closed once all goroutines and other internal resources have been released.

type InterceptorAdjustFunc added in v0.4.6

type InterceptorAdjustFunc func(oldCost uint32, request interface{}) uint32

InterceptorAdjustFunc is a closure that is permitted to peek at the contents of the gRPC request body.

type InterceptorFactory added in v0.4.6

type InterceptorFactory struct {
	DefaultCostPerQuery    uint32
	DefaultCostPerRequest  uint32
	DefaultCostPerResponse uint32
	ByFullMethod           map[string]InterceptorPerMethod
}

InterceptorFactory creates gRPC Interceptors (and other wrapper types) for capturing cost-adjusted query-per-second data.

func (InterceptorFactory) Cost added in v0.4.6

func (factory InterceptorFactory) Cost(method string) (costPerQuery, costPerReq, costPerResp uint32, adjustFn InterceptorAdjustFunc)

Cost returns the cost factors for the named method.

The method should be in gRPC "full method" syntax, i.e. a URL path like "/package.of.Service/Method".

func (InterceptorFactory) DialOptions added in v0.4.6

func (factory InterceptorFactory) DialOptions(more ...grpc.DialOption) []grpc.DialOption

DialOptions returns the DialOptions for installing client-side gRPC interceptors.

func (InterceptorFactory) Handler added in v0.4.6

func (factory InterceptorFactory) Handler(inner http.Handler) http.Handler

Handler wraps an http.Handler to install server-side HTTP cost instrumentation.

See RoundTripper for details of how HTTP requests are mapped to gRPC calls.

func (InterceptorFactory) RoundTripper added in v0.4.6

func (factory InterceptorFactory) RoundTripper(inner http.RoundTripper) http.RoundTripper

RoundTripper wraps an http.RoundTripper to install client-side HTTP cost instrumentation.

The HTTP requests are treated as if they are unitary gRPC calls, with a "full method" name of "/your/url/here@VERB" for HTTP method "VERB", and a request type of *http.Request.

(The query string is not included in the "full method" name.)

func (InterceptorFactory) ServerOptions added in v0.4.6

func (factory InterceptorFactory) ServerOptions(more ...grpc.ServerOption) []grpc.ServerOption

ServerOptions returns the ServerOptions for installing server-side gRPC interceptors.

func (InterceptorFactory) StreamClientInterceptor added in v0.4.6

func (factory InterceptorFactory) StreamClientInterceptor() grpc.StreamClientInterceptor

StreamClientInterceptor returns a gRPC StreamClientInterceptor.

func (InterceptorFactory) StreamServerInterceptor added in v0.4.6

func (factory InterceptorFactory) StreamServerInterceptor() grpc.StreamServerInterceptor

StreamServerInterceptor returns a gRPC StreamServerInterceptor.

func (InterceptorFactory) UnaryClientInterceptor added in v0.4.6

func (factory InterceptorFactory) UnaryClientInterceptor() grpc.UnaryClientInterceptor

UnaryClientInterceptor returns a gRPC UnaryClientInterceptor.

func (InterceptorFactory) UnaryServerInterceptor added in v0.4.6

func (factory InterceptorFactory) UnaryServerInterceptor() grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a gRPC UnaryServerInterceptor.

type InterceptorPerMethod added in v0.4.6

type InterceptorPerMethod struct {
	CostPerQuery    uint32
	CostPerRequest  uint32
	CostPerResponse uint32
	AdjustFunc      InterceptorAdjustFunc
}

InterceptorPerMethod is the cost adjustments for a specific gRPC method. Client-side SendMsg and server-side RecvMsg events will be routed through AdjustFunc, if non-nil.

type Key added in v0.5.1

type Key struct {
	ServiceName    string
	ShardNumber    uint32
	HasShardNumber bool
}

Key represents a (ServiceName, ShardNumber) tuple, where the ShardNumber is optional. If HasShardNumber is false, then ShardNumber should be zero.

func (*Key) ForceCanonical added in v0.5.1

func (key *Key) ForceCanonical()

ForceCanonical ensures that this Key is in the canonical format, i.e. that SharID is zero if HasShardNumber is false.

func (Key) String added in v0.5.1

func (key Key) String() string

String returns a human-readable string representation of this Key.

type WatchFunc added in v0.5.0

type WatchFunc func(bool)

WatchFunc is the callback type for observing changes in serving status.

type WatchID added in v0.5.0

type WatchID uint32

WatchID tracks a registered WatchFunc.

func WatchIsServing added in v0.5.0

func WatchIsServing(fn WatchFunc) WatchID

WatchIsServing calls the given callback when the serving status changes.

Jump to

Keyboard shortcuts

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