Documentation ¶
Index ¶
- Variables
- func Register(name string, factory Factory)
- type ConsulClient
- type ConsulDiscovery
- func (c *ConsulDiscovery) DiscoverVTGate(ctx context.Context, tags []string) (*vtadminpb.VTGate, error)
- func (c *ConsulDiscovery) DiscoverVTGateAddr(ctx context.Context, tags []string) (string, error)
- func (c *ConsulDiscovery) DiscoverVTGateAddrs(ctx context.Context, tags []string) ([]string, error)
- func (c *ConsulDiscovery) DiscoverVTGates(ctx context.Context, tags []string) ([]*vtadminpb.VTGate, error)
- func (c *ConsulDiscovery) DiscoverVtctld(ctx context.Context, tags []string) (*vtadminpb.Vtctld, error)
- func (c *ConsulDiscovery) DiscoverVtctldAddr(ctx context.Context, tags []string) (string, error)
- func (c *ConsulDiscovery) DiscoverVtctldAddrs(ctx context.Context, tags []string) ([]string, error)
- func (c *ConsulDiscovery) DiscoverVtctlds(ctx context.Context, tags []string) ([]*vtadminpb.Vtctld, error)
- type ConsulHealth
- type Discovery
- func New(impl string, cluster *vtadminpb.Cluster, args []string) (Discovery, error)
- func NewConsul(cluster *vtadminpb.Cluster, flags *pflag.FlagSet, args []string) (Discovery, error)
- func NewDynamic(cluster *vtadminpb.Cluster, flags *pflag.FlagSet, args []string) (Discovery, error)
- func NewStaticFile(cluster *vtadminpb.Cluster, flags *pflag.FlagSet, args []string) (Discovery, error)
- type DynamicDiscovery
- type Factory
- type JSONClusterConfig
- type JSONDiscovery
- func (d *JSONDiscovery) DiscoverVTGate(ctx context.Context, tags []string) (*vtadminpb.VTGate, error)
- func (d *JSONDiscovery) DiscoverVTGateAddr(ctx context.Context, tags []string) (string, error)
- func (d *JSONDiscovery) DiscoverVTGateAddrs(ctx context.Context, tags []string) ([]string, error)
- func (d *JSONDiscovery) DiscoverVTGates(ctx context.Context, tags []string) ([]*vtadminpb.VTGate, error)
- func (d *JSONDiscovery) DiscoverVtctld(ctx context.Context, tags []string) (*vtadminpb.Vtctld, error)
- func (d *JSONDiscovery) DiscoverVtctldAddr(ctx context.Context, tags []string) (string, error)
- func (d *JSONDiscovery) DiscoverVtctldAddrs(ctx context.Context, tags []string) ([]string, error)
- func (d *JSONDiscovery) DiscoverVtctlds(ctx context.Context, tags []string) ([]*vtadminpb.Vtctld, error)
- type JSONVTGateConfig
- type JSONVtctldConfig
- type StaticFileDiscovery
Constants ¶
This section is empty.
Variables ¶
var ( // ErrImplementationNotRegistered is returned from discovery.New if it is // called with an unknown implementation. ErrImplementationNotRegistered = errors.New("no discovery factory registered for implementation") // ErrNoVTGates should be returned from DiscoverVTGate* methods when they // are unable to find any vtgates for the given filter/query/tags. ErrNoVTGates = errors.New("no vtgates found") // ErrNoVtctlds should be returned from DiscoverVtctld* methods when they // are unable to find any vtctlds for the given filter/query/tags. ErrNoVtctlds = errors.New("no vtctlds found") )
Functions ¶
Types ¶
type ConsulClient ¶
type ConsulClient interface {
Health() ConsulHealth
}
ConsulClient defines an interface for the subset of the consul API used by discovery, so we can swap in an implementation for testing.
type ConsulDiscovery ¶
type ConsulDiscovery struct {
// contains filtered or unexported fields
}
ConsulDiscovery implements the Discovery interface for consul.
func (*ConsulDiscovery) DiscoverVTGate ¶
func (c *ConsulDiscovery) DiscoverVTGate(ctx context.Context, tags []string) (*vtadminpb.VTGate, error)
DiscoverVTGate is part of the Discovery interface.
func (*ConsulDiscovery) DiscoverVTGateAddr ¶
DiscoverVTGateAddr is part of the Discovery interface.
func (*ConsulDiscovery) DiscoverVTGateAddrs ¶ added in v0.14.0
DiscoverVTGateAddrs is part of the Discovery interface.
func (*ConsulDiscovery) DiscoverVTGates ¶
func (c *ConsulDiscovery) DiscoverVTGates(ctx context.Context, tags []string) ([]*vtadminpb.VTGate, error)
DiscoverVTGates is part of the Discovery interface.
func (*ConsulDiscovery) DiscoverVtctld ¶ added in v0.10.0
func (c *ConsulDiscovery) DiscoverVtctld(ctx context.Context, tags []string) (*vtadminpb.Vtctld, error)
DiscoverVtctld is part of the Discovery interface.
func (*ConsulDiscovery) DiscoverVtctldAddr ¶ added in v0.10.0
DiscoverVtctldAddr is part of the Discovery interface.
func (*ConsulDiscovery) DiscoverVtctldAddrs ¶ added in v0.14.0
DiscoverVtctldAddrs is part of the Discovery interface.
func (*ConsulDiscovery) DiscoverVtctlds ¶ added in v0.10.0
func (c *ConsulDiscovery) DiscoverVtctlds(ctx context.Context, tags []string) ([]*vtadminpb.Vtctld, error)
DiscoverVtctlds is part of the Discovery interface.
type ConsulHealth ¶
type ConsulHealth interface {
ServiceMultipleTags(service string, tags []string, passingOnly bool, q *consul.QueryOptions) ([]*consul.ServiceEntry, *consul.QueryMeta, error) // nolint:lll
}
ConsulHealth defines an interface for the subset of the (*consul.Health) struct used by discovery, so we can swap in an implementation for testing.
type Discovery ¶
type Discovery interface { // DiscoverVTGate returns a vtgate found in the discovery service. // Tags can optionally be used to filter the set of potential gates further. // Which gate in a set of found gates is returned is not specified by the // interface, and can be implementation-specific. DiscoverVTGate(ctx context.Context, tags []string) (*vtadminpb.VTGate, error) // DiscoverVTGateAddr returns the address of a of vtgate found in the // discovery service. Tags can optionally be used to filter the set of // potential gates further. Which gate in a set of found gates is used to // return an address is not specified by the interface, and can be // implementation-specific. DiscoverVTGateAddr(ctx context.Context, tags []string) (string, error) // DiscoverVTGateAddrs returns a list of addresses of vtgates found in the // discovery service. This is semantically equivalent to the result of // DiscoverVTGateAddr for each gate returned by a call to DiscoverVTGates. DiscoverVTGateAddrs(ctx context.Context, tags []string) ([]string, error) // DiscoverVTGates returns a list of vtgates found in the discovery service. // Tags can optionally be used to filter gates. Order of the gates is not // specified by the interface, and can be implementation-specific. DiscoverVTGates(ctx context.Context, tags []string) ([]*vtadminpb.VTGate, error) // DiscoverVtctld returns a vtctld found in the discovery service. // Tags can optionally be used to filter the set of potential vtctlds // further. Which vtctld in a set of found vtctlds is returned is not // specified by the interface, and can be implementation-specific. DiscoverVtctld(ctx context.Context, tags []string) (*vtadminpb.Vtctld, error) // DiscoverVtctldAddr returns the address of a vtctld found in the discovery // service. Tags can optionally be used to filter the set of potential // vtctlds further. Which vtctld in a set of potential vtctld is used to // return an address is not specified by the interface, and can be // implementation-specific. DiscoverVtctldAddr(ctx context.Context, tags []string) (string, error) // DiscoverVtctldAddrs returns a list of addresses of vtctlds found in the // discovery service. This is semantically equivalent to the result of // DiscoverVtctldAddr for each gate returned by a call to DiscoverVtctlds. DiscoverVtctldAddrs(ctx context.Context, tags []string) ([]string, error) // DiscoverVtctlds returns a list of vtctlds found in the discovery service. // Tags can optionally be used to filter vtctlds. Order of the vtctlds is // not specified by the interface, and can be implementation-specific. DiscoverVtctlds(ctx context.Context, tags []string) ([]*vtadminpb.Vtctld, error) }
Discovery defines the interface that service discovery plugins must implement. See ConsulDiscovery for an example implementation.
func New ¶
New returns a Discovery implementation using the registered factory for the implementation. Usage of the args slice is dependent on the implementation's factory.
func NewConsul ¶
NewConsul returns a ConsulDiscovery for the given cluster. Args are a slice of command-line flags (e.g. "-key=value") that are parsed by a consul- specific flag set.
func NewDynamic ¶ added in v0.14.0
NewDynamic returns a DynamicDiscovery for the given cluster.
type DynamicDiscovery ¶ added in v0.14.0
type DynamicDiscovery struct {
JSONDiscovery
}
type Factory ¶
type Factory func(cluster *vtadminpb.Cluster, flags *pflag.FlagSet, args []string) (Discovery, error)
Factory represents a function that can create a Discovery implementation. This package will provide several implementations and register them for use. The flags FlagSet is provided for convenience, but also to hint to plugin developers that they should expect the args to be in a format compatible with pflag.
type JSONClusterConfig ¶ added in v0.13.0
type JSONClusterConfig struct { VTGates []*JSONVTGateConfig `json:"vtgates,omitempty"` Vtctlds []*JSONVtctldConfig `json:"vtctlds,omitempty"` }
JSONClusterConfig configures Vitess components for a single cluster.
type JSONDiscovery ¶ added in v0.13.0
type JSONDiscovery struct {
// contains filtered or unexported fields
}
JSONDiscovery implements the Discovery interface for "discovering" Vitess components hardcoded in a json object.
StaticFileDiscovery and DynamicDiscovery inherit from JSONDiscovery because they both read the same JSON object. They only differ in where the JSON object is stored.
As an example, here's a minimal JSON file for a single Vitess cluster running locally (such as the one described in https://vitess.io/docs/get-started/local-docker):
{ "vtgates": [ { "host": { "hostname": "127.0.0.1:15991" } } ] }
For more examples of various static file configurations, see the unit tests.
func (*JSONDiscovery) DiscoverVTGate ¶ added in v0.13.0
func (d *JSONDiscovery) DiscoverVTGate(ctx context.Context, tags []string) (*vtadminpb.VTGate, error)
DiscoverVTGate is part of the Discovery interface.
func (*JSONDiscovery) DiscoverVTGateAddr ¶ added in v0.13.0
DiscoverVTGateAddr is part of the Discovery interface.
func (*JSONDiscovery) DiscoverVTGateAddrs ¶ added in v0.14.0
DiscoverVTGateAddrs is part of the Discovery interface.
func (*JSONDiscovery) DiscoverVTGates ¶ added in v0.13.0
func (d *JSONDiscovery) DiscoverVTGates(ctx context.Context, tags []string) ([]*vtadminpb.VTGate, error)
DiscoverVTGates is part of the Discovery interface.
func (*JSONDiscovery) DiscoverVtctld ¶ added in v0.13.0
func (d *JSONDiscovery) DiscoverVtctld(ctx context.Context, tags []string) (*vtadminpb.Vtctld, error)
DiscoverVtctld is part of the Discovery interface.
func (*JSONDiscovery) DiscoverVtctldAddr ¶ added in v0.13.0
DiscoverVtctldAddr is part of the Discovery interface.
func (*JSONDiscovery) DiscoverVtctldAddrs ¶ added in v0.14.0
DiscoverVtctldAddrs is part of the Discovery interface.
func (*JSONDiscovery) DiscoverVtctlds ¶ added in v0.13.0
func (d *JSONDiscovery) DiscoverVtctlds(ctx context.Context, tags []string) ([]*vtadminpb.Vtctld, error)
DiscoverVtctlds is part of the Discovery interface.
type JSONVTGateConfig ¶ added in v0.13.0
JSONVTGateConfig contains host and tag information for a single VTGate in a cluster.
type JSONVtctldConfig ¶ added in v0.13.0
JSONVtctldConfig contains a host and tag information for a single Vtctld in a cluster.
type StaticFileDiscovery ¶
type StaticFileDiscovery struct {
JSONDiscovery
}
StaticFileDiscovery implements the Discovery interface for "discovering" Vitess components hardcoded in a static JSON file. It inherits from JSONDiscovery.
As an example, here's a minimal JSON file for a single Vitess cluster running locally (such as the one described in https://vitess.io/docs/get-started/local-docker):
{ "vtgates": [ { "host": { "hostname": "127.0.0.1:15991" } } ] }
For more examples of various static file configurations, see the unit tests.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package fakediscovery provides a fake, in-memory discovery implementation.
|
Package fakediscovery provides a fake, in-memory discovery implementation. |