Skip to content

Commit

Permalink
Merge pull request #227 from onflow/kan/access-node-metrics
Browse files Browse the repository at this point in the history
Kan/access node metrics
  • Loading branch information
Kay-Zee authored Dec 9, 2020
2 parents b48d87b + 9ebe36a commit 9a5942a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cmd/access/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func main() {
logTxTimeToExecuted bool
logTxTimeToFinalizedExecuted bool
retryEnabled bool
rpcMetricsEnabled bool
)

cmd.FlowNode(flow.RoleAccess.String()).
Expand All @@ -85,6 +86,7 @@ func main() {
flags.BoolVar(&logTxTimeToFinalizedExecuted, "log-tx-time-to-finalized-executed", false, "log transaction time to finalized and executed")
flags.BoolVar(&pingEnabled, "ping-enabled", false, "whether to enable the ping process that pings all other peers and report the connectivity to metrics")
flags.BoolVar(&retryEnabled, "retry-enabled", false, "whether to enable the retry mechanism at the access node level")
flags.BoolVar(&rpcMetricsEnabled, "rpc-metrics-enabled", false, "whether to enable the rpc metrics")
flags.StringVarP(&nodeInfoFile, "node-info-file", "", "", "full path to a json file which provides more details about nodes when reporting its reachability metrics")
}).
Module("collection node client", func(node *cmd.FlowNodeBuilder) error {
Expand Down Expand Up @@ -188,6 +190,7 @@ func main() {
transactionMetrics,
collectionGRPCPort,
retryEnabled,
rpcMetricsEnabled,
)
return rpcEng, nil
}).
Expand Down
2 changes: 1 addition & 1 deletion engine/access/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (suite *Suite) TestGetSealedTransaction() {
require.NoError(suite.T(), err)

rpcEng := rpc.New(suite.log, suite.state, rpc.Config{}, nil, nil, nil, blocks, headers, collections, transactions,
suite.chainID, metrics, 0, false)
suite.chainID, metrics, 0, false, false)

// create the ingest engine
ingestEng, err := ingestion.New(suite.log, suite.net, suite.state, suite.me, suite.request, blocks, headers, collections,
Expand Down
2 changes: 1 addition & 1 deletion engine/access/ingestion/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (suite *Suite) SetupTest() {
require.NoError(suite.T(), err)

rpcEng := rpc.New(log, suite.proto.state, rpc.Config{}, nil, nil, nil, suite.blocks, suite.headers, suite.collections,
suite.transactions, flow.Testnet, metrics.NewNoopCollector(), 0, false)
suite.transactions, flow.Testnet, metrics.NewNoopCollector(), 0, false, false)

eng, err := New(log, net, suite.proto.state, suite.me, suite.request, suite.blocks, suite.headers, suite.collections,
suite.transactions, metrics.NewNoopCollector(), collectionsToMarkFinalized, collectionsToMarkExecuted,
Expand Down
20 changes: 18 additions & 2 deletions engine/access/rpc/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"net/http"

grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/rs/zerolog"
"google.golang.org/grpc"

Expand Down Expand Up @@ -60,6 +61,7 @@ func New(log zerolog.Logger,
transactionMetrics module.TransactionMetrics,
collectionGRPCPort uint,
retryEnabled bool,
rpcMetricsEnabled bool,
) *Engine {

log = log.With().Str("engine", "rpc").Logger()
Expand All @@ -69,10 +71,19 @@ func New(log zerolog.Logger,
}

// create a GRPC server to serve GRPC clients
grpcServer := grpc.NewServer(
grpcOpts := []grpc.ServerOption{
grpc.MaxRecvMsgSize(config.MaxMsgSize),
grpc.MaxSendMsgSize(config.MaxMsgSize),
)
}
if rpcMetricsEnabled {
grpcOpts = append(
grpcOpts,
grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor),
grpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor),
)
}

grpcServer := grpc.NewServer(grpcOpts...)

// wrap the GRPC server with an HTTP proxy server to serve HTTP clients
httpServer := NewHTTPServer(grpcServer, config.HTTPListenAddr)
Expand Down Expand Up @@ -107,6 +118,11 @@ func New(log zerolog.Logger,
access.NewHandler(backend, chainID.Chain()),
)

if rpcMetricsEnabled {
// Not interested in legacy metrics, so initialize here
grpc_prometheus.Register(grpcServer)
}

// Register legacy gRPC handlers for backwards compatibility, to be removed at a later date
legacyaccessproto.RegisterAccessAPIServer(
eng.grpcServer,
Expand Down
1 change: 0 additions & 1 deletion fvm/state/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func TestAccounts_GetWithNoKeys(t *testing.T) {
})
}


func TestAccounts_GetPublicKey(t *testing.T) {

t.Run("non-existent key index", func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/golang/protobuf v1.4.2
github.com/google/go-cmp v0.5.2
github.com/google/uuid v1.1.1
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/golang-lru v0.5.4
github.com/improbable-eng/grpc-web v0.12.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
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/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU=
Expand Down

0 comments on commit 9a5942a

Please sign in to comment.