From fa62207dd4a6ecc8c5d970dcee8a3d0e893ab061 Mon Sep 17 00:00:00 2001 From: Silas Davis <silas@monax.io> Date: Tue, 21 Aug 2018 09:10:53 +0100 Subject: [PATCH] Rename RPC/TM and add safety to metrics Signed-off-by: Silas Davis <silas@monax.io> --- core/kernel.go | 6 +++--- integration/integration.go | 2 +- integration/rpcinfo/main_test.go | 4 ++-- rpc/config.go | 6 +++--- rpc/metrics/export.go | 5 +++++ rpc/metrics/server.go | 2 +- rpc/rpcinfo/info_server.go | 2 +- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/core/kernel.go b/core/kernel.go index f73125f6..316da522 100644 --- a/core/kernel.go +++ b/core/kernel.go @@ -197,10 +197,10 @@ func NewKernel(ctx context.Context, keyClient keys.KeyClient, privValidator tmTy }, }, { - Name: "RPC/tm", - Enabled: rpcConfig.TM.Enabled, + Name: "RPC/info", + Enabled: rpcConfig.Info.Enabled, Launch: func() (process.Process, error) { - server, err := rpcinfo.StartServer(kern.Service, "/websocket", rpcConfig.TM.ListenAddress, kern.Logger) + server, err := rpcinfo.StartServer(kern.Service, "/websocket", rpcConfig.Info.ListenAddress, kern.Logger) if err != nil { return nil, err } diff --git a/integration/integration.go b/integration/integration.go index 7c136f8a..883afde4 100644 --- a/integration/integration.go +++ b/integration/integration.go @@ -170,7 +170,7 @@ func NewTestConfig(genesisDoc *genesis.GenesisDoc) *config.BurrowConfig { cnf.Tendermint.ExternalAddress = cnf.Tendermint.ListenAddress cnf.RPC.GRPC.ListenAddress = GetLocalAddress() cnf.RPC.Metrics.ListenAddress = GetTCPLocalAddress() - cnf.RPC.TM.ListenAddress = GetTCPLocalAddress() + cnf.RPC.Info.ListenAddress = GetTCPLocalAddress() cnf.Keys.RemoteAddress = "" return cnf } diff --git a/integration/rpcinfo/main_test.go b/integration/rpcinfo/main_test.go index 29f3f474..dfd581c9 100644 --- a/integration/rpcinfo/main_test.go +++ b/integration/rpcinfo/main_test.go @@ -32,8 +32,8 @@ import ( var kern *core.Kernel var _ = integration.ClaimPorts() var testConfig = integration.NewTestConfig(rpctest.GenesisDoc) -var jsonRpcClient = rpcClient.NewJSONRPCClient(testConfig.RPC.TM.ListenAddress) -var httpClient = rpcClient.NewURIClient(testConfig.RPC.TM.ListenAddress) +var jsonRpcClient = rpcClient.NewJSONRPCClient(testConfig.RPC.Info.ListenAddress) +var httpClient = rpcClient.NewURIClient(testConfig.RPC.Info.ListenAddress) var clients = map[string]tmClient.RPCClient{ "JSONRPC": jsonRpcClient, "HTTP": httpClient, diff --git a/rpc/config.go b/rpc/config.go index 23bfbdbb..3763bb79 100644 --- a/rpc/config.go +++ b/rpc/config.go @@ -7,7 +7,7 @@ import "fmt" const localhost = "127.0.0.1" type RPCConfig struct { - TM *ServerConfig `json:",omitempty" toml:",omitempty"` + Info *ServerConfig `json:",omitempty" toml:",omitempty"` Profiler *ServerConfig `json:",omitempty" toml:",omitempty"` GRPC *ServerConfig `json:",omitempty" toml:",omitempty"` Metrics *MetricsConfig `json:",omitempty" toml:",omitempty"` @@ -37,14 +37,14 @@ type MetricsConfig struct { func DefaultRPCConfig() *RPCConfig { return &RPCConfig{ - TM: DefaultTMConfig(), + Info: DefaultInfoConfig(), Profiler: DefaultProfilerConfig(), GRPC: DefaultGRPCConfig(), Metrics: DefaultMetricsConfig(), } } -func DefaultTMConfig() *ServerConfig { +func DefaultInfoConfig() *ServerConfig { return &ServerConfig{ Enabled: true, ListenAddress: fmt.Sprintf("tcp://%s:26658", localhost), diff --git a/rpc/metrics/export.go b/rpc/metrics/export.go index 2487a0f7..2ea9d7b7 100644 --- a/rpc/metrics/export.go +++ b/rpc/metrics/export.go @@ -14,6 +14,7 @@ package metrics import ( + "fmt" "math" "github.com/hyperledger/burrow/rpc" @@ -107,6 +108,10 @@ func (e *Exporter) getBlocks() (*rpc.ResultBlocks, error) { return nil, err } + if !(len(res.BlockMetas) > 0) { + return nil, fmt.Errorf("no blocks returned") + } + return res, nil } diff --git a/rpc/metrics/server.go b/rpc/metrics/server.go index 5eab0754..b6dbe8b1 100644 --- a/rpc/metrics/server.go +++ b/rpc/metrics/server.go @@ -71,7 +71,7 @@ func StartServer(service *rpc.Service, pattern, listenAddress string, blockSampl prometheus.MustRegister(&exporter) mux := http.NewServeMux() - mux.Handle(pattern, prometheus.Handler()) + mux.Handle(pattern, server.RecoverAndLogHandler(prometheus.Handler(), logger)) srv, err := server.StartHTTPServer(listenAddress, mux, logger) if err != nil { diff --git a/rpc/rpcinfo/info_server.go b/rpc/rpcinfo/info_server.go index ff500e1b..3f51321f 100644 --- a/rpc/rpcinfo/info_server.go +++ b/rpc/rpcinfo/info_server.go @@ -24,7 +24,7 @@ import ( ) func StartServer(service *rpc.Service, pattern, listenAddress string, logger *logging.Logger) (*http.Server, error) { - logger = logger.With(structure.ComponentKey, "RPC_TM") + logger = logger.With(structure.ComponentKey, "RPC_Info") routes := GetRoutes(service, logger) mux := http.NewServeMux() wm := server.NewWebsocketManager(routes, logger) -- GitLab