Skip to content

Commit

Permalink
Merge pull request #109335 from herkolategan/backport23.1-109160
Browse files Browse the repository at this point in the history
roachtest: simplify address functions
  • Loading branch information
herkolategan authored Aug 25, 2023
2 parents b151af8 + 825a1f7 commit 3ae559f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 43 deletions.
67 changes: 25 additions & 42 deletions pkg/cmd/roachtest/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2342,40 +2342,29 @@ func addrToHostPort(addr string) (string, int, error) {
// InternalAdminUIAddr returns the internal Admin UI address in the form host:port
// for the specified node.
func (c *clusterImpl) InternalAdminUIAddr(
ctx context.Context, l *logger.Logger, node option.NodeListOption,
_ context.Context, l *logger.Logger, node option.NodeListOption,
) ([]string, error) {
var addrs []string
internalAddrs, err := roachprod.AdminURL(l, c.MakeNodes(node), "", "",
false, false, false)
if err != nil {
return nil, err
}
for _, u := range internalAddrs {
addr, err := urlToAddr(u)
if err != nil {
return nil, err
}
adminUIAddr, err := addrToAdminUIAddr(addr)
if err != nil {
return nil, err
}
addrs = append(addrs, adminUIAddr)
}
return addrs, nil
return c.adminUIAddr(l, node, false)
}

// ExternalAdminUIAddr returns the external Admin UI address in the form host:port
// for the specified node.
func (c *clusterImpl) ExternalAdminUIAddr(
_ context.Context, l *logger.Logger, node option.NodeListOption,
) ([]string, error) {
return c.adminUIAddr(l, node, true)
}

func (c *clusterImpl) adminUIAddr(
l *logger.Logger, node option.NodeListOption, external bool,
) ([]string, error) {
var addrs []string
externalAddrs, err := roachprod.AdminURL(l, c.MakeNodes(node), "", "",
true, false, false)
adminURLs, err := roachprod.AdminURL(l, c.MakeNodes(node), "", "",
external, false, false)
if err != nil {
return nil, err
}
for _, u := range externalAddrs {
for _, u := range adminURLs {
addr, err := urlToAddr(u)
if err != nil {
return nil, err
Expand All @@ -2389,40 +2378,34 @@ func (c *clusterImpl) ExternalAdminUIAddr(
return addrs, nil
}

// InternalAddr returns the internal address in the form host:port for the
// specified nodes.
func (c *clusterImpl) InternalAddr(
// InternalIP returns the internal IP addresses for the specified nodes.
func (c *clusterImpl) InternalIP(
ctx context.Context, l *logger.Logger, node option.NodeListOption,
) ([]string, error) {
var addrs []string
urls, err := c.pgURLErr(ctx, l, node, false, "")
if err != nil {
return nil, err
}
for _, u := range urls {
addr, err := urlToAddr(u)
if err != nil {
return nil, err
}
addrs = append(addrs, addr)
}
return addrs, nil
return roachprod.IP(l, c.MakeNodes(node), false)
}

// InternalIP returns the internal IP addresses for the specified nodes.
func (c *clusterImpl) InternalIP(
// InternalAddr returns the internal address in the form host:port for the
// specified nodes.
func (c *clusterImpl) InternalAddr(
ctx context.Context, l *logger.Logger, node option.NodeListOption,
) ([]string, error) {
return roachprod.IP(l, c.MakeNodes(node), false)
return c.addr(ctx, l, node, false)
}

// ExternalAddr returns the external address in the form host:port for the
// specified node.
func (c *clusterImpl) ExternalAddr(
ctx context.Context, l *logger.Logger, node option.NodeListOption,
) ([]string, error) {
return c.addr(ctx, l, node, true)
}

func (c *clusterImpl) addr(
ctx context.Context, l *logger.Logger, node option.NodeListOption, external bool,
) ([]string, error) {
var addrs []string
urls, err := c.pgURLErr(ctx, l, node, true, "")
urls, err := c.pgURLErr(ctx, l, node, external, "")
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/roachtest/cluster/cluster_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type Cluster interface {
ExternalPGUrl(ctx context.Context, l *logger.Logger, node option.NodeListOption, tenant string) ([]string, error)

// SQL clients to nodes.

Conn(ctx context.Context, l *logger.Logger, node int, opts ...func(*option.ConnOption)) *gosql.DB
ConnE(ctx context.Context, l *logger.Logger, node int, opts ...func(*option.ConnOption)) (*gosql.DB, error)

Expand Down Expand Up @@ -110,7 +111,7 @@ type Cluster interface {
IsLocal() bool
// IsSecure returns true iff the cluster uses TLS.
IsSecure() bool
// Returns CPU architecture of the nodes.
// Architecture returns CPU architecture of the nodes.
Architecture() vm.CPUArch

// Deleting CockroachDB data and logs on nodes.
Expand Down

0 comments on commit 3ae559f

Please sign in to comment.