Documentation ¶
Overview ¶
Package discoverkit is an extensible for discovering Dogma applications running on a network.
Index ¶
Constants ¶
const ( // DefaultDNSQueryInterval is the default interval at which DNS queries are // performed. DefaultDNSQueryInterval = 10 * time.Second )
const ( // DefaultGRPCPort is the default TCP port used by servers that implement // the APIs in interopspec, in particular the DiscoverAPI. DefaultGRPCPort = "50555" )
const DefaultKubernetesPortName = "dogma"
DefaultKubernetesPortName is the default port name used to discover Kubernetes services that are valid gRPC targets.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application struct { // Identity is the application's identity. Identity configkit.Identity // Target is the gRPC target that is hosting the application. Target Target // Connection is the connection that was used to discover the application. Connection grpc.ClientConnInterface }
Application is a Dogma application that was discovered on a Target.
type ApplicationDiscoverer ¶
type ApplicationDiscoverer struct { // Dial is the function used to dial gRPC targets. // // If it is nil, grpc.DialContext() is used. Dial Dialer // BackoffStrategy is the strategy that determines when to retry watching a // gRPC target for application availability changes. BackoffStrategy backoff.Strategy // LogError is an optional function that logs errors that occur while // attempting to watch a gRPC target. LogError func(Target, error) }
ApplicationDiscoverer is a service that discovers Dogma applications running on gRPC targets.
It discovers applications on gRPC targets that implement the DiscoverAPI as defined in github.com/dogmatiq/interopspec/discoverspec. An implementation of this API is provided by the discoverkit.Server type.
func (*ApplicationDiscoverer) DiscoverApplications ¶
func (d *ApplicationDiscoverer) DiscoverApplications( ctx context.Context, t Target, obs ApplicationObserver, ) error
DiscoverApplications invokes an observer for each Dogma application target that is discovered on a specific gRPC target.
It returns a nil error if the target is contactable but it does not implement the DiscoverAPI service. Otherwise, it runs until ctx is canceled.
Errors that occur while communicating with the target are logged to the LogError function, if present, before retrying. The retry interval is determined by the discoverer's BackoffStrategy.
The context passed to the observer is canceled when the application becomes unavailable or the discover is stopped.
The discoverer MAY block on calls to the observer. It is the observer's responsibility to start new goroutines to handle background tasks, as appropriate.
type ApplicationObserver ¶
type ApplicationObserver func(ctx context.Context, a Application)
ApplicationObserver is a function that handles the discovery of a Dogma application running on a gRPC target.
ctx is canceled when the application becomes unavailable or the discoverer is stopped. ctx is NOT canceled when the observer function returns and as such may be used by goroutines started by the observer.
The discoverer MAY block on calls to the observer. It is the observer's responsibility to start new goroutines to handle background tasks, as appropriate.
Note that it is possible for multiple targets to host the same application.
type DNSTargetDiscoverer ¶
type DNSTargetDiscoverer struct { // QueryHost is the hostname that is queried. QueryHost string // NewTargets returns the targets that are discovered based on the addition // of a new network address to the DNS query result. // // addr is the address discovered by the DNS query. It may be a hostname or // an IP address. // // If NewTargets is nil the discoverer constructs a single Target for each // discovered address. The target name is built using the discovered address // as the host and the DefaultGRPCPort constant for the port. NewTargets func(ctx context.Context, addr string) (targets []Target, err error) // LookupHost is the function used to query the host. // // If it is nil, net.DefaultResolver.LookupHost() is used. LookupHost func(ctx context.Context, host string) (addresses []string, err error) // QueryInterval is the interval at which DNS queries are performed. // // If it is non-positive, the DefaultDNSQueryInterval constant is used. QueryInterval time.Duration }
DNSTargetDiscoverer is a TargetDiscoverer that performs a DNS query to discover targets.
It queries a single host and treats each A, AAAA or CNAME record in the result as a distinct target. This is not a DNS-SD implementation.
func (*DNSTargetDiscoverer) DiscoverTargets ¶
func (d *DNSTargetDiscoverer) DiscoverTargets(ctx context.Context, obs TargetObserver) error
DiscoverTargets invokes an observer for each gRPC target that is discovered.
It runs until ctx is canceled or an error occurs.
The context passed to the observer is canceled when the target becomes unavailable or the discover is stopped.
The discoverer MAY block on calls to the observer. It is the observer's responsibility to start new goroutines to handle background tasks, as appropriate.
type Dialer ¶
type Dialer func(context.Context, string, ...grpc.DialOption) (*grpc.ClientConn, error)
Dialer is a function for connecting to gRPC targets.
It matches the signature of grpc.DialContext().
type KubernetesEnvironmentTargetDiscoverer ¶ added in v0.1.2
type KubernetesEnvironmentTargetDiscoverer struct { // PortName is the name (not the number) of the port used to identify a // Dogma target. // // If it is empty, DefaultKubernetesPortName is used. PortName string // DialOptions returns the dial options used to dial the given address. DialOptions func(addr string) []grpc.DialOption }
KubernetesEnvironmentTargetDiscoverer discovers gRPC targets by inspecting the environment for Kubernetes-style environment variables.
func (*KubernetesEnvironmentTargetDiscoverer) DiscoverTargets ¶ added in v0.1.2
func (d *KubernetesEnvironmentTargetDiscoverer) DiscoverTargets( ctx context.Context, obs TargetObserver, ) error
DiscoverTargets invokes an observer for each gRPC target that is discovered.
It runs until ctx is canceled or an error occurs.
The context passed to the observer is canceled when the target becomes unavailable or the discover is stopped.
The discoverer MAY block on calls to the observer. It is the observer's responsibility to start new goroutines to handle background tasks, as appropriate.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an implementation of discoverspec.DiscoverAPIServer.
func (*Server) Unavailable ¶
Unavailable marks the given application as unavailable.
func (*Server) WatchApplications ¶
func (s *Server) WatchApplications( _ *discoverspec.WatchApplicationsRequest, stream discoverspec.DiscoverAPI_WatchApplicationsServer, ) error
WatchApplications starts watching the server for updates to the availability of Dogma applications.
type StaticTargetDiscoverer ¶
type StaticTargetDiscoverer []Target
StaticTargetDiscoverer is a TargetDiscoverer that always "discovers" a fixed set of pre-configured targets.
func (StaticTargetDiscoverer) DiscoverTargets ¶
func (d StaticTargetDiscoverer) DiscoverTargets(ctx context.Context, obs TargetObserver) error
DiscoverTargets invokes an observer for each gRPC target that is discovered.
It runs until ctx is canceled or an error occurs.
The context passed to the observer is canceled when the target becomes unavailable or the discover is stopped.
The discoverer MAY block on calls to the observer. It is the observer's responsibility to start new goroutines to handle background tasks, as appropriate.
type Target ¶
type Target struct { // Name is the target name used to dial the target. // // Typically this is the hostname and port of a single gRPC server but it // may use any of the naming schemes defined in // https://github.com/grpc/grpc/blob/master/doc/naming.md. Name string // DialOptions is a set of grpc.DialOptions used when dialing this target. DialOptions []grpc.DialOption }
Target represents some dialable gRPC target, typically a single gRPC server.
type TargetDiscoverer ¶
type TargetDiscoverer interface { // DiscoverTargets invokes an observer for each gRPC target that is // discovered. // // It runs until ctx is canceled or an error occurs. // // The context passed to the observer is canceled when the target becomes // unavailable or the discover is stopped. // // The discoverer MAY block on calls to the observer. It is the observer's // responsibility to start new goroutines to handle background tasks, as // appropriate. DiscoverTargets(ctx context.Context, obs TargetObserver) error }
TargetDiscoverer is an interface for services that discover gRPC targets.
A "target" is some endpoint that can be dialed using gRPC. It is typically a single gRPC server, but may be anything that can be referred to by a "name" as defined in https://github.com/grpc/grpc/blob/master/doc/naming.md.
type TargetObserver ¶
TargetObserver is a function that handles the discovery of a gRPC target.
ctx is canceled when the target becomes unavailable or the discoverer is stopped. ctx is NOT canceled when the observer function returns and as such may be used by goroutines started by the observer.
The discoverer MAY block on calls to the observer. It is the observer's responsibility to start new goroutines to handle background tasks, as appropriate.