Skip to content

Commit

Permalink
Merge pull request #1580 from mesg-foundation/feature/prometheus-stats
Browse files Browse the repository at this point in the history
Engine execution stats
  • Loading branch information
Nicolas Mahé authored Jan 13, 2020
2 parents 5154ea2 + 146147a commit 6d279c5
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 1 deletion.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/go-bindata/go-bindata v0.0.0-20181025070752-41975c0ccc30
github.com/go-kit/kit v0.9.0
github.com/go-playground/locales v0.13.0
github.com/go-playground/universal-translator v0.17.0
github.com/gogo/protobuf v1.3.1
Expand All @@ -28,6 +29,7 @@ require (
github.com/google/uuid v1.1.1 // indirect
github.com/gorilla/mux v1.7.3
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/huandu/xstrings v1.2.0 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
Expand All @@ -44,7 +46,7 @@ require (
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v0.1.1 // indirect
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/prometheus/client_golang v1.1.0 // indirect
github.com/prometheus/client_golang v1.1.0
github.com/pseudomuto/protoc-gen-doc v1.3.0
github.com/pseudomuto/protokit v0.2.0 // indirect
github.com/rakyll/statik v0.1.6 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmo
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg=
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
Expand Down
2 changes: 2 additions & 0 deletions scripts/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function start_engine {
--network name=$MESG_TENDERMINT_NETWORK \
--publish $MESG_SERVER_PORT:50052 \
--publish $MESG_TENDERMINT_PORT:26656 \
--publish 26657:26657 \
--publish 26660:26660 \
mesg/engine:local
}

Expand Down
2 changes: 2 additions & 0 deletions sdk/execution/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (s *Backend) Create(request cosmostypes.Request, msg msgCreateExecution) (*
if err != nil {
return nil, err
}
m.InProgress.Add(1)
store.Set(exec.Hash, value)
return exec, nil
}
Expand Down Expand Up @@ -159,6 +160,7 @@ func (s *Backend) Update(request cosmostypes.Request, msg msgUpdateExecution) (*
if err != nil {
return nil, err
}
m.Completed.Add(1)
store.Set(exec.Hash, value)
return exec, nil
}
Expand Down
56 changes: 56 additions & 0 deletions sdk/execution/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package executionsdk

import (
"github.com/go-kit/kit/metrics"
prometheus "github.com/go-kit/kit/metrics/prometheus"
stdprometheus "github.com/prometheus/client_golang/prometheus"
)

var m *metric

type metric struct {
Created metrics.Counter
PreSigned metrics.Counter
Signed metrics.Counter
InProgress metrics.Counter
Completed metrics.Counter
}

func newMetric() *metric {
return &metric{
Created: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: "mesg",
Subsystem: "execution",
Name: "created",
Help: "executions created",
}, []string{}),
Signed: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: "mesg",
Subsystem: "execution",
Name: "signed",
Help: "executions signed",
}, []string{}),
PreSigned: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: "mesg",
Subsystem: "execution",
Name: "pre_signed",
Help: "executions pre signed",
}, []string{}),
InProgress: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: "mesg",
Subsystem: "execution",
Name: "in_progress",
Help: "executions in progress",
}, []string{}),
Completed: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: "mesg",
Subsystem: "execution",
Name: "completed",
Help: "executions completed",
}, []string{}),
}
}

func init() {
m = newMetric()
}
3 changes: 3 additions & 0 deletions sdk/execution/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ func New(client *cosmos.Client, serviceSDK *servicesdk.SDK, instanceSDK *instanc

// Create creates a new execution.
func (s *SDK) Create(req *api.CreateExecutionRequest) (*execution.Execution, error) {
m.Created.Add(1)
acc, err := s.client.GetAccount()
if err != nil {
return nil, err
}
m.PreSigned.Add(1)
msg := newMsgCreateExecution(req, acc.GetAddress())
tx, err := s.client.BuildAndBroadcastMsg(msg)
m.Signed.Add(1)
if err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions server/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/mesg-foundation/engine/config"
protobuf_api "github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/sdk"
Expand Down Expand Up @@ -46,13 +47,16 @@ func (s *Server) Serve(address string) error {
keepaliveOpt,
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
grpc_logrus.StreamServerInterceptor(logrus.StandardLogger().WithField("module", "grpc")),
grpc_prometheus.StreamServerInterceptor,
)),
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
grpc_logrus.UnaryServerInterceptor(logrus.StandardLogger().WithField("module", "grpc")),
grpc_prometheus.UnaryServerInterceptor,
validateInterceptor,
)),
)
s.register()
grpc_prometheus.Register(s.instance)
logrus.WithField("module", "grpc").Info("server listens on ", ln.Addr())
return s.instance.Serve(ln)
}
Expand Down

0 comments on commit 6d279c5

Please sign in to comment.