Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-23.1: roachtest: assign adminui ports dynamically for virtual clusters #117737

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions pkg/cmd/roachtest/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2434,6 +2434,12 @@ func (c *clusterImpl) ExternalAdminUIAddr(
return c.adminUIAddr(ctx, l, node, true)
}

func (c *clusterImpl) AdminUIPorts(
ctx context.Context, l *logger.Logger, nodes option.NodeListOption,
) ([]int, error) {
return roachprod.AdminPorts(ctx, l, c.MakeNodes(nodes), c.IsSecure())
}

func (c *clusterImpl) adminUIAddr(
ctx context.Context, l *logger.Logger, node option.NodeListOption, external bool,
) ([]string, error) {
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 @@ -86,10 +86,11 @@ type Cluster interface {
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)

// URLs for the Admin UI.
// URLs and Ports for the Admin UI.

InternalAdminUIAddr(ctx context.Context, l *logger.Logger, node option.NodeListOption) ([]string, error)
ExternalAdminUIAddr(ctx context.Context, l *logger.Logger, node option.NodeListOption) ([]string, error)
AdminUIPorts(ctx context.Context, l *logger.Logger, node option.NodeListOption) ([]int, error)

// Running commands on nodes.

Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/roachtest/option/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func DefaultStartVirtualClusterOpts(tenantName string, sqlInstance int) StartOpt
startOpts.RoachprodOpts.Target = install.StartServiceForVirtualCluster
startOpts.RoachprodOpts.VirtualClusterName = tenantName
startOpts.RoachprodOpts.SQLInstance = sqlInstance
startOpts.RoachprodOpts.SQLPort = 0
startOpts.RoachprodOpts.AdminUIPort = 0
return startOpts
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/cmd/roachtest/tests/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,18 @@ SELECT count(replicas)
t.L().Printf("killing all nodes\n")
c.Stop(ctx, t.L(), option.DefaultStopOpts())

adminPorts, err := c.AdminUIPorts(ctx, t.L(), c.Node(1))
if err != nil {
t.Fatal(err)
}

// Restart node 1, but have it listen on a different port for internal
// connections. This will require node 1 to reach out to the other nodes in
// the cluster for gossip info.
err := c.RunE(ctx, c.Node(1),
err = c.RunE(ctx, c.Node(1),
` ./cockroach start --insecure --background --store={store-dir} `+
`--log-dir={log-dir} --cache=10% --max-sql-memory=10% `+
`--listen-addr=:$[{pgport:1}+1000] --http-port=$[{pgport:1}+1] `+
fmt.Sprintf(`--listen-addr=:$[{pgport:1}+1000] --http-port=%d `, adminPorts[0])+
`--join={pghost:1}:{pgport:1} `+
`--advertise-addr={pghost:1}:$[{pgport:1}+1000] `+
`> {log-dir}/cockroach.stdout 2> {log-dir}/cockroach.stderr`)
Expand Down
22 changes: 22 additions & 0 deletions pkg/roachprod/roachprod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,28 @@ func AdminURL(
return urlGenerator(ctx, c, l, c.TargetNodes(), uConfig)
}

// AdminPorts finds the AdminUI ports for a cluster.
func AdminPorts(
ctx context.Context, l *logger.Logger, clusterName string, secure bool,
) ([]int, error) {
if err := LoadClusters(); err != nil {
return nil, err
}
c, err := newCluster(l, clusterName, install.SecureOption(secure))
if err != nil {
return nil, err
}
var ports []int
for _, node := range c.Nodes {
port, err := c.NodeUIPort(ctx, node)
if err != nil {
return nil, errors.Wrapf(err, "Error discovering UI Port for node %d", node)
}
ports = append(ports, port)
}
return ports, nil
}

// PprofOpts specifies the options needed by Pprof().
type PprofOpts struct {
Heap bool
Expand Down