Conversation
7fc1b96 to
7264087
Compare
|
related: #29307 |
dnephin
left a comment
There was a problem hiding this comment.
Will task ids and service ids ever overlap?
Could we just accept all the ids without adding a new flag?
There was a problem hiding this comment.
Could this be passed to getSwarmLogs() with a LogSelector{} param instead of using forms?
There was a problem hiding this comment.
if we leave getSwarmLogs as is, with no LogSelector parameter, then later on a route for arbitrary combinations of service and task logs (for example, maybe stack logs?) can be easily constructed. in fact, on local, i had such a route, that looked somewhat like /swarm/logs?service=foo&service=bar&task=wombo and returned a log stream for whatever selectors.
There was a problem hiding this comment.
(what i mean is getSwarmLogs() can be used verbatim as a handler)
There was a problem hiding this comment.
I think it should still be pretty easy to support such a handler, without having to modify the request parameters in the current implementation.
There was a problem hiding this comment.
Ok, then my second question (for you and anyone else) is where is the best place to put the getSwarmLogs function, if it does not conform to the Handler function type? Can I leave it in the cluster_routes.go file? I believe explicitly should NOT go in the daemon, I think the pattern of having the daemon construct the logs byte stream response is Bad and i'm addressing that in a separate PR.
There was a problem hiding this comment.
Please use github.com/docker/docker/pkg/testutil/cmd to run commands in tests. It helps ensure that we have consistent (and sufficiently detailed) error messages when things fail, and it should be a lot less verbose.
|
I'm not sure the right options for the CLI UI. What I've presented is my best effort as to what I think is correct. Ideally I'd like to support any arbitrary combination of task/service/node logs to reflect what the swarmkit GRPC can do with log selectors. However, that concept DOES NOT map to the existing REST API paradigm, and, by extension, to the CLI. Someone is going to come in here, like the last PR about this, and suggest that we do like filters or whatever and I agree with you but I'm really boxed in by the REST paradigm, which is not conducive to arbitrary selectors like GRPC API is. We'd need an extra API endpoint that does have the format I'm going to alter the CLI to have the pattern |
7264087 to
c2b5057
Compare
|
Fixed the CLI UI. Fixed the tests. |
|
LGTM |
c2b5057 to
0635a57
Compare
|
@dnephin Moved service log handling to a selector as suggested. |
daemon/cluster/services.go
Outdated
daemon/cluster/services.go
Outdated
daemon/cluster/services.go
Outdated
There was a problem hiding this comment.
Same as above as well - we need this check
|
Minor comments, overall LGTM |
0635a57 to
d82ae95
Compare
|
@aluzzardi fixed nits |
vdemeester
left a comment
There was a problem hiding this comment.
SGTM (design wise)
/CC @cpuguy83 @thaJeztah @mlaventure
cli/command/service/logs.go
Outdated
There was a problem hiding this comment.
This comment can go 👼 (and I agree with the change 😛)
cli/command/service/logs.go
Outdated
There was a problem hiding this comment.
Isn't this err un-useful at all ? (and thus the call as well)
@dperny missing an error check here ?
There was a problem hiding this comment.
Yeah I totally dropped an error check, good catch.
There was a problem hiding this comment.
This doesn't look addressed but it has been below. I moved the logs call to after the error check.
d82ae95 to
ea442cf
Compare
|
@vdemeester fixed. |
|
@dperny can you update the documentation ? (at least the API doc to add the endpoint) |
|
I would like to do so but I am unclear on how to go about it. |
|
you need to edit |
ea442cf to
0765e98
Compare
|
updated api/swagger.yml to reflect task logs. The updated API documentation may not be totally correct (it is copied from service logs, which is also not totally correct for pre-existing reasons) and will need to be updated again before service logs are moved out of experimental. |
api/swagger.yaml
Outdated
api/swagger.yaml
Outdated
api/swagger.yaml
Outdated
There was a problem hiding this comment.
i'm correcting it but it's also wrong in the docs for service. i need to, in a separate PR, fix the problems with all the API documentation.
0765e98 to
c5d1179
Compare
vdemeester
left a comment
There was a problem hiding this comment.
LGTM 🐸
/cc @thaJeztah @dnephin
daemon/cluster/services.go
Outdated
There was a problem hiding this comment.
Could this be a new function convertSelector() ? The existing function is already way too long, so if we could avoid adding more code to it, that would be awesome.
There was a problem hiding this comment.
The refactoring in #32154 substantially shortens this function as well, but I'm going to make this change right now anyway.
There was a problem hiding this comment.
result := d.Command(...)
result.Assert(c, icmd.Expected{
Out: "<something you expect to see in stdout>",
})will give much better error messages when there are failures here.
There was a problem hiding this comment.
Doesn't exactly work in this place b/c I'm expecting a service ID, which I can't do a simple string match on. But I understand the gist of what you're saying, I'll fix it.
There was a problem hiding this comment.
I think this could easily pass when you don't expect it to. out is actually Combined(), so any error message would allow this to pass. Using icmd.Expected{Out: ...} is a much stricter assertion.
cli/command/service/logs.go
Outdated
There was a problem hiding this comment.
I believe this will panic in the formatter if passed a task id where the task slot > 9 because strings.Repeat() will be called with a negative number. padding needs to be set to something reasonable for the tasks case.
padding is a bad name for this variable. It should probably be changed to something like maxLength.
There was a problem hiding this comment.
You're right, it does panic. This whole part of the CLI is kind of a mess and I'm going to refactor it later. For now, I'm going to add a check as a bit of a kludge.
There was a problem hiding this comment.
Since you have task in the branch above (returned from TaskInspectWithRaw()), couldn't you set padding to
padding = len(strconv.FormatInt(int64(task.Slot), 10))which would now be duplicated with the formatting below. but could be extracted to a function.
There was a problem hiding this comment.
You're right, I've fixed it correctly.
a01f028 to
0ea9867
Compare
|
@dnephin fixed concerns. |
0ea9867 to
0131057
Compare
|
@dnephin actually fixed all the concerns the right way this time. |
|
@dperny I think the error is legit |
Refactored the API to more easily accept new endpoints. Added REST, client, and CLI endpoints for getting logs from a specific task. All that is needed after this commit to enable arbitrary service log selectors is a REST endpoint and handler. Task logs can be retrieved by putting in a task ID at the CLI instead of a service ID. Signed-off-by: Drew Erny <drew.erny@docker.com>
0131057 to
d330dc3
Compare
|
Forgot to strip a trailing newline, it's fixed now. |
|
LGTM 👍 |
|
ping @dperny erm;
Looks like the Also, can you open a pull request to add a mention of this endpoint to the API changelog; https://github.com/docker/docker/blob/master/docs/api/version-history.md#v129-api-changes ? |
| return err | ||
| } | ||
| maxLength = getMaxLength(task.Slot) | ||
| responseBody, err = cli.TaskLogs(ctx, opts.target, options) |
There was a problem hiding this comment.
Do we have to make this API-version dependent? Or is it ok to have this fail when talking to an older daemon (given that it was "experimental" so far?
There was a problem hiding this comment.
Oh hmmmm I hadn't thought about that...
There was a problem hiding this comment.
I may be mistaken but I BELIEVE if you talk to an older daemon, it's going to fail in the same way it would if I patched this, just with a less helpful error message.
There was a problem hiding this comment.
Well, it's still experimental, so "ok" to break, but what happens with a 17.03 / 17.04 client talking to a 17.05 daemon?
|
@thaJeztah Yes, the |
Thanks! I was confused for a bit, couldn't find the flag LOL |
Add Support for Service Task Logs
This PR probably needs a docs update too. I'm gonna wait until it passes design review before I update the docs
- What I did
Refactored the API to more easily accept new endpoints. Added REST, client, and CLI endpoints for getting logs from a specific task. All that is needed after this commit to enable arbitrary service log selectors is a REST endpoint.
Added a--taskflag todocker service logsto get logs for a specific task.Added search by task if a service wasn't found.
- How I did it
Refactored a bunch of code, added a couple of new endpoints.
- How to verify it
Added a new integration test. You can also try running
docker service logs --task [taskid].- Description for the changelog
docker service logscommand now also gets task logs. Added/task/{id}/logsREST endpoint.- A picture of a cute animal (not mandatory but encouraged)

/cc @aluzzardi