Documentation ¶
Overview ¶
Package atcclient implements a client for the Roxy Air Traffic Control protocol.
Index ¶
- Constants
- func CancelWatchIsServing(id WatchID)
- func GetCostCounter() uint64
- func IsServing() bool
- func SetIsServing(isServing bool)
- func Spend(cost uint)
- type ATCClient
- func (c *ATCClient) ClientAssign(ctx context.Context, first *roxy_v0.ClientData) (context.CancelFunc, <-chan []*roxy_v0.Event, <-chan error, error)
- func (c *ATCClient) Close() error
- func (c *ATCClient) Dial(ctx context.Context, addr *net.TCPAddr) (*grpc.ClientConn, roxy_v0.AirTrafficControlClient, error)
- func (c *ATCClient) Find(ctx context.Context, key Key, useCache bool) (*net.TCPAddr, error)
- func (c *ATCClient) Lookup(ctx context.Context, key Key) (*roxy_v0.LookupResponse, error)
- func (c *ATCClient) LookupClients(ctx context.Context, key Key, uniqueID string) (*roxy_v0.LookupClientsResponse, error)
- func (c *ATCClient) LookupServers(ctx context.Context, key Key, uniqueID string) (*roxy_v0.LookupServersResponse, error)
- func (c *ATCClient) ServerAnnounce(ctx context.Context, first *roxy_v0.ServerData) (context.CancelFunc, <-chan error, error)
- type InterceptorAdjustFunc
- type InterceptorFactory
- func (factory InterceptorFactory) Cost(method string) (costPerQuery, costPerReq, costPerResp uint32, adjustFn InterceptorAdjustFunc)
- func (factory InterceptorFactory) DialOptions(more ...grpc.DialOption) []grpc.DialOption
- func (factory InterceptorFactory) Handler(inner http.Handler) http.Handler
- func (factory InterceptorFactory) RoundTripper(inner http.RoundTripper) http.RoundTripper
- func (factory InterceptorFactory) ServerOptions(more ...grpc.ServerOption) []grpc.ServerOption
- func (factory InterceptorFactory) StreamClientInterceptor() grpc.StreamClientInterceptor
- func (factory InterceptorFactory) StreamServerInterceptor() grpc.StreamServerInterceptor
- func (factory InterceptorFactory) UnaryClientInterceptor() grpc.UnaryClientInterceptor
- func (factory InterceptorFactory) UnaryServerInterceptor() grpc.UnaryServerInterceptor
- type InterceptorPerMethod
- type Key
- type WatchFunc
- type WatchID
Constants ¶
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 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 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.
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, ShardID) 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 ¶
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) Dial ¶
func (c *ATCClient) Dial(ctx context.Context, addr *net.TCPAddr) (*grpc.ClientConn, roxy_v0.AirTrafficControlClient, error)
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 ¶
Find queries any ATC tower for information about which ATC tower is responsible for the given (ServiceName, ShardID) tuple. If useCache is false, then the local cache will not be consulted.
func (*ATCClient) Lookup ¶
Lookup queries any ATC tower for information about the given service or shard. Unlike with most other uses of Key, setting HasShardID 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, ShardID) 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
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
Key represents a (ServiceName, ShardID) tuple, where the ShardID is optional. If HasShardID is false, then ShardID 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 HasShardID is false.