-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: Adds "head" flag to flow-run logs
#8003
Conversation
- If head is provided, the first N logs are returned - Otherwise, all the logs are returned linked to issue PrefectHQ#7998
✅ Deploy Preview for prefect-orion ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
Although @serinamarie 's spec was 50 lines by default, I chose to return all of them as I found it a little more intuitive and convenient for the user. Please let me know if you think otherwise 🙏 |
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.
Hi @ohadch, thanks for jumping on this so quickly!
When you say you return all logs by default when specifying the head
option, I would expect that
prefect flow-run logs <flow_run_id> --head
would then return all logs, rather than running into the error: Option '--head' requires an argument.
Also, I think it's likely that if a user specifies the head
option, it's because they don't want all the logs by default, but I'll defer to @madkinsz on it.
In addition, I wonder if it makes sense to bother with making the creation of logs a fixture at some point.
Hey @serinamarie , Sure 😄 Let's make it perfect. For now I support the following two cases: prefect flow-run logs <uuid> // Returns all logs
prefect flow-run logs <uuid> --head N // Returns the first N logs You would also like the following to work: prefect flow-run logs <uuid> --head // Should return the first 50 logs But unfortunately I can't seem to make it work, because I do not find how to make What do you think? Am I missing something? It is my first time working with |
@serinamarie Also, good idea regarding the fixture. Please have a look at that as well. |
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.
But unfortunately I can't seem to make it work, because I do not find how to make
typer.Option()
support a flag with a default value. I only succeed with declaring either a boolean flag, and then not being able to pass the optional value (aka 50), or declaring an option with a default value, but then not being able to display all logs when the user does not pass the--head
parameter.What do you think? Am I missing something? It is my first time working with
typer
, so maybe I missed something in the docs?
I agree, I don't think it's possible to have a flag support a default value here. We were thinking that an additional number
param with a default of 20 would be an ideal way to ensure that if the head
flag is set, we will receive 20 logs back, unless a user specifies the number themselves.
Example behavior:
prefect flow-run logs <flow_run_id> --head
returns 20 logs
prefect flow-run logs <flow_run_id> --head -n 210
returns 210 logs
Then we can also use the -n
param later on with --tail
😀
Also, the new fixture definitely makes the tests look more succinct! 🙏
- flow-run logs --head -> Returns 50 logs - flow-run logs --head --num-lines 10 -> returns 10 logs
@serinamarie Thanks! This idea makes sense to me as well. I implemented it and used 20 lines for the default head value. |
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.
It's looking good! 😀 One other thing I noticed while testing this is that
prefect flow-run logs <flow_run_id> -n 5
displays all logs but we would like to display the first 5 logs (default sort), e.g. prefect flow-run logs <flow_run_id> -n 5
will display the oldest 5 logs in chronological order.
As another example, in the future with --reverse
, prefect flow-run logs <flow_run_id> --reverse -n 5
would display the 5 most recent logs in reverse (newest first)
Hey @serinamarie , it's a good catch, I wanted to discuss it but you already resolved my concern :) Now |
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.
Hi @ohadch, just a few small things to wrap this one up 🙂 Since a log can be multiple lines, I think --num_logs
or --count
would be a more descriptive long form of the -n
command. Leaning toward num_logs
. Sorry I didn't think on this sooner.
Additionally, I'm not sure we need to test Typer functionality, e.g. testing min=1 in test_when_num_lines_is_smaller_than_one_then_exit_with_error
or the short forms of commands in test_h_and_n_shortcuts_for_head_and_num_lines
. Is there some particular reason for it?
Thanks so much!
Regarding num-logs - I also think so. I thought that -l --limit may be also suitable, what do you think? Regarding the tests - as it is more of an integration compared to a unit test, I do like to test all of the requirements regardless of the implementation method (in this case typer), but I sure can remove it if it is redundant in your opinion :) @serinamarie |
Hey @madkinsz , thanks for reviewing. Apparently this is one of "works on my machine" situations 😅. Not sure what causes it to fail at your end - can you please share the complete test run log? |
@ohadch You should be able to see the full logs in GitHub Actions, can you not? I believe this is do to colored CLI output. @serinamarie and I will look into a fix. |
@madkinsz Sure, missed that. Seems like the coloring is a possible lead. On the other hand, as @serinamarie pointed out earlier, this test might be redundant anyway for this feature. What do you think? |
We disable colors with |
@madkinsz I see the problem. My question is if that is a blocker in your opinion? |
@ohadch Yeah we cannot merge this with failing CI. You can add a pytest skip annotation to that test though and note that we need to disable colors. |
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.
Hi @ohadch Can you skip that test for now?
Co-authored-by: Serina Grill <42048900+serinamarie@users.noreply.github.com>
Hey @serinamarie , committed your suggestion for skipping the test. :) |
Thanks a lot, @ohadch! 🎉 |
…er-builds-consolidation * 'main' of https://github.com/prefecthq/prefect: (34 commits) Minor API docstring formatting fixes, mostly lists (PrefectHQ#8196) Build multi-arch images for releases (PrefectHQ#7901) feat: Adds "head" flag to `flow-run logs` (PrefectHQ#8003) Updates to Automations and Notifications documentation (PrefectHQ#8140) Bump @prefecthq/vue-compositions from 1.2.3 to 1.2.9 in /orion-ui (PrefectHQ#8175) Bump eslint from 8.31.0 to 8.32.0 in /orion-ui (PrefectHQ#8174) Update Postgres tests to use Docker instead of GHA services (PrefectHQ#8125) Update `black` and `isort` versions in pre-commit (PrefectHQ#8167) Chore: Bump orion and prefect design to 1.2.0 (PrefectHQ#8163) Mark `test_process_streams_stderr` as flaky on Python 3.11 (PrefectHQ#8161) Add release notes for 2.7.8 (PrefectHQ#8160) Add some host_config arguments to DockerContainer (PrefectHQ#8033) Skip flaky test `test_dependent_events_in_two_loops_do_not_deadlock` (PrefectHQ#8159) Update jsonschema requirement from <4.0.0,>=3.2.0 to >=3.2.0,<5.0.0 (PrefectHQ#8152) Fix detection of conda installation in test (PrefectHQ#8149) Add `httpx.WriteError` to client retryable exceptions (PrefectHQ#8145) Add documentation for cache refreshes (PrefectHQ#8156) Add YouTube video to welcome page (PrefectHQ#8090) Add social links (PrefectHQ#8088) bump orion-design, release flow run timeline (PrefectHQ#8153) ...
Co-authored-by: ohadchaet <ohad.chaet@lynx.md> Co-authored-by: Michael Adkins <michael@prefect.io> Co-authored-by: Serina Grill <42048900+serinamarie@users.noreply.github.com>
Co-authored-by: ohadchaet <ohad.chaet@lynx.md> Co-authored-by: Michael Adkins <michael@prefect.io> Co-authored-by: Serina Grill <42048900+serinamarie@users.noreply.github.com>
closes #7998
Adds a
--head
flag to theprefect flow-run logs <flow_run_id>
command.Example
Returns
Checklist
<link to issue>
"fix
,feature
,enhancement