Skip to content

Commit

Permalink
Merge #46913
Browse files Browse the repository at this point in the history
46913: demo: display connection urls for nodes in the demo cluster r=knz a=rohany

Fixes #46901.

Release note (cli change): cockroach demo now displays a connection
URL to the demo cluster, and in a multi-node cluster it displays
connection strings for all of the nodes in the cluster.

Co-authored-by: Rohan Yadav <[email protected]>
  • Loading branch information
craig[bot] and rohany committed Apr 2, 2020
2 parents 6b4b508 + 18d0231 commit c347574
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
49 changes: 45 additions & 4 deletions pkg/cli/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,12 @@ func setupTransientCluster(
// Prepare the URL for use by the SQL shell.
// TODO (rohany): there should be a way that the user can request a specific node
// to connect to to see the effects of the artificial latency.
c.connURL, err = makeURLForServer(c.s, gen, c.certsDir)
c.connURL, err = makeURLForServer(
c.s,
gen,
c.certsDir,
true, /* includeAppName */
)
if err != nil {
return c, err
}
Expand Down Expand Up @@ -659,7 +664,12 @@ func (c *transientCluster) setupWorkload(
if demoCtx.runWorkload {
var sqlURLs []string
for i := range c.servers {
sqlURL, err := makeURLForServer(c.servers[i], gen, c.certsDir)
sqlURL, err := makeURLForServer(
c.servers[i],
gen,
c.certsDir,
true, /* includeAppName */
)
if err != nil {
return err
}
Expand Down Expand Up @@ -723,7 +733,7 @@ func (c *transientCluster) runWorkload(
}

func makeURLForServer(
s *server.TestServer, gen workload.Generator, certPath string,
s *server.TestServer, gen workload.Generator, certPath string, includeAppName bool,
) (string, error) {
options := url.Values{}
cfg := base.Config{
Expand All @@ -734,7 +744,9 @@ func makeURLForServer(
if err := cfg.LoadSecurityOptions(options, security.RootUser); err != nil {
return "", err
}
options.Add("application_name", sqlbase.ReportableAppNamePrefix+"cockroach demo")
if includeAppName {
options.Add("application_name", sqlbase.ReportableAppNamePrefix+"cockroach demo")
}
sqlURL := url.URL{
Scheme: "postgres",
User: url.User(security.RootUser),
Expand Down Expand Up @@ -969,6 +981,35 @@ func runDemo(cmd *cobra.Command, gen workload.Generator) (err error) {
#
`, c.s.AdminURL())

// Don't include the application name in the URLs we display to users.
if demoCtx.nodes == 1 {
connURL, err := makeURLForServer(
c.servers[0],
gen,
c.certsDir,
false, /* includeAppName */
)
if err != nil {
return checkAndMaybeShout(err)
}
fmt.Printf("# Connect to the cluster on a SQL shell at: '%s'.\n#\n", connURL)
} else {
fmt.Printf("# Connect to different nodes in the cluster on a SQL shell at:\n")
for _, s := range c.servers {
connURL, err := makeURLForServer(
s,
gen,
c.certsDir,
false, /* includeAppName */
)
if err != nil {
return checkAndMaybeShout(err)
}
fmt.Printf("# * Node %d: '%s'\n", s.NodeID(), connURL)
}
fmt.Printf("#\n")
}

if !demoCtx.insecure {
fmt.Printf(
"# The user %q with password %q has been created. Use it to access the Web UI!\n#\n",
Expand Down
25 changes: 25 additions & 0 deletions pkg/cli/interactive_tests/test_demo.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,28 @@ eexpect root@
# Ensure db is movr.
eexpect "movr>"
end_test

# Test that demo displays connection URLs for nodes in the cluster.
start_test "Check that node URLs are displayed"
spawn $argv demo --insecure
# Check that we see our message.
eexpect "Connect to the cluster on a SQL shell at"

# Start the test again with a multi node cluster.
spawn $argv demo --insecure --nodes 3

# Check that we get a message for each node.
eexpect "Connect to different nodes in the cluster on a SQL shell at"
eexpect "Node 1"
eexpect "Node 2"
eexpect "Node 3"

spawn $argv demo --insecure=false
eexpect "Connect to the cluster on a SQL shell at"
# Expect that security related tags are part of the connection URL.
eexpect "sslcert="
eexpect "sslkey="
eexpect "sslrootcert="

end_test

0 comments on commit c347574

Please sign in to comment.