add pyroscope (#4871)

* pyroscope

* fixup

* add pyroscope target

* fixins

* spellcheck

* rename 'pyroscoped' feature to 'pyroscope'

* build testnet binary with pyroscope feature

* Update Cargo.toml

Co-authored-by: Andronik <write@reusable.software>

* make args a string, resolve using std::net

* fixup

* remove --features pyroscope for testnet builds

Until the panics are fixed in upstream, this is sane.

* chore: bump pyroscope to 0.3.1

Fixes an underflow panic.

* Revert "remove --features pyroscope for testnet builds
"

This reverts commit 57dbdc7aa5f6427aeb1e3dfdfc97071c3a74851e.

* fix: Make sample rate a prime

Co-authored-by: Pierre Besson <pierre.besson@parity.io>
Co-authored-by: Andronik <write@reusable.software>
This commit is contained in:
Bernhard Schuster
2022-02-22 14:16:49 +01:00
committed by GitHub
parent 7adde98fb4
commit 1ba4af9f15
7 changed files with 152 additions and 3 deletions
+8 -1
View File
@@ -115,7 +115,14 @@ pub struct RunCmd {
/// Must be valid socket address, of format `IP:Port`
/// commonly `127.0.0.1:6831`.
#[clap(long)]
pub jaeger_agent: Option<std::net::SocketAddr>,
pub jaeger_agent: Option<String>,
/// Add the destination address to the `pyroscope` agent.
///
/// Must be valid socket address, of format `IP:Port`
/// commonly `127.0.0.1:4040`.
#[clap(long)]
pub pyroscope_server: Option<String>,
}
#[allow(missing_docs)]
+42 -1
View File
@@ -20,6 +20,7 @@ use log::info;
use sc_cli::{Role, RuntimeVersion, SubstrateCli};
use service::{self, IdentifyVariant};
use sp_core::crypto::Ss58AddressFormatRegistry;
use std::net::ToSocketAddrs;
pub use crate::error::Error;
pub use polkadot_performance_test::PerfCheckError;
@@ -266,7 +267,17 @@ where
info!("----------------------------");
}
let jaeger_agent = cli.run.jaeger_agent;
let jaeger_agent = if let Some(ref jaeger_agent) = cli.run.jaeger_agent {
Some(
jaeger_agent
.to_socket_addrs()
.map_err(Error::AddressResolutionFailure)?
.next()
.ok_or_else(|| Error::AddressResolutionMissing)?,
)
} else {
None
};
runner.run_node_until_exit(move |config| async move {
let role = config.role.clone();
@@ -293,6 +304,31 @@ where
pub fn run() -> Result<()> {
let cli: Cli = Cli::from_args();
#[cfg(feature = "pyroscope")]
let mut pyroscope_agent_maybe = if let Some(ref agent_addr) = cli.run.pyroscope_server {
let address = agent_addr
.to_socket_addrs()
.map_err(Error::AddressResolutionFailure)?
.next()
.ok_or_else(|| Error::AddressResolutionMissing)?;
// The pyroscope agent requires a `http://` prefix, so we just do that.
let mut agent = pyro::PyroscopeAgent::builder(
"http://".to_owned() + address.to_string().as_str(),
"polkadot".to_owned(),
)
.sample_rate(113)
.build()?;
agent.start();
Some(agent)
} else {
None
};
#[cfg(not(feature = "pyroscope"))]
if cli.run.pyroscope_server.is_some() {
return Err(Error::PyroscopeNotCompiledIn)
}
match &cli.subcommand {
None => run_node_inner(cli, service::RealOverseerGen, polkadot_node_metrics::logger_hook()),
Some(Subcommand::BuildSpec(cmd)) => {
@@ -509,5 +545,10 @@ pub fn run() -> Result<()> {
)
.into()),
}?;
#[cfg(feature = "pyroscope")]
if let Some(mut pyroscope_agent) = pyroscope_agent_maybe.take() {
pyroscope_agent.stop();
}
Ok(())
}
+14
View File
@@ -31,6 +31,20 @@ pub enum Error {
#[error(transparent)]
PerfCheck(#[from] polkadot_performance_test::PerfCheckError),
#[cfg(not(feature = "pyroscope"))]
#[error("Binary was not compiled with `--feature=pyroscope`")]
PyroscopeNotCompiledIn,
#[cfg(feature = "pyroscope")]
#[error("Failed to connect to pyroscope agent")]
PyroscopeError(#[from] pyro::error::PyroscopeError),
#[error("Failed to resolve provided URL")]
AddressResolutionFailure(#[from] std::io::Error),
#[error("URL did not resolve to anything")]
AddressResolutionMissing,
#[error("Other: {0}")]
Other(String),
}