diff --git a/container/container.go b/container/container.go index 174023f49..09fa0ee19 100644 --- a/container/container.go +++ b/container/container.go @@ -3,7 +3,6 @@ package container import ( "context" "errors" - "io" "time" "github.com/docker/docker/api/types" @@ -28,7 +27,6 @@ type Container interface { ListServices(labels ...string) ([]swarm.Service, error) ListTasks(namespace []string) ([]swarm.Task, error) Namespace(ss []string) string - ServiceLogs(namespace []string) (io.ReadCloser, error) SharedNetworkID() (networkID string, err error) StartService(options ServiceOptions) (serviceID string, err error) Status(namespace []string) (StatusType, error) diff --git a/container/dockertest/client.go b/container/dockertest/client.go index 1a1922bba..01bb30578 100644 --- a/container/dockertest/client.go +++ b/container/dockertest/client.go @@ -42,7 +42,6 @@ type requests struct { serviceList chan ServiceListRequest serviceInspectWithRaw chan ServiceInspectWithRawRequest serviceRemove chan ServiceRemoveRequest - serviceLogs chan ServiceLogsRequest events chan EventsRequest } @@ -62,7 +61,6 @@ type responses struct { serviceList chan serviceListResponse serviceInspectWithRaw chan serviceInspectWithRawResponse serviceRemove chan serviceRemoveResponse - serviceLogs chan serviceLogsResponse containerInspect chan containerInspectResponse containerList chan containerListResponse containerStop chan containerStopResponse @@ -92,7 +90,6 @@ func newClient() *Client { serviceList: make(chan ServiceListRequest, 20), serviceInspectWithRaw: make(chan ServiceInspectWithRawRequest, 20), serviceRemove: make(chan ServiceRemoveRequest, 20), - serviceLogs: make(chan ServiceLogsRequest, 20), events: make(chan EventsRequest, 20), }, @@ -108,7 +105,6 @@ func newClient() *Client { serviceList: make(chan serviceListResponse, 20), serviceInspectWithRaw: make(chan serviceInspectWithRawResponse, 20), serviceRemove: make(chan serviceRemoveResponse, 20), - serviceLogs: make(chan serviceLogsResponse, 20), containerInspect: make(chan containerInspectResponse, 20), containerList: make(chan containerListResponse, 20), containerStop: make(chan containerStopResponse, 20), @@ -291,18 +287,6 @@ func (c *Client) ServiceRemove(ctx context.Context, serviceID string) error { } } -// ServiceLogs is the mock version of the actual method. -func (c *Client) ServiceLogs(ctx context.Context, - serviceID string, options types.ContainerLogsOptions) (io.ReadCloser, error) { - c.requests.serviceLogs <- ServiceLogsRequest{serviceID, options} - select { - case resp := <-c.responses.serviceLogs: - return resp.rc, resp.err - default: - return nil, nil - } -} - // Events is the mock version of the actual method. func (c *Client) Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error) { c.requests.events <- EventsRequest{Options: options} diff --git a/container/dockertest/requests.go b/container/dockertest/requests.go index aac1631d6..ccfd879b4 100644 --- a/container/dockertest/requests.go +++ b/container/dockertest/requests.go @@ -35,12 +35,6 @@ type ServiceInspectWithRawRequest struct { Options types.ServiceInspectOptions } -// ServiceLogsRequest holds call arguments of *Client.ServiceLogs. -type ServiceLogsRequest struct { - ServiceID string - Options types.ContainerLogsOptions -} - // NegotiateAPIVersionRequest holds call arguments of *Client.NegotiateAPIVersion. type NegotiateAPIVersionRequest struct { } diff --git a/container/dockertest/responses.go b/container/dockertest/responses.go index 0b1791817..b8f388942 100644 --- a/container/dockertest/responses.go +++ b/container/dockertest/responses.go @@ -1,19 +1,11 @@ package dockertest import ( - "io" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/swarm" ) -// serviceLogsResponse holds fake return values of *Client.ServiceLogs. -type serviceLogsResponse struct { - rc io.ReadCloser - err error -} - // serviceRemoveResponse holds fake return values of *Client.ServiceRemove. type serviceRemoveResponse struct { err error diff --git a/container/dockertest/testing.go b/container/dockertest/testing.go index 84bcfb31e..6bf907917 100644 --- a/container/dockertest/testing.go +++ b/container/dockertest/testing.go @@ -78,11 +78,6 @@ func (t *Testing) ProvideServiceInspectWithRaw(service swarm.Service, data []byt t.client.responses.serviceInspectWithRaw <- serviceInspectWithRawResponse{service, data, err} } -// ProvideServiceLogs sets fake return values for the next call to *Client.ServiceLogs. -func (t *Testing) ProvideServiceLogs(rc io.ReadCloser, err error) { - t.client.responses.serviceLogs <- serviceLogsResponse{rc, err} -} - // ProvideTaskList sets fake return values for the next call to *Client.TaskList. func (t *Testing) ProvideTaskList(tasks []swarm.Task, err error) { t.client.responses.taskList <- taskListResponse{tasks, err} @@ -192,11 +187,6 @@ func (t *Testing) LastServiceRemove() <-chan ServiceRemoveRequest { return t.client.requests.serviceRemove } -// LastServiceLogs returns a channel that receives call arguments of last *Client.ServiceLogs call. -func (t *Testing) LastServiceLogs() <-chan ServiceLogsRequest { - return t.client.requests.serviceLogs -} - // LastEvents returns a channel that receives call arguments of last *Client.ServiceLogs call. func (t *Testing) LastEvents() <-chan EventsRequest { return t.client.requests.events diff --git a/container/dockertest/testing_test.go b/container/dockertest/testing_test.go index 19e9d46ab..689f85a3c 100644 --- a/container/dockertest/testing_test.go +++ b/container/dockertest/testing_test.go @@ -244,27 +244,6 @@ func TestServiceRemove(t *testing.T) { require.Equal(t, serviceID, ll.ServiceID) } -func TestServiceLogs(t *testing.T) { - serviceID := "1" - data := []byte{1, 2} - options := types.ContainerLogsOptions{ShowStdout: true} - - dt := New() - dt.ProvideServiceLogs(ioutil.NopCloser(bytes.NewReader(data)), errGeneric) - - rc, err := dt.Client().ServiceLogs(context.Background(), serviceID, options) - require.Equal(t, errGeneric, err) - defer rc.Close() - - data1, err := ioutil.ReadAll(rc) - require.NoError(t, err) - require.Equal(t, data, data1) - - ll := <-dt.LastServiceLogs() - require.Equal(t, serviceID, ll.ServiceID) - require.Equal(t, options, ll.Options) -} - func TestEvents(t *testing.T) { dt := New() msgC := make(chan events.Message) diff --git a/container/mocks/Container.go b/container/mocks/Container.go index c0c499967..f8fc2cdb0 100644 --- a/container/mocks/Container.go +++ b/container/mocks/Container.go @@ -3,7 +3,6 @@ package mocks import container "github.com/mesg-foundation/engine/container" -import io "io" import mock "github.com/stretchr/testify/mock" import swarm "github.com/docker/docker/api/types/swarm" import types "github.com/docker/docker/api/types" @@ -212,29 +211,6 @@ func (_m *Container) Namespace(ss []string) string { return r0 } -// ServiceLogs provides a mock function with given fields: namespace -func (_m *Container) ServiceLogs(namespace []string) (io.ReadCloser, error) { - ret := _m.Called(namespace) - - var r0 io.ReadCloser - if rf, ok := ret.Get(0).(func([]string) io.ReadCloser); ok { - r0 = rf(namespace) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(io.ReadCloser) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func([]string) error); ok { - r1 = rf(namespace) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - // SharedNetworkID provides a mock function with given fields: func (_m *Container) SharedNetworkID() (string, error) { ret := _m.Called() diff --git a/container/service.go b/container/service.go index f687c0868..dccb4dc5d 100644 --- a/container/service.go +++ b/container/service.go @@ -2,7 +2,6 @@ package container import ( "context" - "io" "time" "github.com/docker/docker/api/types" @@ -106,15 +105,3 @@ func (c *DockerContainer) deletePendingContainer(namespace []string, maxGraceTim time.Sleep(1 * time.Second) return c.deletePendingContainer(namespace, maxGraceTime) } - -// ServiceLogs returns the logs of a service. -func (c *DockerContainer) ServiceLogs(namespace []string) (io.ReadCloser, error) { - return c.client.ServiceLogs(context.Background(), c.Namespace(namespace), - types.ContainerLogsOptions{ - ShowStdout: true, - ShowStderr: true, - Timestamps: false, - Follow: true, - }, - ) -} diff --git a/container/service_integration_test.go b/container/service_integration_test.go index fed2b0fdf..3f899ecd0 100644 --- a/container/service_integration_test.go +++ b/container/service_integration_test.go @@ -158,14 +158,3 @@ func TestIntegrationListServices(t *testing.T) { require.Equal(t, 1, len(services)) require.Equal(t, c.Namespace([]string{"TestListServices"}), services[0].Spec.Name) } - -func TestIntegrationServiceLogs(t *testing.T) { - c, err := New() - require.NoError(t, err) - namespace := []string{"TestServiceLogs"} - startTestService(namespace) - defer c.StopService(namespace) - reader, err := c.ServiceLogs(namespace) - require.NoError(t, err) - require.NotNil(t, reader) -} diff --git a/container/service_test.go b/container/service_test.go index 7b1d52554..e25281d0e 100644 --- a/container/service_test.go +++ b/container/service_test.go @@ -1,8 +1,6 @@ package container import ( - "bytes" - "io/ioutil" "testing" "time" @@ -253,30 +251,3 @@ func TestListServices(t *testing.T) { }), }, (<-dt.LastServiceList()).Options) } - -func TestServiceLogs(t *testing.T) { - namespace := []string{"namespace"} - data := []byte{1, 2} - - dt := dockertest.New() - c, _ := New(ClientOption(dt.Client())) - - dt.ProvideServiceLogs(ioutil.NopCloser(bytes.NewReader(data)), nil) - - reader, err := c.ServiceLogs(namespace) - require.NoError(t, err) - defer reader.Close() - - bytes, err := ioutil.ReadAll(reader) - require.NoError(t, err) - require.Equal(t, data, bytes) - - ll := <-dt.LastServiceLogs() - require.Equal(t, c.Namespace(namespace), ll.ServiceID) - require.Equal(t, types.ContainerLogsOptions{ - ShowStdout: true, - ShowStderr: true, - Timestamps: false, - Follow: true, - }, ll.Options) -} diff --git a/protobuf/coreapi/api.pb.go b/protobuf/coreapi/api.pb.go index 05c9fdf96..16a6873d6 100644 --- a/protobuf/coreapi/api.pb.go +++ b/protobuf/coreapi/api.pb.go @@ -22,87 +22,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package -type LogData_Type int32 - -const ( - LogData_Standard LogData_Type = 0 - LogData_Error LogData_Type = 1 -) - -var LogData_Type_name = map[int32]string{ - 0: "Standard", - 1: "Error", -} - -var LogData_Type_value = map[string]int32{ - "Standard": 0, - "Error": 1, -} - -func (x LogData_Type) String() string { - return proto.EnumName(LogData_Type_name, int32(x)) -} - -func (LogData_Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_10679b8ed3075b1e, []int{3, 0} -} - -// The request's data for `ServiceLogs` API. -// -// **Example** -// ```json -// { -// "serviceID": "__SERVICE_ID__", -// "dependencies": ["__SERVICE_DEPENDENCY__"] -// } -// ``` -type ServiceLogsRequest struct { - ServiceID string `protobuf:"bytes,1,opt,name=serviceID,proto3" json:"serviceID,omitempty"` - Dependencies []string `protobuf:"bytes,2,rep,name=dependencies,proto3" json:"dependencies,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ServiceLogsRequest) Reset() { *m = ServiceLogsRequest{} } -func (m *ServiceLogsRequest) String() string { return proto.CompactTextString(m) } -func (*ServiceLogsRequest) ProtoMessage() {} -func (*ServiceLogsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_10679b8ed3075b1e, []int{0} -} - -func (m *ServiceLogsRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ServiceLogsRequest.Unmarshal(m, b) -} -func (m *ServiceLogsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ServiceLogsRequest.Marshal(b, m, deterministic) -} -func (m *ServiceLogsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ServiceLogsRequest.Merge(m, src) -} -func (m *ServiceLogsRequest) XXX_Size() int { - return xxx_messageInfo_ServiceLogsRequest.Size(m) -} -func (m *ServiceLogsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ServiceLogsRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_ServiceLogsRequest proto.InternalMessageInfo - -func (m *ServiceLogsRequest) GetServiceID() string { - if m != nil { - return m.ServiceID - } - return "" -} - -func (m *ServiceLogsRequest) GetDependencies() []string { - if m != nil { - return m.Dependencies - } - return nil -} - // The request to fetch all informations of the Core type InfoRequest struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -114,7 +33,7 @@ func (m *InfoRequest) Reset() { *m = InfoRequest{} } func (m *InfoRequest) String() string { return proto.CompactTextString(m) } func (*InfoRequest) ProtoMessage() {} func (*InfoRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_10679b8ed3075b1e, []int{1} + return fileDescriptor_10679b8ed3075b1e, []int{0} } func (m *InfoRequest) XXX_Unmarshal(b []byte) error { @@ -148,7 +67,7 @@ func (m *InfoReply) Reset() { *m = InfoReply{} } func (m *InfoReply) String() string { return proto.CompactTextString(m) } func (*InfoReply) ProtoMessage() {} func (*InfoReply) Descriptor() ([]byte, []int) { - return fileDescriptor_10679b8ed3075b1e, []int{2} + return fileDescriptor_10679b8ed3075b1e, []int{1} } func (m *InfoReply) XXX_Unmarshal(b []byte) error { @@ -197,7 +116,7 @@ func (m *InfoReply_CoreService) Reset() { *m = InfoReply_CoreService{} } func (m *InfoReply_CoreService) String() string { return proto.CompactTextString(m) } func (*InfoReply_CoreService) ProtoMessage() {} func (*InfoReply_CoreService) Descriptor() ([]byte, []int) { - return fileDescriptor_10679b8ed3075b1e, []int{2, 0} + return fileDescriptor_10679b8ed3075b1e, []int{1, 0} } func (m *InfoReply_CoreService) XXX_Unmarshal(b []byte) error { @@ -246,110 +165,32 @@ func (m *InfoReply_CoreService) GetKey() string { return "" } -// The data received from the stream of the `ServiceLogs` API. -// The data will be received over time as long as the stream is open. -// -// **Example** -// ```json -// { -// "dependency": "__SERVICE_DEPENDENCY__", -// "type": "__LOG_TYPE__", -// "data": "__LOG_CHUNK__", -// } -// ``` -type LogData struct { - Dependency string `protobuf:"bytes,1,opt,name=dependency,proto3" json:"dependency,omitempty"` - Type LogData_Type `protobuf:"varint,2,opt,name=type,proto3,enum=api.LogData_Type" json:"type,omitempty"` - Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *LogData) Reset() { *m = LogData{} } -func (m *LogData) String() string { return proto.CompactTextString(m) } -func (*LogData) ProtoMessage() {} -func (*LogData) Descriptor() ([]byte, []int) { - return fileDescriptor_10679b8ed3075b1e, []int{3} -} - -func (m *LogData) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_LogData.Unmarshal(m, b) -} -func (m *LogData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_LogData.Marshal(b, m, deterministic) -} -func (m *LogData) XXX_Merge(src proto.Message) { - xxx_messageInfo_LogData.Merge(m, src) -} -func (m *LogData) XXX_Size() int { - return xxx_messageInfo_LogData.Size(m) -} -func (m *LogData) XXX_DiscardUnknown() { - xxx_messageInfo_LogData.DiscardUnknown(m) -} - -var xxx_messageInfo_LogData proto.InternalMessageInfo - -func (m *LogData) GetDependency() string { - if m != nil { - return m.Dependency - } - return "" -} - -func (m *LogData) GetType() LogData_Type { - if m != nil { - return m.Type - } - return LogData_Standard -} - -func (m *LogData) GetData() []byte { - if m != nil { - return m.Data - } - return nil -} - func init() { - proto.RegisterEnum("api.LogData_Type", LogData_Type_name, LogData_Type_value) - proto.RegisterType((*ServiceLogsRequest)(nil), "api.ServiceLogsRequest") proto.RegisterType((*InfoRequest)(nil), "api.InfoRequest") proto.RegisterType((*InfoReply)(nil), "api.InfoReply") proto.RegisterType((*InfoReply_CoreService)(nil), "api.InfoReply.CoreService") - proto.RegisterType((*LogData)(nil), "api.LogData") } func init() { proto.RegisterFile("protobuf/coreapi/api.proto", fileDescriptor_10679b8ed3075b1e) } var fileDescriptor_10679b8ed3075b1e = []byte{ - // 390 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x92, 0xc1, 0x8e, 0xd3, 0x30, - 0x10, 0x86, 0x9b, 0x4d, 0x60, 0x37, 0xd3, 0xb2, 0x2a, 0x73, 0x21, 0xaa, 0x10, 0x54, 0x96, 0x90, - 0x2a, 0x24, 0x12, 0x54, 0x10, 0xe2, 0x0c, 0xcb, 0x61, 0xa5, 0x3d, 0x65, 0x11, 0x48, 0xdc, 0xdc, - 0x64, 0x9a, 0x5a, 0x64, 0x6d, 0x63, 0x3b, 0x2b, 0xe5, 0x01, 0x78, 0x25, 0x9e, 0x0f, 0xd9, 0x09, - 0x25, 0x85, 0xdb, 0xf8, 0xcb, 0xef, 0xf9, 0xff, 0x19, 0x07, 0x56, 0xda, 0x28, 0xa7, 0x76, 0xdd, - 0xbe, 0xa8, 0x94, 0x21, 0xae, 0x45, 0xc1, 0xb5, 0xc8, 0x03, 0xc4, 0x98, 0x6b, 0x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, 0xbe, 0x8b, 0x32, 0xd4, 0xec, 0x39, 0x24, 0x5e, 0x81, 0x0b, 0xb8, 0xb8, 0x75, - 0x5c, 0xd6, 0xdc, 0xd4, 0xcb, 0x19, 0xa6, 0xf0, 0xe0, 0x93, 0x31, 0xca, 0x2c, 0xa3, 0x6d, 0x0b, - 0x89, 0x1f, 0x10, 0xdf, 0xc3, 0x7c, 0xf2, 0x5e, 0xf8, 0x24, 0x98, 0xfc, 0xff, 0x82, 0xab, 0xc5, - 0xd4, 0x9d, 0xcd, 0x5e, 0x47, 0xf8, 0x12, 0x12, 0xbf, 0x5f, 0x5c, 0x4e, 0x56, 0x3d, 0x68, 0x2f, - 0x4f, 0x97, 0xcf, 0x66, 0x1f, 0xde, 0x7e, 0xdb, 0x36, 0xc2, 0x1d, 0xba, 0x5d, 0x5e, 0xa9, 0xbb, - 0xe2, 0x8e, 0x6c, 0xf3, 0x6a, 0xaf, 0x3a, 0x59, 0x73, 0x27, 0x94, 0x2c, 0x48, 0x36, 0x42, 0x52, - 0xf1, 0xef, 0xaf, 0xb5, 0x7b, 0x18, 0xc8, 0x9b, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x6e, 0xb2, - 0xfd, 0xd9, 0x75, 0x02, 0x00, 0x00, + // 249 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x90, 0xc1, 0x4a, 0xc4, 0x30, + 0x10, 0x86, 0xad, 0x2d, 0xea, 0xce, 0xa2, 0x2c, 0x39, 0x85, 0x9e, 0x96, 0x9e, 0x16, 0xc1, 0x06, + 0xaa, 0xf8, 0x00, 0x7a, 0xf2, 0x5a, 0x0f, 0x82, 0xb7, 0xb4, 0x3b, 0x6d, 0x83, 0xdd, 0x4c, 0x4c, + 0x9a, 0x85, 0x7d, 0x31, 0x9f, 0x4f, 0x92, 0xea, 0xb2, 0x7a, 0xfb, 0xe7, 0xe3, 0x9b,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d, 0x8f, 0x9d, 0x5b, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -364,8 +205,6 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type CoreClient interface { - // ServiceLogs gives a stream for dependency logs of a service. - ServiceLogs(ctx context.Context, in *ServiceLogsRequest, opts ...grpc.CallOption) (Core_ServiceLogsClient, error) // Info returns all necessary information from the core. Info(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*InfoReply, error) } @@ -378,38 +217,6 @@ func NewCoreClient(cc *grpc.ClientConn) CoreClient { return &coreClient{cc} } -func (c *coreClient) ServiceLogs(ctx context.Context, in *ServiceLogsRequest, opts ...grpc.CallOption) (Core_ServiceLogsClient, error) { - stream, err := c.cc.NewStream(ctx, &_Core_serviceDesc.Streams[0], "/api.Core/ServiceLogs", opts...) - if err != nil { - return nil, err - } - x := &coreServiceLogsClient{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 Core_ServiceLogsClient interface { - Recv() (*LogData, error) - grpc.ClientStream -} - -type coreServiceLogsClient struct { - grpc.ClientStream -} - -func (x *coreServiceLogsClient) Recv() (*LogData, error) { - m := new(LogData) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - func (c *coreClient) Info(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*InfoReply, error) { out := new(InfoReply) err := c.cc.Invoke(ctx, "/api.Core/Info", in, out, opts...) @@ -421,8 +228,6 @@ func (c *coreClient) Info(ctx context.Context, in *InfoRequest, opts ...grpc.Cal // CoreServer is the server API for Core service. type CoreServer interface { - // ServiceLogs gives a stream for dependency logs of a service. - ServiceLogs(*ServiceLogsRequest, Core_ServiceLogsServer) error // Info returns all necessary information from the core. Info(context.Context, *InfoRequest) (*InfoReply, error) } @@ -431,27 +236,6 @@ func RegisterCoreServer(s *grpc.Server, srv CoreServer) { s.RegisterService(&_Core_serviceDesc, srv) } -func _Core_ServiceLogs_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(ServiceLogsRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(CoreServer).ServiceLogs(m, &coreServiceLogsServer{stream}) -} - -type Core_ServiceLogsServer interface { - Send(*LogData) error - grpc.ServerStream -} - -type coreServiceLogsServer struct { - grpc.ServerStream -} - -func (x *coreServiceLogsServer) Send(m *LogData) error { - return x.ServerStream.SendMsg(m) -} - func _Core_Info_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(InfoRequest) if err := dec(in); err != nil { @@ -479,12 +263,6 @@ var _Core_serviceDesc = grpc.ServiceDesc{ Handler: _Core_Info_Handler, }, }, - Streams: []grpc.StreamDesc{ - { - StreamName: "ServiceLogs", - Handler: _Core_ServiceLogs_Handler, - ServerStreams: true, - }, - }, + Streams: []grpc.StreamDesc{}, Metadata: "protobuf/coreapi/api.proto", } diff --git a/protobuf/coreapi/api.proto b/protobuf/coreapi/api.proto index 1c3000247..305e4611d 100644 --- a/protobuf/coreapi/api.proto +++ b/protobuf/coreapi/api.proto @@ -13,27 +13,10 @@ option go_package = "github.com/mesg-foundation/engine/protobuf/coreapi"; // // The source file of this API is hosted on [GitHub](https://github.com/mesg-foundation/engine/blob/master/protobuf/coreapi/api.proto). service Core { - // ServiceLogs gives a stream for dependency logs of a service. - rpc ServiceLogs (ServiceLogsRequest) returns (stream LogData) {} - // Info returns all necessary information from the core. rpc Info(InfoRequest) returns (InfoReply) {} } -// The request's data for `ServiceLogs` API. -// -// **Example** -// ```json -// { -// "serviceID": "__SERVICE_ID__", -// "dependencies": ["__SERVICE_DEPENDENCY__"] -// } -// ``` -message ServiceLogsRequest { - string serviceID = 1; // The Service ID. Generated when using the [`DeployService` API](#deployservice). - repeated string dependencies = 2; // __Optional.__ List of dependencies to filter service logs. All by default. -} - // The request to fetch all informations of the Core message InfoRequest {} @@ -48,26 +31,3 @@ message InfoReply { repeated CoreService services = 1; // List of services that the core is running as core service string version = 4; // Version of the core } - -// The data received from the stream of the `ServiceLogs` API. -// The data will be received over time as long as the stream is open. -// -// **Example** -// ```json -// { -// "dependency": "__SERVICE_DEPENDENCY__", -// "type": "__LOG_TYPE__", -// "data": "__LOG_CHUNK__", -// } -// ``` -message LogData { - enum Type { - Standard = 0; // Standard represents standard log output. - Error = 1; // Error represents error log output. - } - - string dependency = 1; // Service dependency that data belongs. - Type type = 2; // The log type. - bytes data = 3; // Log data chunk. -} - diff --git a/sdk/service/log.go b/sdk/service/log.go deleted file mode 100644 index f7fd414a1..000000000 --- a/sdk/service/log.go +++ /dev/null @@ -1,84 +0,0 @@ -package servicesdk - -import ( - "crypto/sha1" - "encoding/hex" - "io" - - "github.com/docker/docker/pkg/stdcopy" - "github.com/mesg-foundation/engine/hash" - "github.com/mesg-foundation/engine/service" - "github.com/mesg-foundation/engine/x/xstrings" - "github.com/sirupsen/logrus" -) - -// serviceLogFilters keeps log filters. -type serviceLogFilters struct { - // dependencies list is used to provide logs for only requested dependencies. - dependencies []string -} - -// LogsFilter is a filter func for filtering service logs. -type LogsFilter func(*serviceLogFilters) - -// LogsDependenciesFilter returns a dependency filter. -func LogsDependenciesFilter(dependencies ...string) LogsFilter { - return func(s *serviceLogFilters) { - s.dependencies = dependencies - } -} - -// Logs provides logs for dependencies of service serviceID that matches with filters. -// when no dependency filters are set, all the dependencies' logs will be provided. -func (s *Service) Logs(serviceHash hash.Hash, filters ...LogsFilter) ([]*service.Log, error) { - f := &serviceLogFilters{} - for _, filter := range filters { - filter(f) - } - srv, err := s.serviceDB.Get(serviceHash) - if err != nil { - return nil, err - } - var ( - logs []*service.Log - isNoFilter = len(f.dependencies) == 0 - ) - for _, d := range append(srv.Dependencies, srv.Configuration) { - // Service.Configuration can be nil so, here is a check for it. - if d == nil { - continue - } - if isNoFilter || xstrings.SliceContains(f.dependencies, d.Key) { - var r io.ReadCloser - r, err := s.container.ServiceLogs(dependencyNamespace(serviceNamespace(srv.Hash), d.Key)) - if err != nil { - return nil, err - } - rstd, sw := io.Pipe() - rerr, ew := io.Pipe() - go func(dstout, dsterr io.Writer, r io.ReadCloser) { - if _, err := stdcopy.StdCopy(dstout, dsterr, r); err != nil { - r.Close() - logrus.Errorln(err) - } - }(sw, ew, r) - logs = append(logs, &service.Log{ - Dependency: d.Key, - Standard: rstd, - Error: rerr, - }) - } - } - return logs, nil -} - -// serviceNamespace returns the namespace of the service. -func serviceNamespace(hash hash.Hash) []string { - sum := sha1.Sum(hash) - return []string{hex.EncodeToString(sum[:])} -} - -// dependencyNamespace builds the namespace of a dependency. -func dependencyNamespace(serviceNamespace []string, dependencyKey string) []string { - return append(serviceNamespace, dependencyKey) -} diff --git a/server/grpc/core/logs.go b/server/grpc/core/logs.go deleted file mode 100644 index a0994b38d..000000000 --- a/server/grpc/core/logs.go +++ /dev/null @@ -1,75 +0,0 @@ -package core - -import ( - "github.com/mesg-foundation/engine/hash" - "github.com/mesg-foundation/engine/protobuf/acknowledgement" - "github.com/mesg-foundation/engine/protobuf/coreapi" - servicesdk "github.com/mesg-foundation/engine/sdk/service" - "github.com/mesg-foundation/engine/utils/chunker" -) - -// ServiceLogs gives logs of service with the applied dependency filters. -func (s *Server) ServiceLogs(request *coreapi.ServiceLogsRequest, stream coreapi.Core_ServiceLogsServer) error { - hash, err := hash.Decode(request.ServiceID) - if err != nil { - return err - } - - sl, err := s.sdk.Service.Logs(hash, servicesdk.LogsDependenciesFilter(request.Dependencies...)) - if err != nil { - return err - } - - var ( - chunks = make(chan chunker.Data) - errs = make(chan error) - ) - - for _, l := range sl { - cstd := chunker.New(l.Standard, chunks, errs, chunker.ValueOption(&chunkMeta{ - Dependency: l.Dependency, - Type: coreapi.LogData_Standard, - })) - cerr := chunker.New(l.Error, chunks, errs, chunker.ValueOption(&chunkMeta{ - Dependency: l.Dependency, - Type: coreapi.LogData_Error, - })) - defer cstd.Close() - defer cerr.Close() - defer l.Standard.Close() - defer l.Error.Close() - } - - // send header to notify client that the stream is ready. - if err := acknowledgement.SetStreamReady(stream); err != nil { - return err - } - - ctx := stream.Context() - for { - select { - case <-ctx.Done(): - return ctx.Err() - - case err := <-errs: - return err - - case chunk := <-chunks: - meta := chunk.Value.(*chunkMeta) - data := &coreapi.LogData{ - Dependency: meta.Dependency, - Type: meta.Type, - Data: chunk.Data, - } - if err := stream.Send(data); err != nil { - return err - } - } - } -} - -// chunkMeta is a meta data for chunks. -type chunkMeta struct { - Dependency string - Type coreapi.LogData_Type -} diff --git a/utils/chunker/chunker.go b/utils/chunker/chunker.go deleted file mode 100644 index 583ced578..000000000 --- a/utils/chunker/chunker.go +++ /dev/null @@ -1,97 +0,0 @@ -// Package chunker provides functionalities to create chunks from an -// io.Reader and also create an io.Reader from chunks. -package chunker - -import ( - "io" -) - -// Chunker converts data read from reader into chunks. -type Chunker struct { - // chunkSize determines the chunk sizes. - chunkSize int - - // reader is the reader to convert into chunks. - reader io.Reader - - // chunks is the channel where upcoming chunks sent. - chunks chan Data - - // err is the channel where the error will be send after chunking - // operation fails. - err chan error - - // value carries the context value of chunk. - value interface{} - - closed chan struct{} -} - -// Data represents a data chunk. -type Data struct { - // Value carries the context value of data chunk. - Value interface{} - - // Data is data chunk. - Data []byte -} - -// New returns a new chunker for r and it forwards each chunk to chunks channel. -// an error will be sent to err channel if chunking fails. -func New(r io.Reader, chunks chan Data, err chan error, options ...Option) *Chunker { - c := &Chunker{ - reader: r, - chunks: chunks, - err: err, - closed: make(chan struct{}), - chunkSize: 1024, - } - for _, option := range options { - option(c) - } - go c.read() - return c -} - -// Option is the configuration func of Chunker. -type Option func(*Chunker) - -// ChunkSizeOption returns an option to set chunk size. -func ChunkSizeOption(n int) Option { - return func(c *Chunker) { - c.chunkSize = n - } -} - -// ValueOption returns an option to set context value to chunks. -func ValueOption(value interface{}) Option { - return func(c *Chunker) { - c.value = value - } -} - -// read reads data from reader and sends to chunks channel. -func (c *Chunker) read() { - buf := make([]byte, c.chunkSize) - for { - n, err := c.reader.Read(buf) - if err != nil { - c.err <- err - return - } - select { - case <-c.closed: - return - case c.chunks <- Data{ - Value: c.value, - Data: buf[:n], - }: - } - } -} - -// Close will stop reading from reader and no more chunks will be emitted. -func (c *Chunker) Close() error { - close(c.closed) - return nil -} diff --git a/utils/chunker/chunker_test.go b/utils/chunker/chunker_test.go deleted file mode 100644 index 6ed899c94..000000000 --- a/utils/chunker/chunker_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package chunker - -import ( - "bytes" - "io" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestNew(t *testing.T) { - var ( - chunk = []byte{1, 2} - r = errorCloser{bytes.NewReader(chunk)} - chunks = make(chan Data) - errs = make(chan error) - value = "1" - ) - - New(r, chunks, errs, ValueOption(value)) - - require.Equal(t, Data{ - Value: value, - Data: chunk, - }, <-chunks) - - r.Close() - require.Equal(t, io.EOF, <-errs) -} - -type errorCloser struct { - io.Reader -} - -func (c errorCloser) Close() error { - return io.EOF -} diff --git a/utils/chunker/stream.go b/utils/chunker/stream.go deleted file mode 100644 index 01a9e9081..000000000 --- a/utils/chunker/stream.go +++ /dev/null @@ -1,64 +0,0 @@ -package chunker - -import ( - "io" - "sync" -) - -// Stream implements io.Reader. -type Stream struct { - recv chan []byte - - done chan struct{} - m sync.Mutex - - data []byte - i int64 -} - -// NewStream returns a new stream. -func NewStream() *Stream { - return &Stream{ - recv: make(chan []byte), - done: make(chan struct{}, 1), - } -} - -// Provide provides data for Read. -func (s *Stream) Provide(data []byte) { - s.recv <- data -} - -// Read puts data into p. -func (s *Stream) Read(p []byte) (n int, err error) { - if s.i >= int64(len(s.data)) { - for { - select { - case <-s.done: - return 0, io.EOF - - case data := <-s.recv: - if err != nil { - return 0, err - } - s.data = data - s.i = 0 - return s.Read(p) - } - } - } - n = copy(p, s.data[s.i:]) - s.i += int64(n) - return n, nil -} - -// Close closes reader. -func (s *Stream) Close() error { - s.m.Lock() - defer s.m.Unlock() - if s.done == nil { - return nil - } - s.done <- struct{}{} - return nil -} diff --git a/utils/chunker/stream_test.go b/utils/chunker/stream_test.go deleted file mode 100644 index 95c6c999b..000000000 --- a/utils/chunker/stream_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package chunker - -import ( - "io/ioutil" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestLogReader(t *testing.T) { - var ( - chunk1 = []byte{1} - chunk2 = []byte{2} - ) - - s := NewStream() - - go func() { - s.Provide(chunk1) - s.Provide(chunk2) - s.Close() - }() - - data, err := ioutil.ReadAll(s) - require.NoError(t, err) - require.Len(t, data, 2) - require.Equal(t, chunk1, []byte{data[0]}) - require.Equal(t, chunk2, []byte{data[1]}) -}