Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ca943a6
More test fixes:
Mar 24, 2022
51028f5
Add initial proof-of-concept for custom grpc resolver
Mar 24, 2022
d5622ee
Add Options for passing through cluster-specific configs to Resolvers
Mar 24, 2022
f048c6e
tidy imports
Mar 24, 2022
640a1d3
Better, more structured, logging, beginning vtgate/vtsql support
Mar 24, 2022
b594953
More documentation, plus unexport our resolver implementation
Mar 24, 2022
268d021
More docs
Mar 24, 2022
34e5684
gut WaitForReady
Mar 24, 2022
2879fa2
Add copyright notice
Mar 24, 2022
e609389
Add unit tests for cluster resolver
Mar 24, 2022
e0455c5
Add wrappers to detect ResolveNow calls and remove Sleep from test :t…
Mar 25, 2022
7c597b0
Document improvement ideas. I'll follow-up on these in a second change
Mar 25, 2022
5610bba
Add *Addrs variants of discovery for gates and vtctlds
Mar 25, 2022
bd09cd9
Refactors! Better discoveryFunc abstraction and still update addrs wi…
Mar 26, 2022
7730366
Add debug.Debuggable support for resolvers
Mar 28, 2022
7431402
Use cluster discovery resolver for vtgate/vtsql as well
Mar 28, 2022
39eecaf
Fix tests
Mar 29, 2022
8f296af
remove waitforready-related flag and config
Mar 29, 2022
68386e0
post merge cleanup
Mar 29, 2022
30476f7
The big refactor to enable configurable resolver options
Mar 29, 2022
00c30d0
remove unnecssary discovery call
Mar 29, 2022
b6e838d
remove WithBlock debugging aid
Mar 30, 2022
453c0b5
rename resolver debug fields for consistency
Mar 30, 2022
419bc96
Push discovery down to resolver level, update tests
Mar 30, 2022
2848fe3
annotate resolver span with addrs
Mar 30, 2022
3d858b6
add util function for dial addrs
Mar 30, 2022
acbadfa
Remove .host field as it does not have a use anymore
Mar 30, 2022
b2b9dd9
inline vtsql trace helper
Mar 30, 2022
bee9bc7
Support balancer policies
Mar 30, 2022
c46051e
add link to service config docs
Mar 30, 2022
71fe85b
lol ......
Mar 30, 2022
6efd9d8
add documentation
Mar 30, 2022
3d7ab09
Update code to use new target.URL field (all other fields are depreca…
Apr 4, 2022
f1bc355
Update tests with URL field
Apr 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion go/vt/vtadmin/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"vitess.io/vitess/go/vt/vitessdriver"
"vitess.io/vitess/go/vt/vtadmin/cluster"
"vitess.io/vitess/go/vt/vtadmin/cluster/discovery/fakediscovery"
"vitess.io/vitess/go/vt/vtadmin/cluster/resolver"
vtadminerrors "vitess.io/vitess/go/vt/vtadmin/errors"
"vitess.io/vitess/go/vt/vtadmin/testutil"
"vitess.io/vitess/go/vt/vtadmin/vtctldclient/fakevtctldclient"
Expand Down Expand Up @@ -2652,7 +2653,9 @@ func TestGetTablets(t *testing.T) {
Id: "c1",
Name: "one",
},
Discovery: disco,
ResolverOptions: &resolver.Options{
Discovery: disco,
},
})
db.DialFunc = func(cfg vitessdriver.Configuration) (*sql.DB, error) {
return nil, assert.AnError
Expand Down
8 changes: 8 additions & 0 deletions go/vt/vtadmin/cluster/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ type Discovery interface {
// 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.
Expand All @@ -68,6 +72,10 @@ type Discovery interface {
// 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.
Expand Down
50 changes: 50 additions & 0 deletions go/vt/vtadmin/cluster/discovery/discovery_consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,31 @@ func (c *ConsulDiscovery) DiscoverVTGateAddr(ctx context.Context, tags []string)
return addr, nil
}

// DiscoverVTGateAddrs is part of the Discovery interface.
func (c *ConsulDiscovery) DiscoverVTGateAddrs(ctx context.Context, tags []string) ([]string, error) {
span, ctx := trace.NewSpan(ctx, "ConsulDiscovery.DiscoverVTGateAddrs")
defer span.Finish()

executeFQDNTemplate := false

vtgates, err := c.discoverVTGates(ctx, tags, executeFQDNTemplate)
if err != nil {
return nil, err
}

addrs := make([]string, len(vtgates))
for i, vtgate := range vtgates {
addr, err := textutil.ExecuteTemplate(c.vtgateAddrTmpl, vtgate)
if err != nil {
return nil, fmt.Errorf("failed to execute vtgate address template for %v: %w", vtgate, err)
}

addrs[i] = addr
}

return addrs, nil
}

// DiscoverVTGates is part of the Discovery interface.
func (c *ConsulDiscovery) DiscoverVTGates(ctx context.Context, tags []string) ([]*vtadminpb.VTGate, error) {
span, ctx := trace.NewSpan(ctx, "ConsulDiscovery.DiscoverVTGates")
Expand Down Expand Up @@ -348,6 +373,31 @@ func (c *ConsulDiscovery) DiscoverVtctldAddr(ctx context.Context, tags []string)
return addr, nil
}

// DiscoverVtctldAddrs is part of the Discovery interface.
func (c *ConsulDiscovery) DiscoverVtctldAddrs(ctx context.Context, tags []string) ([]string, error) {
span, ctx := trace.NewSpan(ctx, "ConsulDiscovery.DiscoverVtctldAddrs")
defer span.Finish()

executeFQDNTemplate := false

vtctlds, err := c.discoverVtctlds(ctx, tags, executeFQDNTemplate)
if err != nil {
return nil, err
}

addrs := make([]string, len(vtctlds))
for i, vtctld := range vtctlds {
addr, err := textutil.ExecuteTemplate(c.vtctldAddrTmpl, vtctld)
if err != nil {
return nil, fmt.Errorf("failed to execute vtctld address template for %v: %w", vtctld, err)
}

addrs[i] = addr
}

return addrs, nil
}

// DiscoverVtctlds is part of the Discovery interface.
func (c *ConsulDiscovery) DiscoverVtctlds(ctx context.Context, tags []string) ([]*vtadminpb.Vtctld, error) {
span, ctx := trace.NewSpan(ctx, "ConsulDiscovery.DiscoverVtctlds")
Expand Down
37 changes: 37 additions & 0 deletions go/vt/vtadmin/cluster/discovery/discovery_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"math/rand"

"vitess.io/vitess/go/trace"

vtadminpb "vitess.io/vitess/go/vt/proto/vtadmin"
)

Expand Down Expand Up @@ -146,6 +147,24 @@ func (d *JSONDiscovery) DiscoverVTGateAddr(ctx context.Context, tags []string) (
return gate.Hostname, nil
}

// DiscoverVTGateAddrs is part of the Discovery interface.
func (d *JSONDiscovery) DiscoverVTGateAddrs(ctx context.Context, tags []string) ([]string, error) {
span, ctx := trace.NewSpan(ctx, "JSONDiscovery.DiscoverVTGateAddrs")
defer span.Finish()

gates, err := d.discoverVTGates(ctx, tags)
if err != nil {
return nil, err
}

addrs := make([]string, len(gates))
for i, gate := range gates {
addrs[i] = gate.Hostname
}

return addrs, nil
}

// DiscoverVTGates is part of the Discovery interface.
func (d *JSONDiscovery) DiscoverVTGates(ctx context.Context, tags []string) ([]*vtadminpb.VTGate, error) {
span, ctx := trace.NewSpan(ctx, "JSONDiscovery.DiscoverVTGates")
Expand Down Expand Up @@ -228,6 +247,24 @@ func (d *JSONDiscovery) DiscoverVtctldAddr(ctx context.Context, tags []string) (
return vtctld.Hostname, nil
}

// DiscoverVtctldAddrs is part of the Discovery interface.
func (d *JSONDiscovery) DiscoverVtctldAddrs(ctx context.Context, tags []string) ([]string, error) {
span, ctx := trace.NewSpan(ctx, "JSONDiscovery.DiscoverVtctldAddrs")
defer span.Finish()

vtctlds, err := d.discoverVtctlds(ctx, tags)
if err != nil {
return nil, err
}

addrs := make([]string, len(vtctlds))
for i, vtctld := range vtctlds {
addrs[i] = vtctld.Hostname
}

return addrs, nil
}

// DiscoverVtctlds is part of the Discovery interface.
func (d *JSONDiscovery) DiscoverVtctlds(ctx context.Context, tags []string) ([]*vtadminpb.Vtctld, error) {
span, ctx := trace.NewSpan(ctx, "JSONDiscovery.DiscoverVtctlds")
Expand Down
30 changes: 30 additions & 0 deletions go/vt/vtadmin/cluster/discovery/fakediscovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ func (d *Fake) DiscoverVTGateAddr(ctx context.Context, tags []string) (string, e
return gate.Hostname, nil
}

// DiscoverVTGateAddrs is part of the discovery.Discovery interface.
func (d *Fake) DiscoverVTGateAddrs(ctx context.Context, tags []string) ([]string, error) {
gates, err := d.DiscoverVTGates(ctx, tags)
if err != nil {
return nil, err
}

addrs := make([]string, len(gates))
for i, gate := range gates {
addrs[i] = gate.Hostname
}

return addrs, nil
}

// DiscoverVtctlds is part of the discover.Discovery interface.
func (d *Fake) DiscoverVtctlds(ctx context.Context, tags []string) ([]*vtadminpb.Vtctld, error) {
if d.vtctlds.shouldErr {
Expand Down Expand Up @@ -234,6 +249,21 @@ func (d *Fake) DiscoverVtctldAddr(ctx context.Context, tags []string) (string, e
return vtctld.Hostname, nil
}

// DiscoverVtctldAddrs is part of the discovery.Discovery interface.
func (d *Fake) DiscoverVtctldAddrs(ctx context.Context, tags []string) ([]string, error) {
vtctlds, err := d.DiscoverVtctlds(ctx, tags)
if err != nil {
return nil, err
}

addrs := make([]string, len(vtctlds))
for i, vtctld := range vtctlds {
addrs[i] = vtctld.Hostname
}

return addrs, nil
}

// DiscoverVtctld is part of the discover.Discovery interface.
func (d *Fake) DiscoverVtctld(ctx context.Context, tags []string) (*vtadminpb.Vtctld, error) {
vtctlds, err := d.DiscoverVtctlds(ctx, tags)
Expand Down
Loading