-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Add flags on logs #2720
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
Add flags on logs #2720
Conversation
compose/cli/log_printer.py
Outdated
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.
Instead of passing these as individual properties, could we do it as a single dict log_args ?
|
Thanks for this PR! This is looking good, although I'm not sure if we can just change the api call from attach to logs. We'll have to make sure we have reasonable test coverage in this area, and try it out manually. The test failure is unrelated I think. |
874e179 to
3e1bbce
Compare
|
I transformed the logs args as a dictionary. I added some tests, mainly acceptance. I'm sure you would like integration or units tests, but I don't know how to do that because it's mainly api calls ? |
|
+1 for tail |
compose/cli/main.py
Outdated
| tail = options['--tail'] | ||
| if tail is not None and tail.isdigit(): | ||
| tail = int(tail) | ||
| log_args['tail'] = tail |
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.
Small problem here, we should show an error if --tail is invalid instead of just ignoring it.
image_type_from_opt() is a good example for this. It lets you move this if branch into the validation function as well.
|
Thanks! This is looking great. Couple comments around error reporting and testing. |
compose/cli/main.py
Outdated
|
|
||
| monochrome = options['--no-color'] | ||
| log_args = {} | ||
| log_args['stream'] = options['--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.
stream and follow should be different things, however it looks like they were set to the same thing in docker-py. stream should say "return an iterator", where as follow is a behaviour of the API to continue to send logs or stop once it receives the latest one.
I think we need to fix docker-py to have separate params, then this should be:
logs_args['follow'] = ...
stream should always be True.
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 understand the difference between stream and follow, but I'm not sure to understand the advantage of this change.
If you set follow to True, should stream always be True ?
Maybe should we open an issue on docker-py to talk about it before to merge this PR ?
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.
Yes, I think follow=True does imply stream=True, but stream=True doesn't imply follow=True, you may still want to stream without following.
Yes, I created #934
3e1bbce to
8fd4d3e
Compare
|
Thanks for the feedback, I added an error message when the tail parameter is invalid, and I rewrote some tests. I'm waiting for the issue docker/docker-py#934 to finish this PR. |
|
the documentation checker failure is due to the tutorials repo going private #2928 will solve that when merged. |
|
Cool, the docker-py change has been merged and will be in the next release. For now you can use a git url and git sha for the docker-py dependency in |
8fd4d3e to
5618b07
Compare
|
I changed the docker-py dependency. Now, we always call the |
compose/cli/log_printer.py
Outdated
| output=sys.stdout, | ||
| monochrome=False, | ||
| cascade_stop=False, | ||
| log_args={'follow': False}): |
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.
Using a mutable value as a default kwarg value can lead to a lot of confusion.
Instead of this default, please use
def __init__(self, ..., log_args=None):
log_args = log_args or {}
...|
This is looking good. I'm a little surprised there isn't any changes to |
compose/cli/main.py
Outdated
| monochrome = options['--no-color'] | ||
| log_args = {} | ||
| log_args['follow'] = options['--follow'] | ||
| log_args['timestamps'] = options['--timestamps'] |
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.
Minor thing, but this could be a single assignment with a dictionary literal.
log_args = {
'follow': options['--follow'],
'timestamps': options['--timestamps'],
}5618b07 to
2bbb779
Compare
|
Thank you for the review. I applied fixes. I removed the part with threading and I rewrite the There is no change on |
|
|
Indeed, I missed it ... Because docker-py has a backward compatibly, Should we set explicitly |
|
I think it would be good to set that explicitly, yes |
|
However, we need to set Do you think there are enough tests if I just add to the |
|
I see, you're right it does use attach, I forgot about that. I think it's fine as is. |
Closes docker#2187 Signed-off-by: Stéphane Seguin <stephseguin93@gmail.com>
Signed-off-by: Stéphane Seguin <stephseguin93@gmail.com>
Closes docker#265 Signed-off-by: Stéphane Seguin <stephseguin93@gmail.com>
Signed-off-by: Stéphane Seguin <stephseguin93@gmail.com>
2bbb779 to
038da4e
Compare
|
I added the |
|
LGTM |
|
Might be a good idea to rerun the tests on janky? Code looks good overall. |
|
LGTM |
|
@aanand would you mind to comment if this merge will be done also to libcompose, which is used by rancher-compose? Thanks. |
|
@JayHaoDing It will have to be separately implemented. libcompose is not high priority at the moment - we have a Compose release very soon, so that's what we're focusing on. |
This PR adds the --follow, --timestamps and --tail options on logs (#2227).