From e87392b1a643a58a461cebc384f545c23ce153fe Mon Sep 17 00:00:00 2001 From: DarrylWong Date: Mon, 8 Jan 2024 14:39:47 -0500 Subject: [PATCH] roachtest: discover the adminUIPort for acceptance/gossip/restart-node-one This test relies on assumption `adminUIPort = SQLPort + 1` but adminui is temporarily hardcoded as 26258 while SQLPort will be dynamically assigned without the following override. This changes it to discover the port instead of relying on this assumption. Release note: None --- pkg/cmd/roachtest/cluster.go | 6 +++++ .../roachtest/cluster/cluster_interface.go | 3 ++- pkg/cmd/roachtest/option/options.go | 2 +- pkg/cmd/roachtest/tests/gossip.go | 9 ++++++-- pkg/roachprod/roachprod.go | 22 +++++++++++++++++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/roachtest/cluster.go b/pkg/cmd/roachtest/cluster.go index 3da39b2eb454..8330cd992f8a 100644 --- a/pkg/cmd/roachtest/cluster.go +++ b/pkg/cmd/roachtest/cluster.go @@ -2455,6 +2455,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) { diff --git a/pkg/cmd/roachtest/cluster/cluster_interface.go b/pkg/cmd/roachtest/cluster/cluster_interface.go index fb62be728519..f67f88688d11 100644 --- a/pkg/cmd/roachtest/cluster/cluster_interface.go +++ b/pkg/cmd/roachtest/cluster/cluster_interface.go @@ -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. diff --git a/pkg/cmd/roachtest/option/options.go b/pkg/cmd/roachtest/option/options.go index 57d8cafb0f67..bdf1dacac6d2 100644 --- a/pkg/cmd/roachtest/option/options.go +++ b/pkg/cmd/roachtest/option/options.go @@ -53,7 +53,7 @@ func DefaultStartVirtualClusterOpts(tenantName string, sqlInstance int) StartOpt startOpts.RoachprodOpts.Target = install.StartServiceForVirtualCluster startOpts.RoachprodOpts.VirtualClusterName = tenantName startOpts.RoachprodOpts.SQLInstance = sqlInstance - // TODO(DarrylWong): remove once #117125 is addressed. + startOpts.RoachprodOpts.SQLPort = 0 startOpts.RoachprodOpts.AdminUIPort = 0 return startOpts } diff --git a/pkg/cmd/roachtest/tests/gossip.go b/pkg/cmd/roachtest/tests/gossip.go index ea3afd04665a..49ddac1f934a 100644 --- a/pkg/cmd/roachtest/tests/gossip.go +++ b/pkg/cmd/roachtest/tests/gossip.go @@ -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`) diff --git a/pkg/roachprod/roachprod.go b/pkg/roachprod/roachprod.go index 554b6c2c8c89..50b8254fc44c 100644 --- a/pkg/roachprod/roachprod.go +++ b/pkg/roachprod/roachprod.go @@ -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