Skip to content

Conversation

@seguins
Copy link

@seguins seguins commented Jan 21, 2016

This PR adds the --follow, --timestamps and --tail options on logs (#2227).

Copy link

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 ?

@dnephin
Copy link

dnephin commented Jan 22, 2016

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.

@seguins seguins force-pushed the 2227-improvements-logs branch from 874e179 to 3e1bbce Compare January 22, 2016 16:29
@seguins
Copy link
Author

seguins commented Jan 22, 2016

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 ?

@j-san
Copy link

j-san commented Jan 25, 2016

+1 for tail

@dnephin dnephin added this to the 1.7.0 milestone Feb 5, 2016
tail = options['--tail']
if tail is not None and tail.isdigit():
tail = int(tail)
log_args['tail'] = tail
Copy link

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.

@dnephin
Copy link

dnephin commented Feb 5, 2016

Thanks! This is looking great. Couple comments around error reporting and testing.


monochrome = options['--no-color']
log_args = {}
log_args['stream'] = options['--follow']
Copy link

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.

Copy link
Author

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 ?

Copy link

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

@seguins seguins force-pushed the 2227-improvements-logs branch from 3e1bbce to 8fd4d3e Compare February 15, 2016 21:04
@seguins
Copy link
Author

seguins commented Feb 15, 2016

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.

@SvenDowideit
Copy link

the documentation checker failure is due to the tutorials repo going private

#2928 will solve that when merged.

@dnephin
Copy link

dnephin commented Feb 26, 2016

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 requirements.txt: For example: git+https://github.com/docker/docker-py.git@81d8caaf36159bf1accd86eab2e157bf8dd071a9#egg=docker-py

@seguins seguins force-pushed the 2227-improvements-logs branch from 8fd4d3e to 5618b07 Compare February 28, 2016 22:20
@seguins
Copy link
Author

seguins commented Feb 28, 2016

I changed the docker-py dependency. Now, we always call the logs api with stream=True.

output=sys.stdout,
monochrome=False,
cascade_stop=False,
log_args={'follow': False}):
Copy link

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 {}
    ...

@dnephin
Copy link

dnephin commented Feb 29, 2016

This is looking good. I'm a little surprised there isn't any changes to def up(). I suspect that it's going to need to pass in follow=True, and it's a bit concerning we don't have any tests failing without it.

monochrome = options['--no-color']
log_args = {}
log_args['follow'] = options['--follow']
log_args['timestamps'] = options['--timestamps']
Copy link

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'],
}

@seguins
Copy link
Author

seguins commented Feb 29, 2016

Thank you for the review. I applied fixes. I removed the part with threading and I rewrite the test_logs_follow test. I'm not sure it's the best way to test this case, but I haven't found better solution.

There is no change on up because it uses the attach api instead of logapi.

@dnephin
Copy link

dnephin commented Feb 29, 2016

There is no change on up because it uses the attach api instead of log api.

up uses LogPrinter, which used to attach, but is now using logs, so I think it's no longer using attach.

@seguins
Copy link
Author

seguins commented Feb 29, 2016

Indeed, I missed it ... Because docker-py has a backward compatibly, up still work.

Should we set explicitly follow=True ?

@dnephin
Copy link

dnephin commented Feb 29, 2016

I think it would be good to set that explicitly, yes

@seguins
Copy link
Author

seguins commented Mar 1, 2016

up uses a convergence_plan. Convergence plan sets should_attach_logs = not detached which has for effect to call attach_log_stream method of container. This method attachs the container and stores the result in log_stream.

LogPrinter checks if log_stream is set and in this case it's not call the logs api. up will not call the log api but the attach api.

However, we need to set follow=True because it's used for displaying the end of process.

Do you think there are enough tests if I just add to the test_up_attached test : assert 'exited with code 0' in stdout ?

@dnephin
Copy link

dnephin commented Mar 1, 2016

I see, you're right it does use attach, I forgot about that. I think it's fine as is.

seguins added 4 commits March 1, 2016 20:23
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>
@seguins seguins force-pushed the 2227-improvements-logs branch from 2bbb779 to 038da4e Compare March 1, 2016 19:57
@seguins
Copy link
Author

seguins commented Mar 1, 2016

I added the follow=True for up. This PR is ready for a new review.

@dnephin
Copy link

dnephin commented Mar 1, 2016

LGTM

@shin-
Copy link

shin- commented Mar 1, 2016

Might be a good idea to rerun the tests on janky? Code looks good overall.

@aanand
Copy link

aanand commented Mar 2, 2016

LGTM

@jayhding
Copy link

@aanand would you mind to comment if this merge will be done also to libcompose, which is used by rancher-compose? Thanks.

@aanand
Copy link

aanand commented Mar 18, 2016

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants