config: rename prof_laddr to pprof_laddr and move it to rpc (#5315)

* config: rename prof_laddr to pprof_laddr and move it to rpc

also, remove `/unsafe_start_cpu_profiler`, `/unsafe_stop_cpu_profiler`
and `/unsafe_write_heap_profile` in favor of pprof server functionality.

Closes #5303

* update changelog

* log start
This commit is contained in:
Anton Kaliaev
2020-09-01 11:54:21 +04:00
committed by GitHub
parent 8a1404b70e
commit 43c3e4265b
10 changed files with 31 additions and 69 deletions

View File

@@ -8,6 +8,10 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
- [crypto/secp256k1] \#5280 `secp256k1` has been removed from the Tendermint repo. (@marbar3778) - [crypto/secp256k1] \#5280 `secp256k1` has been removed from the Tendermint repo. (@marbar3778)
- CLI/RPC/Config
- [config] \#5315 Rename `prof_laddr` to `pprof_laddr` and move it to `rpc` section (@melekes)
- [rpc] \#5315 Remove `/unsafe_start_cpu_profiler`, `/unsafe_stop_cpu_profiler` and `/unsafe_write_heap_profile`. Please use pprof functionality instead (@melekes)
## FEATURES ## FEATURES
- [privval] \#5239 Add `chainID` to requests from client. (@marbar3778) - [privval] \#5239 Add `chainID` to requests from client. (@marbar3778)

View File

@@ -144,6 +144,13 @@ All requests are now accompanied by the chainID from the network.
This is a optional field and can be ignored by key management systems. It This is a optional field and can be ignored by key management systems. It
is recommended to check the chainID if using the same key management system for multiple chains. is recommended to check the chainID if using the same key management system for multiple chains.
### RPC
`/unsafe_start_cpu_profiler`, `/unsafe_stop_cpu_profiler` and
`/unsafe_write_heap_profile` were removed. Please use pprof server, which can
be enabled through `--rpc.pprof_laddr=X` flag or `pprof_laddr=X` config setting
in the rpc section.
## v0.33.4 ## v0.33.4
### Go API ### Go API

View File

@@ -58,6 +58,7 @@ func AddNodeFlags(cmd *cobra.Command) {
config.RPC.GRPCListenAddress, config.RPC.GRPCListenAddress,
"GRPC listen address (BroadcastTx only). Port required") "GRPC listen address (BroadcastTx only). Port required")
cmd.Flags().Bool("rpc.unsafe", config.RPC.Unsafe, "Enabled unsafe rpc methods") cmd.Flags().Bool("rpc.unsafe", config.RPC.Unsafe, "Enabled unsafe rpc methods")
cmd.Flags().String("rpc.pprof_laddr", config.RPC.PprofListenAddress, "pprof listen address (https://golang.org/pkg/net/http/pprof)")
// p2p flags // p2p flags
cmd.Flags().String( cmd.Flags().String(

View File

@@ -210,9 +210,6 @@ type BaseConfig struct { //nolint: maligned
// Mechanism to connect to the ABCI application: socket | grpc // Mechanism to connect to the ABCI application: socket | grpc
ABCI string `mapstructure:"abci"` ABCI string `mapstructure:"abci"`
// TCP or UNIX socket address for the profiling server to listen on
ProfListenAddress string `mapstructure:"prof_laddr"`
// If true, query the ABCI app on connecting to a new peer // If true, query the ABCI app on connecting to a new peer
// so the app can decide if we should keep the connection or not // so the app can decide if we should keep the connection or not
FilterPeers bool `mapstructure:"filter_peers"` // false FilterPeers bool `mapstructure:"filter_peers"` // false
@@ -230,7 +227,6 @@ func DefaultBaseConfig() BaseConfig {
ABCI: "socket", ABCI: "socket",
LogLevel: DefaultPackageLogLevels(), LogLevel: DefaultPackageLogLevels(),
LogFormat: LogFormatPlain, LogFormat: LogFormatPlain,
ProfListenAddress: "",
FastSyncMode: true, FastSyncMode: true,
FilterPeers: false, FilterPeers: false,
DBBackend: "goleveldb", DBBackend: "goleveldb",
@@ -383,6 +379,9 @@ type RPCConfig struct {
// NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server. // NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server.
// Otherwise, HTTP server is run. // Otherwise, HTTP server is run.
TLSKeyFile string `mapstructure:"tls_key_file"` TLSKeyFile string `mapstructure:"tls_key_file"`
// pprof listen address (https://golang.org/pkg/net/http/pprof)
PprofListenAddress string `mapstructure:"pprof_laddr"`
} }
// DefaultRPCConfig returns a default configuration for the RPC server // DefaultRPCConfig returns a default configuration for the RPC server

View File

@@ -139,9 +139,6 @@ node_key_file = "{{ js .BaseConfig.NodeKey }}"
# Mechanism to connect to the ABCI application: socket | grpc # Mechanism to connect to the ABCI application: socket | grpc
abci = "{{ .BaseConfig.ABCI }}" abci = "{{ .BaseConfig.ABCI }}"
# TCP or UNIX socket address for the profiling server to listen on
prof_laddr = "{{ .BaseConfig.ProfListenAddress }}"
# If true, query the ABCI app on connecting to a new peer # If true, query the ABCI app on connecting to a new peer
# so the app can decide if we should keep the connection or not # so the app can decide if we should keep the connection or not
filter_peers = {{ .BaseConfig.FilterPeers }} filter_peers = {{ .BaseConfig.FilterPeers }}
@@ -232,6 +229,9 @@ tls_cert_file = "{{ .RPC.TLSCertFile }}"
# Otherwise, HTTP server is run. # Otherwise, HTTP server is run.
tls_key_file = "{{ .RPC.TLSKeyFile }}" tls_key_file = "{{ .RPC.TLSKeyFile }}"
# pprof listen address (https://golang.org/pkg/net/http/pprof)
pprof_laddr = "{{ .RPC.PprofListenAddress }}"
####################################################### #######################################################
### P2P Configuration Options ### ### P2P Configuration Options ###
####################################################### #######################################################

View File

@@ -92,9 +92,6 @@ node_key_file = "config/node_key.json"
# Mechanism to connect to the ABCI application: socket | grpc # Mechanism to connect to the ABCI application: socket | grpc
abci = "socket" abci = "socket"
# TCP or UNIX socket address for the profiling server to listen on
prof_laddr = ""
# If true, query the ABCI app on connecting to a new peer # If true, query the ABCI app on connecting to a new peer
# so the app can decide if we should keep the connection or not # so the app can decide if we should keep the connection or not
filter_peers = false filter_peers = false
@@ -185,6 +182,9 @@ tls_cert_file = ""
# Otherwise, HTTP server is run. # Otherwise, HTTP server is run.
tls_key_file = "" tls_key_file = ""
# pprof listen address (https://golang.org/pkg/net/http/pprof)
pprof_laddr = ""
####################################################### #######################################################
### P2P Configuration Options ### ### P2P Configuration Options ###
####################################################### #######################################################

View File

@@ -787,9 +787,10 @@ func NewNode(config *cfg.Config,
pexReactor = createPEXReactorAndAddToSwitch(addrBook, config, sw, logger) pexReactor = createPEXReactorAndAddToSwitch(addrBook, config, sw, logger)
} }
if config.ProfListenAddress != "" { if config.RPC.PprofListenAddress != "" {
go func() { go func() {
logger.Error("Profile server", "err", http.ListenAndServe(config.ProfListenAddress, nil)) logger.Info("Starting pprof server", "laddr", config.RPC.PprofListenAddress)
logger.Error("pprof server error", "err", http.ListenAndServe(config.RPC.PprofListenAddress, nil))
}() }()
} }

View File

@@ -1,9 +1,6 @@
package core package core
import ( import (
"os"
"runtime/pprof"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
) )
@@ -13,44 +10,3 @@ func UnsafeFlushMempool(ctx *rpctypes.Context) (*ctypes.ResultUnsafeFlushMempool
env.Mempool.Flush() env.Mempool.Flush()
return &ctypes.ResultUnsafeFlushMempool{}, nil return &ctypes.ResultUnsafeFlushMempool{}, nil
} }
var profFile *os.File
// UnsafeStartCPUProfiler starts a pprof profiler using the given filename.
func UnsafeStartCPUProfiler(ctx *rpctypes.Context, filename string) (*ctypes.ResultUnsafeProfile, error) {
var err error
profFile, err = os.Create(filename)
if err != nil {
return nil, err
}
err = pprof.StartCPUProfile(profFile)
if err != nil {
return nil, err
}
return &ctypes.ResultUnsafeProfile{}, nil
}
// UnsafeStopCPUProfiler stops the running pprof profiler.
func UnsafeStopCPUProfiler(ctx *rpctypes.Context) (*ctypes.ResultUnsafeProfile, error) {
pprof.StopCPUProfile()
if err := profFile.Close(); err != nil {
return nil, err
}
return &ctypes.ResultUnsafeProfile{}, nil
}
// UnsafeWriteHeapProfile dumps a heap profile to the given filename.
func UnsafeWriteHeapProfile(ctx *rpctypes.Context, filename string) (*ctypes.ResultUnsafeProfile, error) {
memProfFile, err := os.Create(filename)
if err != nil {
return nil, err
}
if err := pprof.WriteHeapProfile(memProfFile); err != nil {
return nil, err
}
if err := memProfFile.Close(); err != nil {
return nil, err
}
return &ctypes.ResultUnsafeProfile{}, nil
}

View File

@@ -25,7 +25,6 @@ Available endpoints:
/health /health
/unconfirmed_txs /unconfirmed_txs
/unsafe_flush_mempool /unsafe_flush_mempool
/unsafe_stop_cpu_profiler
/validators /validators
Endpoints that require arguments: Endpoints that require arguments:
@@ -40,8 +39,6 @@ Endpoints that require arguments:
/dial_persistent_peers?persistent_peers=_ /dial_persistent_peers?persistent_peers=_
/subscribe?event=_ /subscribe?event=_
/tx?hash=_&prove=_ /tx?hash=_&prove=_
/unsafe_start_cpu_profiler?filename=_
/unsafe_write_heap_profile?filename=_
/unsubscribe?event=_ /unsubscribe?event=_
``` ```
*/ */

View File

@@ -6,6 +6,7 @@ import (
// TODO: better system than "unsafe" prefix // TODO: better system than "unsafe" prefix
// Routes is a map of available routes.
var Routes = map[string]*rpc.RPCFunc{ var Routes = map[string]*rpc.RPCFunc{
// subscribe/unsubscribe are reserved for websocket events. // subscribe/unsubscribe are reserved for websocket events.
"subscribe": rpc.NewWSRPCFunc(Subscribe, "query"), "subscribe": rpc.NewWSRPCFunc(Subscribe, "query"),
@@ -45,14 +46,10 @@ var Routes = map[string]*rpc.RPCFunc{
"broadcast_evidence": rpc.NewRPCFunc(BroadcastEvidence, "evidence"), "broadcast_evidence": rpc.NewRPCFunc(BroadcastEvidence, "evidence"),
} }
// AddUnsafeRoutes adds unsafe routes.
func AddUnsafeRoutes() { func AddUnsafeRoutes() {
// control API // control API
Routes["dial_seeds"] = rpc.NewRPCFunc(UnsafeDialSeeds, "seeds") Routes["dial_seeds"] = rpc.NewRPCFunc(UnsafeDialSeeds, "seeds")
Routes["dial_peers"] = rpc.NewRPCFunc(UnsafeDialPeers, "peers,persistent") Routes["dial_peers"] = rpc.NewRPCFunc(UnsafeDialPeers, "peers,persistent")
Routes["unsafe_flush_mempool"] = rpc.NewRPCFunc(UnsafeFlushMempool, "") Routes["unsafe_flush_mempool"] = rpc.NewRPCFunc(UnsafeFlushMempool, "")
// profiler API
Routes["unsafe_start_cpu_profiler"] = rpc.NewRPCFunc(UnsafeStartCPUProfiler, "filename")
Routes["unsafe_stop_cpu_profiler"] = rpc.NewRPCFunc(UnsafeStopCPUProfiler, "")
Routes["unsafe_write_heap_profile"] = rpc.NewRPCFunc(UnsafeWriteHeapProfile, "filename")
} }