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

TOOLS-2708: Atlas recommended connection string for mongostat doesn't work #314

Merged
merged 5 commits into from
Oct 5, 2020

Conversation

varsha804
Copy link
Contributor

@varsha804 varsha804 commented Sep 15, 2020

The connection string failure seems to be a result of this code change. Since opts.Port and opts.Host are not set when a user only uses --uri, fullhost gets set to localhost:27017, thereby incorrectly rewriting the hostname to localhost.

Manual testing:

  1. Atlas cluster
  2. mlaunch cluster
  3. --discover without a connection string
  4. Connection string as a positional argument without --uri

Screen Shot 2020-09-15 at 2 41 38 PM

mongostat/mongostat.go Show resolved Hide resolved
Copy link
Contributor

@huan-Mongo huan-Mongo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@tfogo tfogo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since opts.Port and opts.Host are not set when a user only uses --uri

I think this is the underlying bug though. What you have works, but I think it's more of a band-aid. I think we should fix the problem in ToolOptions.setOptionsFromURI() instead.

@varsha804
Copy link
Contributor Author

Updated manual testing:
Screen Shot 2020-09-23 at 2 46 08 PM

@@ -596,6 +596,20 @@ func (opts *ToolOptions) setOptionsFromURI(cs connstring.ConnString) error {
return ConflictingArgsErrorFormat("host", strings.Join(cs.Hosts, ","), opts.Host, "--host")
}
}
} else if len(cs.Hosts) > 0 {
hostPort := strings.Split(cs.Hosts[0], ":")
opts.Host = hostPort[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think we have to loop through cs.Hosts and construct a comma separated list of the hosts without ports for opts.Host. Also if cs.ReplicaSet is set, we should prepend <replSet>/ to the list.

It looks like util.CreateConnectionAddrs() expects a comma separated list of hosts so we need to make sure we set it correctly here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't see your question about this on the mtc PR - I'll respond there.

opts.Host = hostPort[0]

// a port might not be specified, e.g. `mongostat --discover`
if len(hostPort) == 2 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good check, we should do this for each of the elements of cs.Hosts.

Copy link
Member

@tfogo tfogo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm once the mtc PR is merged.

Copy link
Contributor

@huan-Mongo huan-Mongo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after revendor

@varsha804 varsha804 merged commit 746360f into master Oct 5, 2020
@varsha804 varsha804 deleted the TOOLS-2708 branch October 5, 2020 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants