diff --git a/Cargo.lock b/Cargo.lock index 56d3de489c..df4a1fbe34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11720,7 +11720,6 @@ name = "subspace-metrics" version = "0.1.0" dependencies = [ "actix-web", - "parking_lot 0.12.1", "prometheus", "prometheus-client 0.22.0", "tracing", @@ -11788,6 +11787,7 @@ dependencies = [ "hex-literal", "mimalloc", "parity-scale-codec", + "prometheus-client 0.22.0", "sc-chain-spec", "sc-cli", "sc-client-api", @@ -11814,12 +11814,14 @@ dependencies = [ "sp-messenger", "sp-runtime", "subspace-core-primitives", + "subspace-metrics", "subspace-networking", "subspace-proof-of-space", "subspace-runtime", "subspace-runtime-primitives", "subspace-service", "substrate-build-script-utils", + "substrate-prometheus-endpoint", "supports-color", "tempfile", "thiserror", @@ -12000,7 +12002,6 @@ dependencies = [ "static_assertions", "subspace-archiving", "subspace-core-primitives", - "subspace-metrics", "subspace-networking", "subspace-proof-of-space", "subspace-runtime-primitives", diff --git a/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs b/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs index b1c48ff026..31e79d230b 100644 --- a/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs +++ b/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs @@ -107,8 +107,8 @@ pub(crate) struct FarmingArgs { no_info: bool, /// Defines endpoints for the prometheus metrics server. It doesn't start without at least /// one specified endpoint. Format: 127.0.0.1:8080 - #[arg(long, alias = "metrics-endpoint")] - metrics_endpoints: Vec, + #[arg(long, aliases = ["metrics-endpoint", "metrics-endpoints"])] + prometheus_listen_on: Vec, /// Defines how many sectors farmer will download concurrently, allows to limit memory usage of /// the plotting process, defaults to `--sector-encoding-concurrency` + 1 to download future /// sector ahead of time @@ -314,7 +314,7 @@ where dev, tmp, mut disk_farms, - metrics_endpoints, + prometheus_listen_on, sector_downloading_concurrency, sector_encoding_concurrency, farm_during_initial_plotting, @@ -384,7 +384,7 @@ where // Metrics let mut prometheus_metrics_registry = Registry::default(); let farmer_metrics = FarmerMetrics::new(&mut prometheus_metrics_registry); - let metrics_endpoints_are_specified = !metrics_endpoints.is_empty(); + let should_start_prometheus_server = !prometheus_listen_on.is_empty(); let (node, mut node_runner) = { if dsn.bootstrap_nodes.is_empty() { @@ -399,14 +399,14 @@ where Arc::downgrade(&readers_and_pieces), node_client.clone(), piece_cache.clone(), - metrics_endpoints_are_specified.then_some(&mut prometheus_metrics_registry), + should_start_prometheus_server.then_some(&mut prometheus_metrics_registry), )? }; - let _prometheus_worker = if metrics_endpoints_are_specified { + let _prometheus_worker = if should_start_prometheus_server { let prometheus_task = start_prometheus_metrics_server( - metrics_endpoints, - RegistryAdapter::Libp2p(prometheus_metrics_registry), + prometheus_listen_on, + RegistryAdapter::PrometheusClient(prometheus_metrics_registry), )?; let join_handle = tokio::spawn(prometheus_task); diff --git a/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs b/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs index 7a94dd59cc..2584a54788 100644 --- a/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs +++ b/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs @@ -227,6 +227,7 @@ fn main() -> Result<(), Error> { let consensus_chain_node = subspace_service::new_full::( consensus_chain_config, partial_components, + None, true, SlotProportion::new(3f32 / 4f32), ) diff --git a/crates/subspace-networking/examples/metrics.rs b/crates/subspace-networking/examples/metrics.rs index 30cfc55364..51abd409bb 100644 --- a/crates/subspace-networking/examples/metrics.rs +++ b/crates/subspace-networking/examples/metrics.rs @@ -32,7 +32,7 @@ async fn main() { match start_prometheus_metrics_server( vec![prometheus_metrics_server_address], - RegistryAdapter::Libp2p(metric_registry), + RegistryAdapter::PrometheusClient(metric_registry), ) { Err(err) => { error!( diff --git a/crates/subspace-networking/src/bin/subspace-bootstrap-node/main.rs b/crates/subspace-networking/src/bin/subspace-bootstrap-node/main.rs index e7988fa43a..35cf9447b5 100644 --- a/crates/subspace-networking/src/bin/subspace-bootstrap-node/main.rs +++ b/crates/subspace-networking/src/bin/subspace-bootstrap-node/main.rs @@ -85,8 +85,8 @@ enum Command { external_addresses: Vec, /// Defines endpoints for the prometheus metrics server. It doesn't start without at least /// one specified endpoint. Format: 127.0.0.1:8080 - #[arg(long, alias = "metrics-endpoint")] - metrics_endpoints: Vec, + #[arg(long, aliases = ["metrics-endpoint", "metrics-endpoints"])] + prometheus_listen_on: Vec, }, /// Generate a new keypair GenerateKeypair { @@ -149,7 +149,7 @@ async fn main() -> Result<(), Box> { allow_private_ips, protocol_version, external_addresses, - metrics_endpoints, + prometheus_listen_on, } => { debug!( "Libp2p protocol stack instantiated with version: {} ", @@ -160,10 +160,10 @@ async fn main() -> Result<(), Box> { let keypair = identity::Keypair::from(decoded_keypair); // Metrics - let metrics_endpoints_are_specified = !metrics_endpoints.is_empty(); + let should_start_prometheus_server = !prometheus_listen_on.is_empty(); let mut metrics_registry = Registry::default(); let dsn_metrics_registry = - metrics_endpoints_are_specified.then_some(&mut metrics_registry); + should_start_prometheus_server.then_some(&mut metrics_registry); let known_peers_registry_config = KnownPeersManagerConfig { enable_known_peers_source: false, @@ -217,11 +217,11 @@ async fn main() -> Result<(), Box> { info!("Subspace Bootstrap Node started"); - let prometheus_task = metrics_endpoints_are_specified + let prometheus_task = should_start_prometheus_server .then(|| { start_prometheus_metrics_server( - metrics_endpoints, - RegistryAdapter::Libp2p(metrics_registry), + prometheus_listen_on, + RegistryAdapter::PrometheusClient(metrics_registry), ) }) .transpose()?; diff --git a/crates/subspace-node/Cargo.toml b/crates/subspace-node/Cargo.toml index 2c0bb85204..892d9f2159 100644 --- a/crates/subspace-node/Cargo.toml +++ b/crates/subspace-node/Cargo.toml @@ -40,6 +40,7 @@ hex = "0.4.3" hex-literal = "0.4.1" mimalloc = "0.1.39" parity-scale-codec = "3.6.9" +prometheus-client = "0.22.0" sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } sc-cli = { version = "0.10.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8", default-features = false } sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } @@ -66,11 +67,13 @@ sp-keystore = { version = "0.27.0", git = "https://github.com/subspace/polkadot- sp-messenger = { version = "0.1.0", path = "../../domains/primitives/messenger" } sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" } +subspace-metrics = { version = "0.1.0", path = "../../shared/subspace-metrics" } subspace-networking = { version = "0.1.0", path = "../subspace-networking" } subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space" } subspace-runtime = { version = "0.1.0", path = "../subspace-runtime" } subspace-runtime-primitives = { version = "0.1.0", path = "../subspace-runtime-primitives" } subspace-service = { version = "0.1.0", path = "../subspace-service" } +substrate-prometheus-endpoint = { git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" } supports-color = "2.1.0" tempfile = "3.9.0" thiserror = "1.0.56" diff --git a/crates/subspace-node/src/commands/run.rs b/crates/subspace-node/src/commands/run.rs index 80bead8ccd..d02ae9c1f2 100644 --- a/crates/subspace-node/src/commands/run.rs +++ b/crates/subspace-node/src/commands/run.rs @@ -23,6 +23,7 @@ use sc_utils::mpsc::tracing_unbounded; use sp_core::traits::SpawnEssentialNamed; use sp_messenger::messages::ChainId; use std::env; +use subspace_metrics::{start_prometheus_metrics_server, RegistryAdapter}; use subspace_runtime::{Block, RuntimeApi}; use tracing::{debug, error, info, info_span, warn}; @@ -86,6 +87,7 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> { dev, pot_external_entropy, storage_monitor, + mut prometheus_configuration, } = create_consensus_chain_configuration(consensus, enable_color, domain_options.is_some())?; let maybe_domain_configuration = domain_options @@ -130,6 +132,11 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> { let full_node_fut = subspace_service::new_full::( subspace_configuration, partial_components, + prometheus_configuration + .as_mut() + .map(|prometheus_configuration| { + &mut prometheus_configuration.prometheus_registry + }), true, SlotProportion::new(3f32 / 4f32), ); @@ -274,6 +281,26 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> { consensus_chain_node.network_starter.start_network(); + if let Some(prometheus_configuration) = prometheus_configuration.take() { + let metrics_server = start_prometheus_metrics_server( + vec![prometheus_configuration.listen_on], + RegistryAdapter::Both( + prometheus_configuration.prometheus_registry, + prometheus_configuration.substrate_registry, + ), + ) + .map_err(|error| Error::SubspaceService(error.into()))? + .map(|error| { + debug!(?error, "Metrics server error."); + }); + + consensus_chain_node.task_manager.spawn_handle().spawn( + "metrics-server", + None, + metrics_server, + ); + }; + consensus_chain_node.task_manager }; diff --git a/crates/subspace-node/src/commands/run/consensus.rs b/crates/subspace-node/src/commands/run/consensus.rs index 7bd57f7829..dec69ba3a2 100644 --- a/crates/subspace-node/src/commands/run/consensus.rs +++ b/crates/subspace-node/src/commands/run/consensus.rs @@ -1,6 +1,7 @@ use crate::commands::run::shared::RpcOptions; use crate::{chain_spec, derive_pot_external_entropy, Error}; use clap::Parser; +use prometheus_client::registry::Registry; use sc_chain_spec::GenericChainSpec; use sc_cli::{ generate_node_name, Cors, NodeKeyParams, NodeKeyType, RpcMethods, TelemetryParams, @@ -408,6 +409,12 @@ pub(super) struct ConsensusChainOptions { timekeeper_options: TimekeeperOptions, } +pub(super) struct PrometheusConfiguration { + pub(super) listen_on: SocketAddr, + pub(super) prometheus_registry: Registry, + pub(super) substrate_registry: substrate_prometheus_endpoint::Registry, +} + pub(super) struct ConsensusChainConfiguration { pub(super) maybe_tmp_dir: Option, pub(super) subspace_configuration: SubspaceConfiguration, @@ -415,6 +422,7 @@ pub(super) struct ConsensusChainConfiguration { /// External entropy, used initially when PoT chain starts to derive the first seed pub(super) pot_external_entropy: Vec, pub(super) storage_monitor: StorageMonitorParams, + pub(super) prometheus_configuration: Option, } pub(super) fn create_consensus_chain_configuration( @@ -640,6 +648,7 @@ pub(super) fn create_consensus_chain_configuration( } }; + let substrate_registry = consensus_chain_config.prometheus_registry().cloned(); Ok(ConsensusChainConfiguration { maybe_tmp_dir, subspace_configuration: SubspaceConfiguration { @@ -655,5 +664,12 @@ pub(super) fn create_consensus_chain_configuration( dev, pot_external_entropy, storage_monitor, + prometheus_configuration: prometheus_listen_on.zip(substrate_registry).map( + |(listen_on, substrate_registry)| PrometheusConfiguration { + listen_on, + prometheus_registry: Registry::default(), + substrate_registry, + }, + ), }) } diff --git a/crates/subspace-service/Cargo.toml b/crates/subspace-service/Cargo.toml index 114af2c6bd..19d4a7256d 100644 --- a/crates/subspace-service/Cargo.toml +++ b/crates/subspace-service/Cargo.toml @@ -73,7 +73,6 @@ sp-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/subspac static_assertions = "1.1.0" subspace-archiving = { version = "0.1.0", path = "../subspace-archiving" } subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" } -subspace-metrics = { version = "0.1.0", path = "../../shared/subspace-metrics" } subspace-networking = { version = "0.1.0", path = "../subspace-networking" } subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space" } subspace-runtime-primitives = { version = "0.1.0", path = "../subspace-runtime-primitives" } diff --git a/crates/subspace-service/src/config.rs b/crates/subspace-service/src/config.rs index 1fa9e6d6dc..0b03b00b9f 100644 --- a/crates/subspace-service/src/config.rs +++ b/crates/subspace-service/src/config.rs @@ -1,6 +1,5 @@ use crate::dsn::DsnConfig; use crate::sync_from_dsn::DsnSyncPieceGetter; -use prometheus_client::registry::Registry; use sc_chain_spec::ChainSpec; use sc_network::config::{ MultiaddrWithPeerId, NetworkConfiguration, NodeKeyConfig, SetConfig, SyncMode, TransportConfig, @@ -223,8 +222,6 @@ pub enum SubspaceNetworking { node: Node, /// Bootstrap nodes used (that can be also sent to the farmer over RPC) bootstrap_nodes: Vec, - /// DSN metrics registry - metrics_registry: Option, }, /// Networking must be instantiated internally Create { diff --git a/crates/subspace-service/src/dsn.rs b/crates/subspace-service/src/dsn.rs index cad4b87b76..b69ccdbf37 100644 --- a/crates/subspace-service/src/dsn.rs +++ b/crates/subspace-service/src/dsn.rs @@ -71,13 +71,10 @@ pub struct DsnConfig { pub(crate) fn create_dsn_instance( dsn_protocol_version: String, dsn_config: DsnConfig, - enable_metrics: bool, -) -> Result<(Node, NodeRunner<()>, Option), DsnConfigurationError> { + prometheus_registry: Option<&mut Registry>, +) -> Result<(Node, NodeRunner<()>), DsnConfigurationError> { trace!("Subspace networking starting."); - let mut metrics_registry = Registry::default(); - let dsn_metrics_registry = enable_metrics.then_some(&mut metrics_registry); - let networking_parameters_registry = { let network_path = dsn_config.network_path; @@ -101,7 +98,7 @@ pub(crate) fn create_dsn_instance( let keypair = dsn_config.keypair.clone(); let default_networking_config = - subspace_networking::Config::new(dsn_protocol_version, keypair, (), dsn_metrics_registry); + subspace_networking::Config::new(dsn_protocol_version, keypair, (), prometheus_registry); let networking_config = subspace_networking::Config { keypair: dsn_config.keypair.clone(), @@ -126,13 +123,5 @@ pub(crate) fn create_dsn_instance( ..default_networking_config }; - subspace_networking::construct(networking_config) - .map(|(node, node_runner)| { - ( - node, - node_runner, - enable_metrics.then_some(metrics_registry), - ) - }) - .map_err(Into::into) + subspace_networking::construct(networking_config).map_err(Into::into) } diff --git a/crates/subspace-service/src/lib.rs b/crates/subspace-service/src/lib.rs index 311a820826..82c0e735c3 100644 --- a/crates/subspace-service/src/lib.rs +++ b/crates/subspace-service/src/lib.rs @@ -45,6 +45,7 @@ use futures::FutureExt; use jsonrpsee::RpcModule; use pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi; use parking_lot::Mutex; +use prometheus_client::registry::Registry; use sc_basic_authorship::ProposerFactory; use sc_client_api::execution_extensions::ExtensionsFactory; use sc_client_api::{ @@ -104,7 +105,6 @@ use std::sync::Arc; use std::time::Duration; use subspace_core_primitives::crypto::kzg::{embedded_kzg_settings, Kzg}; use subspace_core_primitives::{BlockNumber, PotSeed, REWARD_SIGNING_CONTEXT}; -use subspace_metrics::{start_prometheus_metrics_server, RegistryAdapter}; use subspace_networking::libp2p::multiaddr::Protocol; use subspace_networking::utils::piece_provider::PieceProvider; use subspace_proof_of_space::Table; @@ -144,10 +144,6 @@ pub enum Error { #[error(transparent)] Telemetry(#[from] sc_telemetry::Error), - /// Prometheus error. - #[error(transparent)] - Prometheus(#[from] substrate_prometheus_endpoint::PrometheusError), - /// Subspace networking (DSN) error. #[error(transparent)] SubspaceDsn(#[from] DsnConfigurationError), @@ -626,6 +622,7 @@ type FullNode = NewFull>; pub async fn new_full( mut config: SubspaceConfiguration, partial_components: PartialComponents, + prometheus_registry: Option<&mut Registry>, enable_rpc_extensions: bool, block_proposal_slot_portion: SlotProportion, ) -> Result, Error> @@ -666,12 +663,11 @@ where } = other; let offchain_indexing_enabled = config.offchain_worker.indexing_enabled; - let (node, bootstrap_nodes, dsn_metrics_registry) = match config.subspace_networking { + let (node, bootstrap_nodes) = match config.subspace_networking { SubspaceNetworking::Reuse { node, bootstrap_nodes, - metrics_registry, - } => (node, bootstrap_nodes, metrics_registry), + } => (node, bootstrap_nodes), SubspaceNetworking::Create { config: dsn_config } => { let dsn_protocol_version = hex::encode(client.chain_info().genesis_hash); @@ -681,10 +677,10 @@ where "Setting DSN protocol version..." ); - let (node, mut node_runner, dsn_metrics_registry) = create_dsn_instance( + let (node, mut node_runner) = create_dsn_instance( dsn_protocol_version, dsn_config.clone(), - config.base.prometheus_config.is_some(), + prometheus_registry, )?; info!("Subspace networking initialized: Node ID is {}", node.id()); @@ -714,7 +710,7 @@ where ), ); - (node, dsn_config.bootstrap_nodes, dsn_metrics_registry) + (node, dsn_config.bootstrap_nodes) } }; @@ -1039,24 +1035,7 @@ where } // We replace the Substrate implementation of metrics server with our own. - if let Some(prometheus_config) = config.base.prometheus_config.take() { - let registry = if let Some(dsn_metrics_registry) = dsn_metrics_registry { - RegistryAdapter::Both(dsn_metrics_registry, prometheus_config.registry) - } else { - RegistryAdapter::Substrate(prometheus_config.registry) - }; - - let metrics_server = - start_prometheus_metrics_server(vec![prometheus_config.port], registry)?.map(|error| { - debug!(?error, "Metrics server error."); - }); - - task_manager.spawn_handle().spawn( - "node-metrics-server", - Some("node-metrics-server"), - metrics_server, - ); - }; + config.base.prometheus_config.take(); let rpc_handlers = sc_service::spawn_tasks(SpawnTasksParams { network: network_service.clone(), diff --git a/shared/subspace-metrics/Cargo.toml b/shared/subspace-metrics/Cargo.toml index e387e23f50..61b89ff70c 100644 --- a/shared/subspace-metrics/Cargo.toml +++ b/shared/subspace-metrics/Cargo.toml @@ -16,7 +16,6 @@ include = [ [dependencies] actix-web = "4.4.1" -parking_lot = "0.12.1" prometheus = { version = "0.13.0", default-features = false } prometheus-client = "0.22.0" tracing = "0.1.40" diff --git a/shared/subspace-metrics/src/lib.rs b/shared/subspace-metrics/src/lib.rs index 22aada5907..c569d68e5b 100644 --- a/shared/subspace-metrics/src/lib.rs +++ b/shared/subspace-metrics/src/lib.rs @@ -1,74 +1,50 @@ #![warn(missing_docs)] //! This Rust module serves as a bridge between two different Prometheus metrics libraries -//! used within our frameworks — Substrate and Libp2p. +//! used: `prometheus-client` (official library) and TiKV's `prometheus` client (used by Substrate). //! The module exposes a web server endpoint at "/metrics" that outputs metrics in Prometheus -//! format. It adapts metrics from either or both of the following libraries: -//! - Official Rust Prometheus client (registry aliased as Libp2pMetricsRegistry) -//! - TiKV's Prometheus client (registry aliased as SubstrateMetricsRegistry) +//! format. It adapts metrics from either or both of those libraries. use actix_web::http::StatusCode; use actix_web::web::Data; use actix_web::{get, App, HttpResponse, HttpServer}; -use parking_lot::Mutex; -use prometheus::{Encoder, Registry as SubstrateMetricsRegistry, TextEncoder}; +use prometheus::{Registry as SubstrateRegistry, TextEncoder}; use prometheus_client::encoding::text::encode; -use prometheus_client::registry::Registry as Libp2pMetricsRegistry; +use prometheus_client::registry::Registry as PrometheusClientRegistry; use std::error::Error; use std::future::Future; use std::io::ErrorKind; use std::net::SocketAddr; -use std::ops::DerefMut; -use std::sync::Arc; use tracing::{error, info, warn}; -type SharedRegistry = Arc>; - -/// An metrics registry adapter for Libp2p and Substrate frameworks. +/// Metrics registry adapter for prometheus-client and Substrate frameworks. /// It specifies which metrics registry or registries are in use. pub enum RegistryAdapter { - /// Uses only the Libp2p metrics registry. - Libp2p(Libp2pMetricsRegistry), + /// Uses only the prometheus-client metrics registry. + PrometheusClient(PrometheusClientRegistry), /// Uses only the Substrate metrics registry. - Substrate(SubstrateMetricsRegistry), - /// We use both Substrate and Libp2p metrics registries. - Both(Libp2pMetricsRegistry, SubstrateMetricsRegistry), + Substrate(SubstrateRegistry), + /// We use both Substrate and prometheus-client metrics registries. + Both(PrometheusClientRegistry, SubstrateRegistry), } #[get("/metrics")] -async fn metrics(registry: Data) -> Result> { - let encoded_metrics = match registry.lock().deref_mut() { - RegistryAdapter::Libp2p(libp2p_registry) => { - let mut encoded = String::new(); - encode(&mut encoded, libp2p_registry)?; +async fn metrics(registry: Data) -> Result> { + let mut encoded_metrics = String::new(); - encoded + match &**registry { + RegistryAdapter::PrometheusClient(libp2p_registry) => { + encode(&mut encoded_metrics, libp2p_registry)?; } RegistryAdapter::Substrate(substrate_registry) => { - let encoder = TextEncoder::new(); - let mut encoded = String::new(); - unsafe { - encoder.encode(&substrate_registry.gather(), &mut encoded.as_mut_vec())?; - } - encoded + TextEncoder::new().encode_utf8(&substrate_registry.gather(), &mut encoded_metrics)?; } RegistryAdapter::Both(libp2p_registry, substrate_registry) => { // We combine outputs of both metrics registries in one string. - let mut libp2p_encoded = String::new(); - encode(&mut libp2p_encoded, libp2p_registry)?; - - let encoder = TextEncoder::new(); - let mut substrate_encoded = String::new(); - unsafe { - encoder.encode( - &substrate_registry.gather(), - &mut substrate_encoded.as_mut_vec(), - )?; - } - - // libp2p string contains #EOF, order is important here. - substrate_encoded + &libp2p_encoded + TextEncoder::new().encode_utf8(&substrate_registry.gather(), &mut encoded_metrics)?; + // prometheus-client string contains #EOF, order is important here + encode(&mut encoded_metrics, libp2p_registry)?; } - }; + } let resp = HttpResponse::build(StatusCode::OK).body(encoded_metrics); @@ -80,8 +56,7 @@ pub fn start_prometheus_metrics_server( mut endpoints: Vec, registry: RegistryAdapter, ) -> std::io::Result>> { - let shared_registry = Arc::new(Mutex::new(registry)); - let data = Data::new(shared_registry); + let data = Data::new(registry); let app_factory = move || App::new().app_data(data.clone()).service(metrics); let result = HttpServer::new(app_factory.clone())