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

Proposal to add delve debugger commands #20

Merged
merged 3 commits into from Sep 14, 2018
Merged

Proposal to add delve debugger commands #20

merged 3 commits into from Sep 14, 2018

Conversation

rnagle
Copy link
Contributor

@rnagle rnagle commented Sep 13, 2018

Proposed changes:

  • Adds the delve debugger to docker images for api and worker services
  • Sets a liberal security_opt in docker-compose.yml to allow the debugger to function properly
  • Adds some make commands to start delve: make debug-api and make debug-worker

Requested feedback

  • Is this a good idea/would anyone find this useful?

TODO

- [ ] Create and use docker-compose-api-debug.yml (and similar for worker) for a sane way of setting environment variables, volumes and ports EDIT: turns out we don't need this

Change Details

  • Running make debug-api or make debug-worker drops you into a (dlv) prompt where you can set breakpoints, examine function arguments, print the results of an expression, etc (see: delve cli docs)

Try it out:

Run docker-compose build to update your local images with delve. Then:

> make debug-api
docker-compose start db queue worker
Starting queue  ... done
Starting db     ... done
Starting worker ... done
docker-compose run -T --rm -p 3000:3000 -v /Users/ryannagle/go/src/github.com/CMSgov/bcda-app:/go/src/github.com/CMSgov/bcda-app api dlv debug -- start-api
Starting bcda-app_queue_1 ... done
Type 'help' for list of commands.
(dlv)

Then:

(dlv) break main.go:54
Breakpoint 1 set at 0xa1b06d for main.main.func1() ./main.go:54
(dlv) continue
> main.main.func1() ./main.go:54 (hits goroutine(1):1 total:1) (PC: 0xa1b06d)
    49:			{
    50:				Name:  "start-api",
    51:				Usage: "Start the API",
    52:				Action: func(c *cli.Context) error {
    53:					// Worker queue connection
=>  54:					queueDatabaseURL := os.Getenv("QUEUE_DATABASE_URL")
    55:					pgxcfg, err := pgx.ParseURI(queueDatabaseURL)
    56:					if err != nil {
    57:						return err
    58:					}
    59:

Examine arguments:

(dlv) args
c = (*github.com/CMSgov/bcda-app/vendor/github.com/urfave/cli.Context)(0xc4200d86e0)
~r1 = error nil

See local variables:

(dlv) locals
queueDatabaseURL = ""

Evaluate an expression:

(dlv) print c.App.Name
"bcda"

…e commands, set liberal security_opt for api and worker services in docker-compose.yml
@msnook
Copy link
Contributor

msnook commented Sep 13, 2018

Extremely valuable!!

msnook
msnook previously approved these changes Sep 13, 2018
em1
em1 previously approved these changes Sep 13, 2018
Copy link
Contributor

@em1 em1 left a comment

Choose a reason for hiding this comment

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

Great idea!

tbellj
tbellj previously approved these changes Sep 13, 2018
Copy link
Contributor

@tbellj tbellj left a comment

Choose a reason for hiding this comment

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

Soooo helpful!

@rnagle rnagle dismissed stale reviews from tbellj, em1, and msnook via 6748207 September 13, 2018 22:59
msnook
msnook previously approved these changes Sep 14, 2018
Copy link
Contributor

@msnook msnook left a comment

Choose a reason for hiding this comment

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

like it!

@rnagle rnagle merged commit 03c292e into master Sep 14, 2018
@rnagle rnagle deleted the rnagle/dlv branch September 14, 2018 15:55
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.

None yet

4 participants