Skip to content
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 streaming API for tasks #2773

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

dperny
Copy link
Collaborator

@dperny dperny commented Oct 30, 2018

- What I did

As documented in moby/moby#37997, if there are too many tasks, then attempting to list them all may cause the size of the response to exceed the gRPC max message size.

To avoid this case, introduct a ListTasksStream endpoint, which uses the gRPC streaming API to send tasks as a stream, avoiding exceeding the max message size.

- How I did it

Adds a new RPC to the ControlAPI server called ListTasksStream, which returns tasks as a stream instead of as one giant response.

- How to test it

Includes automated test.

@@ -170,3 +180,43 @@ func (s *Server) ListTasks(ctx context.Context, request *api.ListTasksRequest) (
Tasks: tasks,
}, nil
}

// ListTasksStream is the same as ListTasks, but instead of sending back all
// tasks as one gRPC message, it brakes the messages up into chunks and sends

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: breaks

// slice the first set of tasks off
var theseTasks []*api.Task
theseTasks, tasks = tasks[:maxTasksInResponse], tasks[maxTasksInResponse:]
stream.Send(&api.ListTasksResponse{Tasks: theseTasks})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess stream.Send can return an error, shouldn't it be checked ?

// send, as the last message, an empty list of tasks, if we happen to have
// a number of tasks that aligns to a maxTasksInResponse size. this
// behavior is fine and expected.
stream.Send(&api.ListTasksResponse{Tasks: tasks})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here?

@thaJeztah
Copy link
Member

Given that this changes the API; is this still a candidate for backporting to the 18.09 codebase? (maybe yes, maybe no, just leaving this here as I think of it now 😄 )

@dperny
Copy link
Collaborator Author

dperny commented Oct 30, 2018

@thaJeztah: it actually doesn't change the public API of the docker engine. it changes the swarmkit API, but that API is more-or-less nonpublic, especially as far as the engine is concerned. you'll see in a bit, i'm running tests on the moby/moby branch right now before i push up that pull request.

As documented in moby/moby#37997, if there are too many tasks, then
attempting to list them all may cause the size of the response to exceed
the gRPC max message size.

To avoid this case, introduct a ListTasksStream endpoint, which uses the
gRPC streaming API to send tasks as a stream, avoiding exceeding the max
message size.

Signed-off-by: Drew Erny <drew.erny@docker.com>
Copy link
Contributor

@wk8 wk8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the helpful comments!

@thaJeztah
Copy link
Member

ping @dperny looks like this needs a rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants