Documentation
¶
Overview ¶
Package grpchelpers includes helpers to set up grpc connections.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dial ¶
func Dial(conf Config) (*grpc.ClientConn, error)
Dial wraps up a standard set of dial behaviours that most grpc clients will want to use. Using this will default to some grpc calls retrying if the name resolver does not provide a service config.
func NewServerHandler ¶
NewServerHandler creates a stats.Handler for a gRPC server.
func ProxyProofTarget ¶
ProxyProofTarget takes the host and if there is no proxy in place in the environment at all or if there is a proxy, but we should still use it for the given url, the returned host will include the dns:// prefix.
Note if this is used to avoid traffic going via a proxy then DNS based load balancing is disabled.
A Note On Proxies.
NO_PROXY domain names can't be honored with dns scheme because of https://github.com/grpc/grpc-go/issues/3401
The following doc... https://github.com/grpc/grpc/blob/master/doc/naming.md suggests that if no scheme prefix is used then the dns is used automatically, but this is a bit misleading.
The dns scheme does a lookup for any SRV and multiple A records amongst other things, to set up a list of servers. At this point the server addresses are all in the form ip:port. The thing is - nothing is actually connected at this point, connections are made lazily. Using the dns scheme supports client side per request load balancing.
If the dns scheme is not used then in fact go grpc uses a 'passthrough' scheme, which defers name resolution to the standard (dns) resolver at connection (dial) time passing through the server name, resolving to one IP. This obviously does not support client side per call balancing.
The detection of a proxy only happens during dialing, and it is the proxy environment variables that indicate whether a proxy should be used.
In the 'passthrough' case because we have the full domain during dialing the client can compare this with the list of domains in the NO_PROXY list. However, in the full dns scheme case we only have a list of IPs which don't match anything in the NO_PROXY list - so they are duly proxied. host should be the host part not including scheme, or have the dns scheme in which case the authority should not be present
func Retryable ¶
Retryable returns true if the error carries a gRPC status code that indicates the call my succeed, if attempted again. Specific servers may have different requirements for what should be retried, so double check that before using this.
func ServiceConfig ¶
ServiceConfig returns a JSON-encoded service config. Takes a service name as defined in the service's .proto file (e.g. "package.ServiceName").
Types ¶
type Config ¶
type Config struct {
// Host is the grpc host URL typically in this form: "dns:///service.domain.:80" if load balancing is desired
// otherwise the raw host should be provided without the dns:/// prefix.
// If the dns:// load balancing scheme is indicated - authority is not accepted and should be empty
Host string
// ServiceName should be as it is defined in the service's .proto file
// (e.g. "package.ServiceName").
ServiceName string
// Timeout is the maximum duration we allow any call to take. Note if this timeout is
// hit then the default retries will not happen, it is up to the caller to decide on retry behaviour.
Timeout time.Duration
}
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error wraps the grpc error to decide if the error is an o11y warning.
func (*Error) Is ¶
Is checks that this error is being checked for the special o11y error that is not added to the trace as an error. If the error is due to relatively expected failure response codes return true so it will appear in the trace as a warning. N.B. We should not see 3XX codes normally in our client responses, so we currently consider them errors.
func (*Error) Retryable ¶
Retryable returns true if the error was caused by a problem that could succeed if resubmitted unchanged.