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

feat: support for Edge Functions debugging #4615

Merged
merged 27 commits into from
May 31, 2022

Conversation

jackiewmacharia
Copy link
Contributor

@jackiewmacharia jackiewmacharia commented May 18, 2022

🎉 Thanks for submitting a pull request! 🎉

Summary

Fixes https://github.com/netlify/pillar-runtime/issues/357
Dependent on: netlify/edge-bundler#31

This PR adds flags to run with netlify dev to extend deno --inspect and deno --inspect-brk for Edge Functions debugging. The --edgeInspect and --edgeInspectBrk have the -e and -E flags respectively as aliases. Each can take a custom host and port that defaults to the default HOST:PORT if none is specified.

To test this out, clone feat/debug-edge-functions-flags branch of edge-bundler; run npm install and npm run build in edge-bundler to set it up; edit CLI package.json to use the cloned version of edge-bundler eg "@netlify/edge-bundler": "file:../edge-bundler" and run some of the below examples in an Edge Functions project.

Examples:

  $ netlify dev --edgeInspect
  $ netlify dev --edgeInspect=127.0.0.1:9229
  $ netlify dev --edgeInspectBrk
  $ netlify dev --edgeInspectBrk=127.0.0.1:9229

For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)
cute animal

@github-actions github-actions bot added the type: feature code contributing to the implementation of a feature and/or user facing functionality label May 18, 2022
@github-actions
Copy link

github-actions bot commented May 18, 2022

📊 Benchmark results

Comparing with 64fca17

Package size: 287 MB

(no change)

^  287 MB  287 MB  287 MB  287 MB  287 MB  286 MB  286 MB  286 MB  286 MB  286 MB  286 MB  286 MB  287 MB 
│   ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

@jackiewmacharia jackiewmacharia changed the title feat: add command to debug Edge Functions using a debugger feat: support for Edge Functions debugging May 18, 2022
@jackiewmacharia jackiewmacharia marked this pull request as ready for review May 26, 2022 08:10
@jackiewmacharia jackiewmacharia requested a review from a team May 26, 2022 08:10
@jackiewmacharia jackiewmacharia requested review from a team as code owners May 26, 2022 08:10
Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

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

Left a few comments, but looking great generally! ✨

new Option(
'-E, --edgeInspectBrk [inspectHostPort]',
'enable Deno inspect-brk with optional inspectHostPort',
).conflicts('edgeInspect'),
Copy link
Member

Choose a reason for hiding this comment

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

Nice use of .conflicts()! ✨

const getAddress = () => {
if (edgeInspect) {
// .slice(1) to remove the = in `=127.0.0.1:9229`
return typeof edgeInspect === 'string' ? edgeInspect.slice(1) : undefined
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused as to why you need to slice this. Commander is supposed to handle this automatically for you.

I've just pulled your branch, tried using ntl dev --edgeInspect=127.0.0.1:1234 and ntl dev --edgeInspect 127.0.0.1:1234 and in both cases options.edgeInspect has the right contents, with no need to slice.

Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aha, this was because I was (wrongfully) using the short form that doesn't support the equal sign ending up with edgeInspect: '=127.0.0.1:3030' if ntl dev -e=127.0.0.1:1234 is used.

I've updated the help flag with more examples on how to use the short forms:

'netlify dev -e 127.0.0.1:9229',
'netlify dev -e127.0.0.1:9229',
'netlify dev -E 127.0.0.1:9229',
'netlify dev -E127.0.0.1:9229',

I don't know if this is sufficient though because the error that pops up when -e=127.0.0.1:1234 or -E=127.0.0.1:1234 is ran is what's below from deno. The --help flag suggestion will bring up the above examples though when ran with netlify dev. 🤔

error: Invalid value for '--inspect=<HOST:PORT>...': invalid IP address syntax

For more information try --help

Caused by:
    invalid IP address syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eduardoboucas this one is updated and ready

src/commands/dev/dev.js Outdated Show resolved Hide resolved
src/commands/dev/dev.js Outdated Show resolved Hide resolved
src/commands/dev/dev.js Outdated Show resolved Hide resolved
eduardoboucas
eduardoboucas previously approved these changes May 30, 2022
Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

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

Great work! Left a minor, non-blocking comment.

Comment on lines 579 to 588
'netlify dev -e',
'netlify dev -e 127.0.0.1:9229',
'netlify dev -e127.0.0.1:9229',
'netlify dev --edgeInspect',
'netlify dev --edgeInspect=127.0.0.1:9229',
'netlify dev -E',
'netlify dev -E 127.0.0.1:9229',
'netlify dev -E127.0.0.1:9229',
'netlify dev --edgeInspectBrk',
'netlify dev --edgeInspectBrk=127.0.0.1:9229',
Copy link
Member

Choose a reason for hiding this comment

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

[dust] I don't think we need to add an example for every single permutation, otherwise we'll end up with a huge list in the help command. How do you feel about keeping just the ones below?

Suggested change
'netlify dev -e',
'netlify dev -e 127.0.0.1:9229',
'netlify dev -e127.0.0.1:9229',
'netlify dev --edgeInspect',
'netlify dev --edgeInspect=127.0.0.1:9229',
'netlify dev -E',
'netlify dev -E 127.0.0.1:9229',
'netlify dev -E127.0.0.1:9229',
'netlify dev --edgeInspectBrk',
'netlify dev --edgeInspectBrk=127.0.0.1:9229',
'netlify dev --edgeInspect',
'netlify dev --edgeInspect=127.0.0.1:9229',
'netlify dev --edgeInspectBrk',
'netlify dev --edgeInspectBrk=127.0.0.1:9229',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the short form ones just in case someone uses the = sign with -e or -E and it fails, they see an example of how go use them with the --help flag. This is because something like -e=127.0.0.1:1234 gives us edgeInspect: '=127.0.0.1:3030' because short forms don't support the equal sign causing it to fail.

Copy link
Member

Choose a reason for hiding this comment

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

I understand that, but you could make the same argument for every single parameter we have. The noise of adding every permutation to the help command will make the help command less useful, IMO.

If we're worried that people will misuse the command and get confused about the TypeError: Invalid URL error message (which I agree is not very helpful), we should consider adding validation to the input, so that we throw an error if it's not a valid host/port pair.

Copy link
Member

Choose a reason for hiding this comment

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

You can do this by specifying a custom parser. See https://github.com/tj/commander.js/#custom-option-processing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eduardoboucas this is now done, the review also got reset.

eduardoboucas
eduardoboucas previously approved these changes May 31, 2022
Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

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

Great work! 🚀

@@ -27,6 +27,7 @@ const {
readGraphQLOperationsSourceFile,
} = require('../../lib/one-graph/cli-netlify-graph')
const {
BANG,
Copy link
Member

Choose a reason for hiding this comment

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

💥

src/commands/dev/dev.js Outdated Show resolved Hide resolved
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
@jackiewmacharia jackiewmacharia merged commit 0b1d68d into main May 31, 2022
@jackiewmacharia jackiewmacharia deleted the feat/debug-edge-functions branch May 31, 2022 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants