-
Notifications
You must be signed in to change notification settings - Fork 143
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
pwa-kit-dev command for tailing logs #789
Conversation
Thanks for the contribution! Unfortunately we can't verify the commit author(s): Mahdi Soleimani <m***@s***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, refresh the status of this Pull Request. |
} | ||
}) | ||
.action(async (_, opts) => { | ||
const {project, environment, cloudApiBase, credentialsFile} = opts.optsWithGlobals() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice – I like that optsWithGlobals
makes the order of the args insignificant. Couldn't work out how to do this myself the other day.
There are a set of commands in here for which these "global" flags can never be of interest – basically anything that is not an "MRT Command" (build, lint, etc).
I think that's harmless, but I came up with this mrtCommand
helper here that might be worth thinking about.
The only advantage I can think of with the mrtCommand
approach is that the --cloudURLBase
still appear in the command-specific help. Here's what we see with your approach now:
(venv) ➜ pwa-kit-dev git:(tail-logs) ./bin/pwa-kit-dev.js logs --help
Usage: pwa-kit-dev logs [options]
tail environment logs
Options:
-p, --project <project_slug> the project slug
-e, --environment <environment_slug> the environment slug
-h, --help display help for command
It's a nice-to-have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I like the mrtCommand
idea, I'll take a shot at refactoring the commands to use it (though you've done most of that in your PR :)). I think your point about the global options not appearing for command-specific help is important, cause I also made credentialsFile
global, which means I've taken it out of the push
and save-credentials
help. And the wrapper seems similar to what other people are doing to get around that problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also like the fancy color-coded logs you have there! I wanna give that a try too :)
} | ||
|
||
const token = await scriptUtils.createToken(project, environment, cloudApiBase, credentials.api_key) | ||
const url = new URL(cloudApiBase.replace('cloud', 'logs')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probs want to validate that URL actually looks "cloud-ish" if you're going to replace like that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add validation to the option definition itself 😀
@raiyaj I think what you have here looks excellent. I think there's an open question about If we do I think y'all were discussing showing the What do other tools do? I feel like |
@olibrook Way back we talked about adding the ability to query past logs using the CLI, but since we have no plans to implement it anytime soon, I agree that the
I checked @johnboxall 's point about |
Thanks for the contribution! It looks like @kenjush is an internal user so signing the CLA is not required. However, we need to confirm this. |
@@ -61,7 +61,7 @@ | |||
"babel-plugin-dynamic-import-node-babel-7": "^2.0.7", | |||
"babel-plugin-formatjs": "10.2.20", | |||
"chalk": "^4.1.2", | |||
"commander": "^8.3.0", | |||
"commander": "^9.3.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept this library upgrade from the initial spike. I noticed PWA Kit team's 3PP approval for this lib is only for v2.20.3 (?!), so I'll look into requesting approval for v9.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my approval request: https://gus.lightning.force.com/lightning/r/ADM_Third_Party_Software__c/a0qEE0000005Si1YAE/view
@@ -6,7 +6,7 @@ | |||
"packages": { | |||
"": { | |||
"name": "pwa-kit-dev", | |||
"version": "2.3.0-dev", | |||
"version": "2.4.0-dev", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this is leftover from the recent 2.3.0-dev release.
@@ -184,7 +224,7 @@ const main = () => { | |||
'a message to include along with the uploaded bundle in Managed Runtime' | |||
) | |||
// The default message is loaded dynamically as part of `uploadBundle(...)` | |||
.default(undefined, '<git branch>:<git commit hash>') | |||
.default(null, '<git branch>:<git commit hash>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to null because I noticed that when it's undefined, the default message is not shown in the help output because of this.
beforeEach(() => { | ||
realFail = Utils.fail | ||
Utils.fail.mockImplementation((errorMessage) => { | ||
throw new Error(errorMessage) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At one point a test in this file was failing because we added a new required option to uploadBundle
, and it was tripping me up because the option validation has no effect in the tests unless Utils.fail
throws an error.
managedRuntimeCommand('logs') | ||
.description(`display environment logs (without --tail, displays this help text and exits)`) | ||
.addOption( | ||
new program.Option('-p, --project <projectSlug>', 'the project slug').default( | ||
null, | ||
"the 'name' key from package.json" | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this help text kind of horrendous! Do we have a plan to support pwa-kit-dev logs
without --tail
soon? You know, in the next few months?
I suspect we don't and we'll be looking at this help text in a year thinking "weird, who thought that was a good idea?"!
Can we do one of:
- Rename the command to
tail-logs
. - Remove the
--tail
flag and just tail when you runpwa-kit-dev logs
, the only thing we have planned. - Keep
--tail
, but provide some behaviour forpwa-kit-dev logs
right away? You could show the first page of logs and then exit, for instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you call it tail-logs
I think there's an easy way to build a logs
command in future, while maintaining backwards compatibility with an alias...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'm convinced. I went with option 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢 🚢
Adds the ability to tail logs for deployed Managed Runtime environments!
Description
Types of Changes
Changes
managedRuntimeCommand
helper into the pwa-kit-dev CLI to make sharing common options likecloudOrigin
andcredentialsFile
easier, and use it forpush
andsave-credentials
tail-logs
commandtail-logs
npm script to each template's package.jsoncommander
's major versionHow to Test-Drive This PR
Ensure your production API key is in
~/.mobify
Checkout this branch
If you haven't done so already, install lerna, then run
npm ci
at the root of the repoTail logs! Run
node packages/pwa-kit-dev/bin/pwa-kit-dev.js tail-logs -p <slug> -e <slug>
for an environment in production. Once you generate some traffic on the environment, you should see something like this:Other things to try:
Checklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization