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

Improve logs in daemon #352

Merged
merged 10 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- (#282) Branch support added. You can now specify your branches with a `#branch` fragment at the end of your git url. E.g.: https://github.com/mesg-foundation/service-ethereum-erc20#websocket
- (#299) Add more user friendly errors when failing to connect to the Core or Docker
- (#356) Use github.com/stretchr/testify package
- (#352) Use logrus logging package

#### Added
- (#242) Add more details in command `mesg-core service validate`
Expand Down
22 changes: 21 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
# go-tests = true
# unused-packages = true

[[constraint]]
branch = "master"
name = "github.com/grpc-ecosystem/go-grpc-middleware"

[[constraint]]
version = "1.0.6"
name = "github.com/sirupsen/logrus"

[[constraint]]
branch = "master"
Expand Down Expand Up @@ -77,7 +84,7 @@
branch = "master"
name = "golang.org/x/net"

[[constraint]]
[[override]]
branch = "master"
name = "google.golang.org/grpc"

Expand Down
40 changes: 20 additions & 20 deletions api/core/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import "github.com/mesg-foundation/core/service/service.proto";
// This is the primary API to interact with MESG Core functionalities.
// It can be consumed by any applications or tools that you'd like to interact with MESG Core.
// It is actually used by the MESG CLI and MESG Application libraries.
//
//
// This API is only accessible through [gRPC](https://grpc.io/).
//
//
// Services must not use this API, but rather use the [Service API](./service.md).
//
//
// The source file of this API is hosted on [GitHub](https://github.com/mesg-foundation/core/blob/master/api/core/api.proto).
service Core {
// Subscribe to a stream that listens for events from a service.
rpc ListenEvent (ListenEventRequest) returns (stream EventData) {}

// Subscribe to a stream that listens for task's result from a service.
rpc ListenResult (ListenResultRequest) returns (stream ResultData) {}

// Execute a service's task through [Core](../guide/start-here/core.md).
rpc ExecuteTask (ExecuteTaskRequest) returns (ExecuteTaskReply) {}

Expand All @@ -29,10 +29,10 @@ service Core {

// Stop a service. The service must be already deployed to [Core](../guide/start-here/core.md).
rpc StopService (StopServiceRequest) returns (StopServiceReply) {}

// Deploy a service to [Core](../guide/start-here/core.md). This will give you an unique identifier which is used to interact with the service.
rpc DeployService (DeployServiceRequest) returns (DeployServiceReply) {}

// Delete a service from Core. This function only deletes a deployed service in [Core](../guide/start-here/core.md). If the service's code is on your computer, the source code will not be deleted.
rpc DeleteService (DeleteServiceRequest) returns (DeleteServiceReply) {}

Expand All @@ -44,7 +44,7 @@ service Core {
}

// The request's data for the `ListenEvent` stream's API.
//
//
// **Example**
// ```json
// {
Expand All @@ -59,7 +59,7 @@ message ListenEventRequest {

// The data received from the stream of the `ListenEvent` API.
// The data will be received over time as long as the stream is open.
//
//
// **Example**
// ```json
// {
Expand All @@ -73,7 +73,7 @@ message EventData {
}

// The request's data for the `ListenResult` stream API.
//
//
// **Example**
// ```json
// {
Expand All @@ -90,7 +90,7 @@ message ListenResultRequest {

// The data received from the stream of the `ListenResult` API.
// The data will be received over time as long as the stream is open.
//
//
// **Example**
// ```json
// {
Expand All @@ -108,7 +108,7 @@ message ResultData {
}

// The request's data for the `ExecuteTask` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -124,7 +124,7 @@ message ExecuteTaskRequest {
}

// The reply's data of the `ExecuteTask` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -136,7 +136,7 @@ message ExecuteTaskReply {
}

// The request's data for the `StartService` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -152,7 +152,7 @@ message StartServiceReply {
}

// The request's data for the `StopService` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -168,7 +168,7 @@ message StopServiceReply {
}

// The request's data for `DeployService` API.
//
//
// **Example**
// ```json
// {
Expand Down Expand Up @@ -203,7 +203,7 @@ message DeployServiceRequest {
}

// The reply's data of `DeployService` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -215,7 +215,7 @@ message DeployServiceReply {
}

// Request's data of the `DeleteService` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -235,7 +235,7 @@ message ListServicesRequest {
}

// The reply's data of the `ListServices` API.
//
//
// **Example**
// ```json
// [{
Expand Down Expand Up @@ -270,7 +270,7 @@ message ListServicesReply {
}

// The request's data for the `GetService` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -282,7 +282,7 @@ message GetServiceRequest {
}

// The reply's data of the `GetService` API.
//
//
// **Example**
// ```json
// {
Expand Down
15 changes: 12 additions & 3 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package api

import (
"errors"
"log"
"net"
"os"

"github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
"github.com/mesg-foundation/core/api/core"
"github.com/mesg-foundation/core/api/service"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
Expand Down Expand Up @@ -35,10 +37,17 @@ func (s *Server) Serve() error {
}

s.listener = listener
s.instance = grpc.NewServer()
s.instance = grpc.NewServer(
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
grpc_logrus.StreamServerInterceptor(logrus.NewEntry(logrus.StandardLogger())),
)),
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
grpc_logrus.UnaryServerInterceptor(logrus.NewEntry(logrus.StandardLogger())),
)),
)
s.register()

log.Println("Server listens on", s.listener.Addr())
logrus.Info("Server listens on ", s.listener.Addr())

// TODO: check if server still on after a connection throw an error. otherwise, add a for around serve
return s.instance.Serve(s.listener)
Expand Down
14 changes: 7 additions & 7 deletions api/service/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ option go_package = "service";
// This is the API for MESG Services to interact with MESG Core.
// It is to be consumed only by MESG Services.
// It provides all necessary functions that MESG Services need in order to interact with MESG Core.
//
//
// This API is only accessible through [gRPC](https://grpc.io/).
//
//
// Applications must not use this API, but rather use the [Core API](./core.md).
//
//
// The source file of this API is hosted on [GitHub](https://github.com/mesg-foundation/core/blob/master/api/service/api.proto).
service Service {
// Emit an event to [Core](../guide/start-here/core.md).
Expand All @@ -27,7 +27,7 @@ service Service {
}

// The request's data for the `EmitEvent` API.
//
//
// **Example:**
// ```json
// {
Expand All @@ -47,7 +47,7 @@ message EmitEventReply {
}

// The request's data for the `ListenTask` stream API.
//
//
// **Example:**
// ```json
// {
Expand All @@ -61,7 +61,7 @@ message ListenTaskRequest {
// The data received from the stream of the `ListenTask` API.
// The data will be received over time as long as the stream is open.
// The `executionID` value must be kept and sent with the result when calling the [`SubmitResult` API](#submitresult).
//
//
// **Example:**
// ```json
// {
Expand All @@ -78,7 +78,7 @@ message TaskData {

// The request's data for the `SubmitResult` API.
// The data must contain the `executionID` of the executed task received from the stream of [`ListenTask` API](#listentask).
//
//
// **Example:**
// ```json
// {
Expand Down
10 changes: 5 additions & 5 deletions cmd/service/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package service
import (
"context"
"fmt"
"log"

"github.com/logrusorgru/aurora"
"github.com/mesg-foundation/core/api/core"
"github.com/mesg-foundation/core/cmd/utils"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -74,10 +74,10 @@ func listenEvents(serviceID string, filter string) {
for {
event, err := stream.Recv()
if err != nil {
log.Println(aurora.Red(err))
logrus.Info(aurora.Red(err))
return
}
log.Println("Receive event", aurora.Green(event.EventKey), ":", aurora.Bold(event.EventData))
logrus.Info("Receive event", aurora.Green(event.EventKey), ":", aurora.Bold(event.EventData))
}
}

Expand All @@ -92,9 +92,9 @@ func listenResults(serviceID string, result string, output string) {
for {
result, err := stream.Recv()
if err != nil {
log.Println(aurora.Red(err))
logrus.Info(aurora.Red(err))
return
}
log.Println("Receive result", aurora.Green(result.TaskKey), aurora.Cyan(result.OutputKey), "with data", aurora.Bold(result.OutputData))
logrus.Info("Receive result", aurora.Green(result.TaskKey), aurora.Cyan(result.OutputKey), "with data", aurora.Bold(result.OutputData))
}
}
Loading