瀏覽代碼

Merge pull request #139 from rumpl/feat-log-stream

Implement gRPC logging
Djordje Lukic 5 年之前
父節點
當前提交
de33f183df

+ 1 - 4
cli/cmd/serve.go

@@ -49,9 +49,7 @@ func runServe(ctx context.Context, opts serveOpts) error {
 	p := proxy.NewContainerAPI()
 
 	containersv1.RegisterContainersServer(s, p)
-	cliv1.RegisterCliServer(s, &cliServer{
-		ctx,
-	})
+	cliv1.RegisterCliServer(s, &cliServer{})
 
 	go func() {
 		<-ctx.Done()
@@ -66,7 +64,6 @@ func runServe(ctx context.Context, opts serveOpts) error {
 }
 
 type cliServer struct {
-	ctx context.Context
 }
 
 func (cs *cliServer) Contexts(ctx context.Context, request *cliv1.ContextsRequest) (*cliv1.ContextsResponse, error) {

+ 273 - 66
containers/v1/containers.pb.go

@@ -1198,6 +1198,108 @@ func (x *ListResponse) GetContainers() []*Container {
 	return nil
 }
 
+type LogsRequest struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	ContainerId string `protobuf:"bytes,1,opt,name=container_id,json=containerId,proto3" json:"container_id,omitempty"`
+	Follow      bool   `protobuf:"varint,2,opt,name=follow,proto3" json:"follow,omitempty"`
+}
+
+func (x *LogsRequest) Reset() {
+	*x = LogsRequest{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_containers_v1_containers_proto_msgTypes[19]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *LogsRequest) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*LogsRequest) ProtoMessage() {}
+
+func (x *LogsRequest) ProtoReflect() protoreflect.Message {
+	mi := &file_containers_v1_containers_proto_msgTypes[19]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use LogsRequest.ProtoReflect.Descriptor instead.
+func (*LogsRequest) Descriptor() ([]byte, []int) {
+	return file_containers_v1_containers_proto_rawDescGZIP(), []int{19}
+}
+
+func (x *LogsRequest) GetContainerId() string {
+	if x != nil {
+		return x.ContainerId
+	}
+	return ""
+}
+
+func (x *LogsRequest) GetFollow() bool {
+	if x != nil {
+		return x.Follow
+	}
+	return false
+}
+
+type LogsResponse struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	Logs []byte `protobuf:"bytes,1,opt,name=logs,proto3" json:"logs,omitempty"`
+}
+
+func (x *LogsResponse) Reset() {
+	*x = LogsResponse{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_containers_v1_containers_proto_msgTypes[20]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *LogsResponse) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*LogsResponse) ProtoMessage() {}
+
+func (x *LogsResponse) ProtoReflect() protoreflect.Message {
+	mi := &file_containers_v1_containers_proto_msgTypes[20]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use LogsResponse.ProtoReflect.Descriptor instead.
+func (*LogsResponse) Descriptor() ([]byte, []int) {
+	return file_containers_v1_containers_proto_rawDescGZIP(), []int{20}
+}
+
+func (x *LogsResponse) GetLogs() []byte {
+	if x != nil {
+		return x.Logs
+	}
+	return nil
+}
+
 var File_containers_v1_containers_proto protoreflect.FileDescriptor
 
 var file_containers_v1_containers_proto_rawDesc = []byte{
@@ -1316,60 +1418,73 @@ var file_containers_v1_containers_proto_rawDesc = []byte{
 	0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b,
 	0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72,
 	0x73, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x52, 0x0a,
-	0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x32, 0x99, 0x06, 0x0a, 0x0a, 0x43,
-	0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x12, 0x5d, 0x0a, 0x04, 0x4c, 0x69, 0x73,
-	0x74, 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61,
-	0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31,
-	0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63,
-	0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f,
-	0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74,
-	0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x63, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61,
-	0x74, 0x65, 0x12, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e,
-	0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76,
-	0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
-	0x2c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69,
-	0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x43,
-	0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x60, 0x0a,
-	0x05, 0x53, 0x74, 0x61, 0x72, 0x74, 0x12, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63,
-	0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65,
-	0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x61, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65,
-	0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e,
-	0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76,
-	0x31, 0x2e, 0x53, 0x74, 0x61, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
-	0x5d, 0x0a, 0x04, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f,
-	0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e,
-	0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x6f, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65,
-	0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e,
+	0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x22, 0x48, 0x0a, 0x0b, 0x4c, 0x6f,
+	0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e,
+	0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
+	0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06,
+	0x66, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x66, 0x6f,
+	0x6c, 0x6c, 0x6f, 0x77, 0x22, 0x22, 0x0a, 0x0c, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70,
+	0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x6f, 0x67, 0x73, 0x18, 0x01, 0x20, 0x01,
+	0x28, 0x0c, 0x52, 0x04, 0x6c, 0x6f, 0x67, 0x73, 0x32, 0xfa, 0x06, 0x0a, 0x0a, 0x43, 0x6f, 0x6e,
+	0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x12, 0x5d, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12,
+	0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69,
+	0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c,
+	0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d,
+	0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74,
+	0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65,
+	0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x63, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
+	0x12, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70,
+	0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e,
+	0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e,
+	0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63,
+	0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65,
+	0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x60, 0x0a, 0x05, 0x53,
+	0x74, 0x61, 0x72, 0x74, 0x12, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65,
+	0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73,
+	0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x61, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
+	0x1a, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70,
+	0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e,
+	0x53, 0x74, 0x61, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5d, 0x0a,
+	0x04, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b,
+	0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72,
+	0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x6f, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
+	0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70,
+	0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e,
+	0x53, 0x74, 0x6f, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5d, 0x0a, 0x04,
+	0x4b, 0x69, 0x6c, 0x6c, 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65,
+	0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73,
+	0x2e, 0x76, 0x31, 0x2e, 0x4b, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
+	0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69,
+	0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4b,
+	0x69, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x63, 0x0a, 0x06, 0x44,
+	0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b,
+	0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72,
+	0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65,
+	0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e,
 	0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76,
-	0x31, 0x2e, 0x53, 0x74, 0x6f, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5d,
-	0x0a, 0x04, 0x4b, 0x69, 0x6c, 0x6c, 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63,
-	0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65,
-	0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4b, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
-	0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61,
-	0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31,
-	0x2e, 0x4b, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x63, 0x0a,
-	0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f,
+	0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
+	0x12, 0x63, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x2b, 0x2e, 0x63, 0x6f, 0x6d,
+	0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74,
+	0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65,
+	0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f,
 	0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e,
-	0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71,
-	0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65,
-	0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73,
-	0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
-	0x73, 0x65, 0x12, 0x63, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x2b, 0x2e, 0x63,
+	0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73,
+	0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5d, 0x0a, 0x04, 0x45, 0x78, 0x65, 0x63, 0x12, 0x29, 0x2e,
+	0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63,
+	0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x65,
+	0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64,
+	0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69,
+	0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x52, 0x65, 0x73, 0x70,
+	0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5f, 0x0a, 0x04, 0x4c, 0x6f, 0x67, 0x73, 0x12, 0x29, 0x2e, 0x63,
 	0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f,
-	0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61,
-	0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e,
-	0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61,
-	0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52,
-	0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5d, 0x0a, 0x04, 0x45, 0x78, 0x65, 0x63, 0x12,
-	0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69,
-	0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x45,
-	0x78, 0x65, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d,
-	0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74,
-	0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x52, 0x65,
-	0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x28, 0x5a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62,
-	0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f,
-	0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31,
-	0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x6f, 0x67, 0x73,
+	0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f,
+	0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e,
+	0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f,
+	0x6e, 0x73, 0x65, 0x30, 0x01, 0x42, 0x28, 0x5a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
+	0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63,
+	0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62,
+	0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -1384,7 +1499,7 @@ func file_containers_v1_containers_proto_rawDescGZIP() []byte {
 	return file_containers_v1_containers_proto_rawDescData
 }
 
-var file_containers_v1_containers_proto_msgTypes = make([]protoimpl.MessageInfo, 20)
+var file_containers_v1_containers_proto_msgTypes = make([]protoimpl.MessageInfo, 22)
 var file_containers_v1_containers_proto_goTypes = []interface{}{
 	(*Port)(nil),           // 0: com.docker.api.containers.v1.Port
 	(*Container)(nil),      // 1: com.docker.api.containers.v1.Container
@@ -1405,12 +1520,14 @@ var file_containers_v1_containers_proto_goTypes = []interface{}{
 	(*KillResponse)(nil),   // 16: com.docker.api.containers.v1.KillResponse
 	(*ListRequest)(nil),    // 17: com.docker.api.containers.v1.ListRequest
 	(*ListResponse)(nil),   // 18: com.docker.api.containers.v1.ListResponse
-	nil,                    // 19: com.docker.api.containers.v1.CreateRequest.LabelsEntry
+	(*LogsRequest)(nil),    // 19: com.docker.api.containers.v1.LogsRequest
+	(*LogsResponse)(nil),   // 20: com.docker.api.containers.v1.LogsResponse
+	nil,                    // 21: com.docker.api.containers.v1.CreateRequest.LabelsEntry
 }
 var file_containers_v1_containers_proto_depIdxs = []int32{
 	0,  // 0: com.docker.api.containers.v1.Container.ports:type_name -> com.docker.api.containers.v1.Port
 	3,  // 1: com.docker.api.containers.v1.CreateRequest.mounts:type_name -> com.docker.api.containers.v1.Mount
-	19, // 2: com.docker.api.containers.v1.CreateRequest.labels:type_name -> com.docker.api.containers.v1.CreateRequest.LabelsEntry
+	21, // 2: com.docker.api.containers.v1.CreateRequest.labels:type_name -> com.docker.api.containers.v1.CreateRequest.LabelsEntry
 	1,  // 3: com.docker.api.containers.v1.ListResponse.containers:type_name -> com.docker.api.containers.v1.Container
 	17, // 4: com.docker.api.containers.v1.Containers.List:input_type -> com.docker.api.containers.v1.ListRequest
 	2,  // 5: com.docker.api.containers.v1.Containers.Create:input_type -> com.docker.api.containers.v1.CreateRequest
@@ -1420,16 +1537,18 @@ var file_containers_v1_containers_proto_depIdxs = []int32{
 	7,  // 9: com.docker.api.containers.v1.Containers.Delete:input_type -> com.docker.api.containers.v1.DeleteRequest
 	5,  // 10: com.docker.api.containers.v1.Containers.Update:input_type -> com.docker.api.containers.v1.UpdateRequest
 	13, // 11: com.docker.api.containers.v1.Containers.Exec:input_type -> com.docker.api.containers.v1.ExecRequest
-	18, // 12: com.docker.api.containers.v1.Containers.List:output_type -> com.docker.api.containers.v1.ListResponse
-	4,  // 13: com.docker.api.containers.v1.Containers.Create:output_type -> com.docker.api.containers.v1.CreateResponse
-	10, // 14: com.docker.api.containers.v1.Containers.Start:output_type -> com.docker.api.containers.v1.StartResponse
-	12, // 15: com.docker.api.containers.v1.Containers.Stop:output_type -> com.docker.api.containers.v1.StopResponse
-	16, // 16: com.docker.api.containers.v1.Containers.Kill:output_type -> com.docker.api.containers.v1.KillResponse
-	8,  // 17: com.docker.api.containers.v1.Containers.Delete:output_type -> com.docker.api.containers.v1.DeleteResponse
-	6,  // 18: com.docker.api.containers.v1.Containers.Update:output_type -> com.docker.api.containers.v1.UpdateResponse
-	14, // 19: com.docker.api.containers.v1.Containers.Exec:output_type -> com.docker.api.containers.v1.ExecResponse
-	12, // [12:20] is the sub-list for method output_type
-	4,  // [4:12] is the sub-list for method input_type
+	19, // 12: com.docker.api.containers.v1.Containers.Logs:input_type -> com.docker.api.containers.v1.LogsRequest
+	18, // 13: com.docker.api.containers.v1.Containers.List:output_type -> com.docker.api.containers.v1.ListResponse
+	4,  // 14: com.docker.api.containers.v1.Containers.Create:output_type -> com.docker.api.containers.v1.CreateResponse
+	10, // 15: com.docker.api.containers.v1.Containers.Start:output_type -> com.docker.api.containers.v1.StartResponse
+	12, // 16: com.docker.api.containers.v1.Containers.Stop:output_type -> com.docker.api.containers.v1.StopResponse
+	16, // 17: com.docker.api.containers.v1.Containers.Kill:output_type -> com.docker.api.containers.v1.KillResponse
+	8,  // 18: com.docker.api.containers.v1.Containers.Delete:output_type -> com.docker.api.containers.v1.DeleteResponse
+	6,  // 19: com.docker.api.containers.v1.Containers.Update:output_type -> com.docker.api.containers.v1.UpdateResponse
+	14, // 20: com.docker.api.containers.v1.Containers.Exec:output_type -> com.docker.api.containers.v1.ExecResponse
+	20, // 21: com.docker.api.containers.v1.Containers.Logs:output_type -> com.docker.api.containers.v1.LogsResponse
+	13, // [13:22] is the sub-list for method output_type
+	4,  // [4:13] is the sub-list for method input_type
 	4,  // [4:4] is the sub-list for extension type_name
 	4,  // [4:4] is the sub-list for extension extendee
 	0,  // [0:4] is the sub-list for field type_name
@@ -1669,6 +1788,30 @@ func file_containers_v1_containers_proto_init() {
 				return nil
 			}
 		}
+		file_containers_v1_containers_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*LogsRequest); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_containers_v1_containers_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*LogsResponse); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
 	}
 	type x struct{}
 	out := protoimpl.TypeBuilder{
@@ -1676,7 +1819,7 @@ func file_containers_v1_containers_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: file_containers_v1_containers_proto_rawDesc,
 			NumEnums:      0,
-			NumMessages:   20,
+			NumMessages:   22,
 			NumExtensions: 0,
 			NumServices:   1,
 		},
@@ -1710,6 +1853,7 @@ type ContainersClient interface {
 	Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error)
 	Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error)
 	Exec(ctx context.Context, in *ExecRequest, opts ...grpc.CallOption) (*ExecResponse, error)
+	Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Containers_LogsClient, error)
 }
 
 type containersClient struct {
@@ -1792,6 +1936,38 @@ func (c *containersClient) Exec(ctx context.Context, in *ExecRequest, opts ...gr
 	return out, nil
 }
 
+func (c *containersClient) Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Containers_LogsClient, error) {
+	stream, err := c.cc.NewStream(ctx, &_Containers_serviceDesc.Streams[0], "/com.docker.api.containers.v1.Containers/Logs", opts...)
+	if err != nil {
+		return nil, err
+	}
+	x := &containersLogsClient{stream}
+	if err := x.ClientStream.SendMsg(in); err != nil {
+		return nil, err
+	}
+	if err := x.ClientStream.CloseSend(); err != nil {
+		return nil, err
+	}
+	return x, nil
+}
+
+type Containers_LogsClient interface {
+	Recv() (*LogsResponse, error)
+	grpc.ClientStream
+}
+
+type containersLogsClient struct {
+	grpc.ClientStream
+}
+
+func (x *containersLogsClient) Recv() (*LogsResponse, error) {
+	m := new(LogsResponse)
+	if err := x.ClientStream.RecvMsg(m); err != nil {
+		return nil, err
+	}
+	return m, nil
+}
+
 // ContainersServer is the server API for Containers service.
 type ContainersServer interface {
 	List(context.Context, *ListRequest) (*ListResponse, error)
@@ -1802,6 +1978,7 @@ type ContainersServer interface {
 	Delete(context.Context, *DeleteRequest) (*DeleteResponse, error)
 	Update(context.Context, *UpdateRequest) (*UpdateResponse, error)
 	Exec(context.Context, *ExecRequest) (*ExecResponse, error)
+	Logs(*LogsRequest, Containers_LogsServer) error
 }
 
 // UnimplementedContainersServer can be embedded to have forward compatible implementations.
@@ -1832,6 +2009,9 @@ func (*UnimplementedContainersServer) Update(context.Context, *UpdateRequest) (*
 func (*UnimplementedContainersServer) Exec(context.Context, *ExecRequest) (*ExecResponse, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method Exec not implemented")
 }
+func (*UnimplementedContainersServer) Logs(*LogsRequest, Containers_LogsServer) error {
+	return status.Errorf(codes.Unimplemented, "method Logs not implemented")
+}
 
 func RegisterContainersServer(s *grpc.Server, srv ContainersServer) {
 	s.RegisterService(&_Containers_serviceDesc, srv)
@@ -1981,6 +2161,27 @@ func _Containers_Exec_Handler(srv interface{}, ctx context.Context, dec func(int
 	return interceptor(ctx, in, info, handler)
 }
 
+func _Containers_Logs_Handler(srv interface{}, stream grpc.ServerStream) error {
+	m := new(LogsRequest)
+	if err := stream.RecvMsg(m); err != nil {
+		return err
+	}
+	return srv.(ContainersServer).Logs(m, &containersLogsServer{stream})
+}
+
+type Containers_LogsServer interface {
+	Send(*LogsResponse) error
+	grpc.ServerStream
+}
+
+type containersLogsServer struct {
+	grpc.ServerStream
+}
+
+func (x *containersLogsServer) Send(m *LogsResponse) error {
+	return x.ServerStream.SendMsg(m)
+}
+
 var _Containers_serviceDesc = grpc.ServiceDesc{
 	ServiceName: "com.docker.api.containers.v1.Containers",
 	HandlerType: (*ContainersServer)(nil),
@@ -2018,6 +2219,12 @@ var _Containers_serviceDesc = grpc.ServiceDesc{
 			Handler:    _Containers_Exec_Handler,
 		},
 	},
-	Streams:  []grpc.StreamDesc{},
+	Streams: []grpc.StreamDesc{
+		{
+			StreamName:    "Logs",
+			Handler:       _Containers_Logs_Handler,
+			ServerStreams: true,
+		},
+	},
 	Metadata: "containers/v1/containers.proto",
 }

+ 10 - 0
containers/v1/containers.proto

@@ -40,6 +40,7 @@ service Containers {
 	rpc Delete(DeleteRequest) returns (DeleteResponse);
 	rpc Update(UpdateRequest) returns (UpdateResponse);
 	rpc Exec(ExecRequest) returns (ExecResponse);
+	rpc Logs(LogsRequest) returns (stream LogsResponse);
 }
 
 message Port {
@@ -154,3 +155,12 @@ message ListRequest {
 message ListResponse {
 	repeated Container containers = 1;
 }
+
+message LogsRequest {
+	string container_id = 1;
+	bool follow = 2;
+}
+
+message LogsResponse {
+	bytes logs = 1;
+}

+ 2 - 2
go.mod

@@ -23,7 +23,7 @@ require (
 	github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee // indirect
 	github.com/gobwas/pool v0.2.0 // indirect
 	github.com/gobwas/ws v1.0.3
-	github.com/golang/protobuf v1.4.0
+	github.com/golang/protobuf v1.4.1
 	github.com/gorilla/mux v1.7.4 // indirect
 	github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
 	github.com/hashicorp/go-multierror v1.1.0
@@ -43,7 +43,7 @@ require (
 	golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect
 	golang.org/x/text v0.3.2 // indirect
 	google.golang.org/grpc v1.29.1
-	google.golang.org/protobuf v1.21.0
+	google.golang.org/protobuf v1.22.0
 	gotest.tools v2.2.0+incompatible
 	gotest.tools/v3 v3.0.2
 )

+ 4 - 0
go.sum

@@ -117,6 +117,8 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
 github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
 github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ=
 github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
+github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
+github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
 github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
 github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
@@ -339,6 +341,8 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ
 google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
 google.golang.org/protobuf v1.21.0 h1:qdOKuR/EIArgaWNjetjgTzgVTAZ+S/WXVrq9HW9zimw=
 google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
+google.golang.org/protobuf v1.22.0 h1:cJv5/xdbk1NnMPR1VP9+HU6gupuG9MLBoH1r6RHZ2MY=
+google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

+ 1 - 0
moby/backend.go

@@ -143,6 +143,7 @@ func (ms *mobyService) Logs(ctx context.Context, containerName string, request c
 	r, err := ms.apiClient.ContainerLogs(ctx, containerName, types.ContainerLogsOptions{
 		ShowStdout: true,
 		ShowStderr: true,
+		Follow:     request.Follow,
 	})
 	if err != nil {
 		return err

+ 10 - 0
server/proxy/containers.go

@@ -101,3 +101,13 @@ func (p *proxyContainerAPI) Update(_ context.Context, _ *v1.UpdateRequest) (*v1.
 func (p *proxyContainerAPI) Exec(_ context.Context, _ *v1.ExecRequest) (*v1.ExecResponse, error) {
 	panic("not implemented") // TODO: Implement
 }
+
+func (p *proxyContainerAPI) Logs(request *v1.LogsRequest, stream v1.Containers_LogsServer) error {
+	ctx := stream.Context()
+	c := Client(ctx)
+
+	return c.ContainerService().Logs(ctx, request.GetContainerId(), containers.LogsRequest{
+		Follow: request.Follow,
+		Writer: &streamWriter{stream},
+	})
+}

+ 23 - 0
server/proxy/streamwriter.go

@@ -0,0 +1,23 @@
+package proxy
+
+import (
+	"io"
+
+	v1 "github.com/docker/api/containers/v1"
+)
+
+type streamWriter struct {
+	stream v1.Containers_LogsServer
+}
+
+func newStreamWriter(stream v1.Containers_LogsServer) io.Writer {
+	return &streamWriter{
+		stream: stream,
+	}
+}
+
+func (w *streamWriter) Write(p []byte) (n int, err error) {
+	return len(p), w.stream.Send(&v1.LogsResponse{
+		Logs: p,
+	})
+}

+ 55 - 0
server/proxy/streamwriter_test.go

@@ -0,0 +1,55 @@
+package proxy
+
+import (
+	"context"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"google.golang.org/grpc/metadata"
+
+	v1 "github.com/docker/api/containers/v1"
+)
+
+type logServer struct {
+	logs []byte
+}
+
+func (ls *logServer) Send(response *v1.LogsResponse) error {
+	ls.logs = response.Logs
+	return nil
+}
+
+func (ls *logServer) SetHeader(metadata.MD) error {
+	return nil
+}
+
+func (ls *logServer) SendHeader(metadata.MD) error {
+	return nil
+}
+
+func (ls *logServer) SetTrailer(metadata.MD) {
+}
+
+func (ls *logServer) Context() context.Context {
+	return nil
+}
+
+func (ls *logServer) SendMsg(m interface{}) error {
+	return nil
+}
+
+func (ls *logServer) RecvMsg(m interface{}) error {
+	return nil
+}
+
+func TestStreamWriter(t *testing.T) {
+	ls := &logServer{}
+	sw := newStreamWriter(ls)
+	in := []byte{104, 101, 108, 108, 111}
+
+	l, err := sw.Write(in)
+
+	assert.Nil(t, err)
+	assert.Equal(t, len(in), l)
+	assert.Equal(t, in, ls.logs)
+}

+ 103 - 23
server/server.go

@@ -48,10 +48,13 @@ import (
 func New(ctx context.Context) *grpc.Server {
 	s := grpc.NewServer(
 		grpc.ChainUnaryInterceptor(
-			unaryMeta(ctx),
+			unaryServerInterceptor(ctx),
 			unary,
 		),
-		grpc.StreamInterceptor(stream),
+		grpc.ChainStreamInterceptor(
+			grpc.StreamServerInterceptor(stream),
+			grpc.StreamServerInterceptor(streamServerInterceptor(ctx)),
+		),
 	)
 	hs := health.NewServer()
 	grpc_health_v1.RegisterHealthServer(s, hs)
@@ -74,34 +77,111 @@ func stream(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo,
 	return grpc_prometheus.StreamServerInterceptor(srv, ss, info, handler)
 }
 
-func unaryMeta(clictx context.Context) func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+// unaryServerInterceptor configures the context and sends it to the next handler
+func unaryServerInterceptor(clictx context.Context) func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
 	return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
-		md, ok := metadata.FromIncomingContext(ctx)
-		if !ok {
-			return handler(ctx, req)
+		currentContext := getContext(ctx)
+		configuredCtx, err := configureContext(clictx, currentContext)
+		if err != nil {
+			return nil, err
 		}
 
-		key, ok := md[apicontext.Key]
-		if !ok {
-			return handler(ctx, req)
+		return handler(configuredCtx, req)
+	}
+}
+
+// streamServerInterceptor configures the context and sends it to the next handler
+func streamServerInterceptor(clictx context.Context) func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
+	return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
+		currentContext := getContext(ss.Context())
+		ctx, err := configureContext(clictx, currentContext)
+		if err != nil {
+			return err
 		}
 
-		if len(key) == 1 {
-			s := store.ContextStore(clictx)
-			ctx = store.WithContextStore(ctx, s)
-			ctx = apicontext.WithCurrentContext(ctx, key[0])
+		return handler(srv, newServerStream(ctx, ss))
+	}
+}
 
-			c, err := client.New(ctx)
-			if err != nil {
-				return nil, err
-			}
+// getContext returns the current context name sent in the request metadata, it
+// returns an empty string if there is no metadata
+// not present
+func getContext(ctx context.Context) string {
+	md, ok := metadata.FromIncomingContext(ctx)
+	if !ok {
+		return ""
+	}
 
-			ctx, err = proxy.WithClient(ctx, c)
-			if err != nil {
-				return nil, err
-			}
-		}
+	key, ok := md[apicontext.Key]
+	if !ok {
+		return ""
+	}
 
-		return handler(ctx, req)
+	if len(key) == 1 {
+		return key[0]
 	}
+
+	return ""
+}
+
+// configureContext populates the request context with objects the client
+// needs: the context store and the api client
+func configureContext(ctx context.Context, currentContext string) (context.Context, error) {
+	s := store.ContextStore(ctx)
+	ctx = store.WithContextStore(ctx, s)
+	if currentContext != "" {
+		ctx = apicontext.WithCurrentContext(ctx, currentContext)
+	}
+
+	c, err := client.New(ctx)
+	if err != nil {
+		return nil, err
+	}
+
+	ctx, err = proxy.WithClient(ctx, c)
+	if err != nil {
+		return nil, err
+	}
+
+	return ctx, nil
+}
+
+// A gRPC server stream will only let you get its context but
+// there is no way to set a new (augmented context) to the next
+// handler (like we do for a unary request). We need to wrap the grpc.ServerSteam
+// to be able to set a new context that will be sent to the next stream interceptor.
+type contextServerStream struct {
+	s   grpc.ServerStream
+	ctx context.Context
+}
+
+func newServerStream(ctx context.Context, s grpc.ServerStream) grpc.ServerStream {
+	return &contextServerStream{
+		s:   s,
+		ctx: ctx,
+	}
+}
+
+func (css *contextServerStream) SetHeader(md metadata.MD) error {
+	return css.s.SetHeader(md)
+}
+
+func (css *contextServerStream) SendHeader(md metadata.MD) error {
+	return css.s.SendHeader(md)
+}
+
+func (css *contextServerStream) SetTrailer(md metadata.MD) {
+	css.s.SetTrailer(md)
+}
+
+func (css *contextServerStream) Context() context.Context {
+	return css.ctx
+}
+
+func (css *contextServerStream) SendMsg(m interface{}) error {
+	return css.s.SendMsg(m)
+}
+
+func (css *contextServerStream) RecvMsg(m interface{}) error {
+	return css.s.RecvMsg(m)
 }

+ 22 - 13
tests/node-client/index.ts

@@ -1,26 +1,35 @@
-import * as grpc from '@grpc/grpc-js';
+import * as grpc from "@grpc/grpc-js";
 import * as continersPb from "./grpc/containers_grpc_pb";
-import { IContainersClient } from './grpc/containers_grpc_pb';
+import { IContainersClient } from "./grpc/containers_grpc_pb";
 import { ListRequest, ListResponse } from "./grpc/containers_pb";
 
 let address = process.argv[3] || "unix:///tmp/backend.sock";
-
-const ContainersServiceClient = grpc.makeClientConstructor(continersPb["com.docker.api.containers.v1.Containers"], "ContainersClient");
-const client = new ContainersServiceClient(address, grpc.credentials.createInsecure()) as unknown as IContainersClient;
+const ContainersServiceClient = grpc.makeClientConstructor(
+  continersPb["com.docker.api.containers.v1.Containers"],
+  "ContainersClient"
+);
+const client = (new ContainersServiceClient(
+  address,
+  grpc.credentials.createInsecure()
+) as unknown) as IContainersClient;
 
 let backend = process.argv[2] || "moby";
 const meta = new grpc.Metadata();
 meta.set("CONTEXT_KEY", backend);
 
 client.list(new ListRequest(), meta, (err: any, response: ListResponse) => {
-    if (err != null) {
-        console.error(err);
-        return;
-    }
+  if (err != null) {
+    console.error(err);
+    return;
+  }
 
-    const containers = response.getContainersList();
+  const containers = response.getContainersList();
 
-    containers.forEach(container => {
-        console.log(container.getId(), container.getImage());
-    });
+  containers.forEach((container) => {
+    console.log(container.getId(), container.getImage());
+  });
 });
+
+function arrayBufferToString(buffer: Uint8Array): string {
+  return String.fromCharCode.apply(null, Array.from(buffer));
+}