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

Added remote mode support #30

Merged
merged 3 commits into from
Mar 2, 2017
Merged

Added remote mode support #30

merged 3 commits into from
Mar 2, 2017

Conversation

utrack
Copy link
Contributor

@utrack utrack commented Jan 22, 2017

This PR adds a possibility to use this tool for instrumented binaries running on remote hosts.

PR adds new protocol command, which dumps running service's binary file. Two dependencies were added, namely github.com/pkg/errors for errors' contexts and github.com/kardianos/osext, which helps agent find the path to executable file.

Interface changes are simple: it is now possible to pass host:port combo instead of PID to gops tool.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@utrack
Copy link
Contributor Author

utrack commented Jan 22, 2017

I signed the CLA.

@googlebot
Copy link

CLAs look good, thanks!

@rakyll
Copy link
Member

rakyll commented Feb 2, 2017

Please no. This tool is designed to work against PID -- that's the sole reason why it exists.

@utrack
Copy link
Contributor Author

utrack commented Feb 2, 2017

@rakyll IDK really, it'd play nicely with current functionality since gops uses TCP socks under the hood (only client's UI limits us to use it remotely).
Besides, currently the tool is useless if instrumented go binary was started by other user - even if you know the agent's real TCP port.

Maybe I should create gops-compatible client for remote use then?

@rakyll
Copy link
Member

rakyll commented Feb 3, 2017

What about accepting host:port along with PIDs?

E.g.

$ gops trace 1234
$ gops trace localhost:6709

@utrack
Copy link
Contributor Author

utrack commented Feb 3, 2017

@rakyll fork does that already :)
This version either accepts PID as before (and resolves it to hostport) or host:port combination. I've covered this in README.md.

@rakyll
Copy link
Member

rakyll commented Feb 6, 2017

Ooops, I looked at the README and saw "target" and assumed it is remote only and breaking the existing behavior. I am going to take a look at the PR very soon!

README.md Outdated
It is possible to use gops tool both in local and remote mode.

Local mode requires that you start the target binary as the same user that runs gops binary.
To use gops in a remote mode you need to know target binary's agent's host and port.
Copy link
Member

Choose a reason for hiding this comment

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

To use gops in remote mode, you need to know target's agent address.

README.md Outdated
@@ -82,31 +89,31 @@ created by github.com/google/gops/agent.Listen
# ...
```

#### $ gops memstats \<pid\>
#### $ gops memstats \<target\>
Copy link
Member

Choose a reason for hiding this comment

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

We should use the one or the other notation:

gops memstats (<pid>|<addr>)

Use for the agent URL.

cmd.go Outdated
)

var cmds = map[string](func(pid int) error){
var cmds = map[string](func(target string) error){
Copy link
Member

Choose a reason for hiding this comment

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

s/target/addr

main.go Outdated
pid, err := strconv.Atoi(os.Args[2])
if err != nil {
usage("PID should be numeric")
usage("missing PID or host:port combo")
Copy link
Member

Choose a reason for hiding this comment

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

missing PID or address

main.go Outdated
}
fn, ok := cmds[cmd]
if !ok {
usage("unknown subcommand")
}
if err := fn(pid); err != nil {
if err := fn(os.Args[2]); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we do the os.Args[2] to addr net.TCPAddr conversion here?

cmd.go Outdated

out, err := cmd(*addr, signal.BinaryDump)
if err != nil {
return errors.New("Couldn't retrieve running binary's dump")
Copy link
Member

Choose a reason for hiding this comment

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

keep error messages lowercase.

@utrack
Copy link
Contributor Author

utrack commented Feb 20, 2017

@rakyll thanks for the CR! Fixed.

@nvcnvn nvcnvn mentioned this pull request Feb 23, 2017
@rakyll rakyll merged commit 288e543 into google:master Mar 2, 2017
@rakyll
Copy link
Member

rakyll commented Mar 2, 2017

Thanks much!!! There are a few minor things but I patch them fix after merging!

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