loomnetwork / loomchain

Loom DAppChain Engine
Other
166 stars 32 forks source link

Add metrics for RPC requests from tendermint #791

Open mattkanwisher opened 5 years ago

mattkanwisher commented 5 years ago

Similar to the InstrmentingEventHandler, we need to wrap all the http calls in rpc_server.go func RPCServer(qsvc QueryService, logger log.TMLogger, bus *QueryEventBus, bindAddr string) error { with metrics.

should be similar to this

// startPrometheusServer starts a Prometheus HTTP server, listening for metrics
// collectors on addr.
func (n *Node) startPrometheusServer(addr string) *http.Server {
    srv := &http.Server{
        Addr: addr,
        Handler: promhttp.InstrumentMetricHandler(
            prometheus.DefaultRegisterer, promhttp.HandlerFor(
                prometheus.DefaultGatherer,
                promhttp.HandlerOpts{MaxRequestsInFlight: n.config.Instrumentation.MaxOpenConnections},
            ),
        ),
    }
    go func() {
        if err := srv.ListenAndServe(); err != http.ErrServerClosed {
            // Error starting or closing listener:
            n.Logger.Error("Prometheus HTTP server ListenAndServe", "err", err)
        }
    }()
    return srv
}
enlight commented 5 years ago

Specifically these are the methods we should time:

"blockchain":           rpc.NewRPCFunc(BlockchainInfo, "minHeight,maxHeight"),
"block":                rpc.NewRPCFunc(Block, "height"),
"block_results":        rpc.NewRPCFunc(BlockResults, "height"),
"commit":               rpc.NewRPCFunc(Commit, "height"),
"tx":                   rpc.NewRPCFunc(Tx, "hash,prove"),
"tx_search":            rpc.NewRPCFunc(TxSearch, "query,prove,page,per_page"),
"validators":           rpc.NewRPCFunc(Validators, "height"),
"consensus_params":     rpc.NewRPCFunc(ConsensusParams, "height"),
"mempool_txs":          rpc.NewRPCFunc(MempoolTxs, "limit"),
"broadcast_tx_commit": rpc.NewRPCFunc(BroadcastTxCommit, "tx"),
"broadcast_tx_sync":   rpc.NewRPCFunc(BroadcastTxSync, "tx"),