-
Notifications
You must be signed in to change notification settings - Fork 111
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
[LogStreaming] App logs command #4041
base: main
Are you sure you want to change the base?
Conversation
Thanks for your contribution! Depending on what you are working on, you may want to request a review from a Shopify team:
|
Coverage report
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success1723 tests passing in 800 suites. Report generated by 🧪jest coverage report action from 73001ce |
d976073
to
1586bed
Compare
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.
Mainly just some nits on my end, though I'd want CLI folks to take a look before I put the ✅ since there are some elements in here that look like they should probably be generic 🤔
packages/app/src/cli/services/app-logs/processes/polling-app-logs.ts
Outdated
Show resolved
Hide resolved
packages/app/src/cli/services/app-logs/processes/polling-app-logs.ts
Outdated
Show resolved
Hide resolved
packages/app/src/cli/services/app-logs/processes/polling-app-logs.ts
Outdated
Show resolved
Hide resolved
796cc88
to
68adb58
Compare
ddff241
to
a982bee
Compare
a697f66
to
2b6fef6
Compare
da11633
to
764ab1d
Compare
f4a6cf0
to
d2614e5
Compare
f056e4d
to
0eff461
Compare
logTimestamp: log.log_timestamp, | ||
} | ||
|
||
setAppLogOutputs((prev) => [...prev, {appLog, prefix}]) |
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.
Curious if we need to keep track of every event we've ever seen 🤔 Not urgent but something to explore as a fast-follow
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.
Since we're using React, which is state-based rendering, I suspect that we need to keep an array of all lines that we want to render on the screen.
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.
That's true in the browser, but is it true with ink? Does dev keep track of every line it's ever printed? If not, wouldn't we be able to do something similar?
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.
Might just be a gap in my understanding of ink
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.
FWIW The output component dev (and this) uses does keep the entire output in state -- it doesn't do virtualisation or anything like that
packages/app/src/cli/services/app-logs/logs-command/ui/components/hooks/usePollAppLogs.test.tsx
Show resolved
Hide resolved
We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset. |
packages/app/src/cli/services/app-logs/logs-command/poll-app-logs.test.ts
Outdated
Show resolved
Hide resolved
packages/app/src/cli/services/app-logs/logs-command/poll-app-logs.ts
Outdated
Show resolved
Hide resolved
packages/app/src/cli/services/app-logs/logs-command/poll-app-logs.ts
Outdated
Show resolved
Hide resolved
logTimestamp: log.log_timestamp, | ||
} | ||
|
||
setAppLogOutputs((prev) => [...prev, {appLog, prefix}]) |
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.
Since we're using React, which is state-based rendering, I suspect that we need to keep an array of all lines that we want to render on the screen.
<Text color="green">{prefix.logTimestamp}</Text> | ||
<Text color="blueBright">{`${prefix.source}`}</Text> | ||
<Text color={prefix.status === 'Success' ? 'green' : 'red'}>{prefix.status}</Text> | ||
<Text>in {prefix.fuelConsumed} M instructions</Text> |
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.
❔ Should we keep the prefix generic for other app log types? In this case, should the prefix actually have something like description
(set to the instruction count for Functions) or something that we just blindly output here?
packages/app/src/cli/services/app-logs/logs-command/ui/components/Logs.test.tsx
Outdated
Show resolved
Hide resolved
packages/app/src/cli/services/app-logs/logs-command/ui/components/hooks/usePollAppLogs.ts
Show resolved
Hide resolved
0a7b159
to
d5f09aa
Compare
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.
This is looking better now, but still a few things to pick up. I think Andrew's round of review in particular does need to be actioned before merging.
env: 'SHOPIFY_FLAG_SOURCE', | ||
}), | ||
status: Flags.string({ | ||
description: 'Filters output to the specified status (success or failure).', |
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 these are fixed strings, lets use options
as per the above.
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.
Ah yea, the status will be fixed to success
or failure
, whereas the source is the extension handle. Maybe we could do @nickwesselman?
static descriptionWithMarkdown = `
Opens a real-time stream of detailed log events from the selected app and store.
Use the \`--source\` argument to limit output to a particular function, such as a specific Shopify Function handle.
Use the \`--status\` argument to specify the type of status to retrieve, either \`success\` or \`failure\`.
\`\`\`
shopify app logs --status=success --source=extension-handle
\`\`\`
`
We will update the flags to use the options for status.
packages/app/src/cli/services/app-logs/logs-command/poll-app-logs.test.ts
Outdated
Show resolved
Hide resolved
cursor?: string | ||
errors?: { | ||
status: number | ||
message: string | ||
}[] | ||
appLogs?: AppLogData[] |
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.
+1
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
poll() | ||
}, []) |
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.
Do we need to handle unmount here -- cancelling the timeout?
Part of the LogStreaming Prototype project.
#gsd:39776
Current:
WHY are these changes introduced?
We are adding the
app logs
command. This command is similar to dev, but will stream logging events with full detail. It will not write logs to file. See the Nick's DX doc for more details.Log Output
Error State
WHAT is this pull request doing?
The
<Logs />
component will handle both the polling, and displaying the output.The log and subscribe process are now only responsible for making the requests. This processes are used in the
Logs
component and are results are handling by either adding the log to the output, or displaying the errors.TLDR on the error handling:
If errors are 401 -> we do not update the polling interval, we will re-subscribe. Manage this in the react component by setting the JWT state to null, so the next time it polls, it will re-subscribe first.
If errors are 429 -> update the polling interval to 60 seconds. We also show the error state and a retry in 60 seconds message.
If errors are we update the retry interval to 5 second, and display the error message.
If errors are not handled, they will get thrown. This will cause the terminal to abort.
If there are app logs, they are displayed to the CLI through the
Static
component. This component is also used by dev'sConcurrentOutput
.How to test your changes?
Checkout this branch
Run:
Optionally:
(https://github.com/Shopify/partners/pull/55154 needed)
Post-release steps
Measuring impact
How do we know this change was effective? Please choose one:
Checklist
dev
ordeploy
have been reflected in the internal flowchart.