Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fix the browser node and ensure it doesn't colour the informant output (
Browse files Browse the repository at this point in the history
#6457)

* Fix browser informant

* Fix documentation

* Add an informant_output_format function to the cli config

* Wrap informant output format in an option

* Revert batch verifier

* Remove wasm-timer from primitives io cargo lock

* Drop informant_output_format function

* derive debug for output format
  • Loading branch information
expenses authored Jun 23, 2020
1 parent c771821 commit ad7b5ef
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 50 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ pub trait CliConfiguration: Sized {
announce_block: self.announce_block()?,
role,
base_path: Some(base_path),
informant_output_format: Default::default(),
})
}

Expand Down
29 changes: 26 additions & 3 deletions client/informant/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,37 @@ use parking_lot::Mutex;
mod display;

/// The format to print telemetry output in.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct OutputFormat {
/// Enable color output in logs.
/// Enable color output in logs. True by default.
pub enable_color: bool,
/// Add a prefix before every log line
/// Defines the informant's prefix for the logs. An empty string by default.
///
/// By default substrate will show logs without a prefix. Example:
///
/// ```text
/// 2020-05-28 15:11:06 ✨ Imported #2 (0xc21c…2ca8)
/// 2020-05-28 15:11:07 💤 Idle (0 peers), best: #2 (0xc21c…2ca8), finalized #0 (0x7299…e6df), ⬇ 0 ⬆ 0
/// ```
///
/// But you can define a prefix by setting this string. This will output:
///
/// ```text
/// 2020-05-28 15:11:06 ✨ [Prefix] Imported #2 (0xc21c…2ca8)
/// 2020-05-28 15:11:07 💤 [Prefix] Idle (0 peers), best: #2 (0xc21c…2ca8), finalized #0 (0x7299…e6df), ⬇ 0 ⬆ 0
/// ```
pub prefix: String,
}

impl Default for OutputFormat {
fn default() -> Self {
Self {
enable_color: true,
prefix: String::new(),
}
}
}

/// Marker trait for a type that implements `TransactionPool` and `MallocSizeOf` on `not(target_os = "unknown")`.
#[cfg(target_os = "unknown")]
pub trait TransactionPoolAndMaybeMallogSizeOf: TransactionPool {}
Expand Down
46 changes: 1 addition & 45 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ pub struct ServiceBuilder<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
remote_backend: Option<Arc<dyn RemoteBlockchain<TBl>>>,
marker: PhantomData<(TBl, TRtApi)>,
block_announce_validator_builder: Option<Box<dyn FnOnce(Arc<TCl>) -> Box<dyn BlockAnnounceValidator<TBl> + Send> + Send>>,
informant_prefix: String,
}

/// A utility trait for building an RPC extension given a `DenyUnsafe` instance.
Expand Down Expand Up @@ -366,7 +365,6 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> {
rpc_extensions_builder: Box::new(|_| ()),
remote_backend: None,
block_announce_validator_builder: None,
informant_prefix: Default::default(),
marker: PhantomData,
})
}
Expand Down Expand Up @@ -450,7 +448,6 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> {
rpc_extensions_builder: Box::new(|_| ()),
remote_backend: Some(remote_blockchain),
block_announce_validator_builder: None,
informant_prefix: Default::default(),
marker: PhantomData,
})
}
Expand Down Expand Up @@ -545,7 +542,6 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
rpc_extensions_builder: self.rpc_extensions_builder,
remote_backend: self.remote_backend,
block_announce_validator_builder: self.block_announce_validator_builder,
informant_prefix: self.informant_prefix,
marker: self.marker,
})
}
Expand Down Expand Up @@ -591,7 +587,6 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
rpc_extensions_builder: self.rpc_extensions_builder,
remote_backend: self.remote_backend,
block_announce_validator_builder: self.block_announce_validator_builder,
informant_prefix: self.informant_prefix,
marker: self.marker,
})
}
Expand Down Expand Up @@ -630,7 +625,6 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
rpc_extensions_builder: self.rpc_extensions_builder,
remote_backend: self.remote_backend,
block_announce_validator_builder: self.block_announce_validator_builder,
informant_prefix: self.informant_prefix,
marker: self.marker,
})
}
Expand Down Expand Up @@ -697,7 +691,6 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
rpc_extensions_builder: self.rpc_extensions_builder,
remote_backend: self.remote_backend,
block_announce_validator_builder: self.block_announce_validator_builder,
informant_prefix: self.informant_prefix,
marker: self.marker,
})
}
Expand Down Expand Up @@ -754,7 +747,6 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
rpc_extensions_builder: self.rpc_extensions_builder,
remote_backend: self.remote_backend,
block_announce_validator_builder: self.block_announce_validator_builder,
informant_prefix: self.informant_prefix,
marker: self.marker,
})
}
Expand Down Expand Up @@ -792,7 +784,6 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
rpc_extensions_builder: Box::new(rpc_extensions_builder),
remote_backend: self.remote_backend,
block_announce_validator_builder: self.block_announce_validator_builder,
informant_prefix: self.informant_prefix,
marker: self.marker,
})
}
Expand Down Expand Up @@ -838,43 +829,9 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
rpc_extensions_builder: self.rpc_extensions_builder,
remote_backend: self.remote_backend,
block_announce_validator_builder: Some(Box::new(block_announce_validator_builder)),
informant_prefix: self.informant_prefix,
marker: self.marker,
})
}

/// Defines the informant's prefix for the logs. An empty string by default.
///
/// By default substrate will show logs without a prefix. Example:
///
/// ```text
/// 2020-05-28 15:11:06 ✨ Imported #2 (0xc21c…2ca8)
/// 2020-05-28 15:11:07 💤 Idle (0 peers), best: #2 (0xc21c…2ca8), finalized #0 (0x7299…e6df), ⬇ 0 ⬆ 0
/// ```
///
/// But you can define a prefix by using this function. Example:
///
/// ```rust,ignore
/// service.with_informant_prefix("[Prefix] ".to_string());
/// ```
///
/// This will output:
///
/// ```text
/// 2020-05-28 15:11:06 ✨ [Prefix] Imported #2 (0xc21c…2ca8)
/// 2020-05-28 15:11:07 💤 [Prefix] Idle (0 peers), best: #2 (0xc21c…2ca8), finalized #0 (0x7299…e6df), ⬇ 0 ⬆ 0
/// ```
pub fn with_informant_prefix(
self,
informant_prefix: String,
) -> Result<ServiceBuilder<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
TExPool, TRpc, Backend>, Error>
where TSc: Clone, TFchr: Clone {
Ok(ServiceBuilder {
informant_prefix: informant_prefix,
..self
})
}
}

/// Implemented on `ServiceBuilder`. Allows running block commands, such as import/export/validate
Expand Down Expand Up @@ -990,7 +947,6 @@ ServiceBuilder<
rpc_extensions_builder,
remote_backend,
block_announce_validator_builder,
informant_prefix,
} = self;

sp_session::generate_initial_session_keys(
Expand Down Expand Up @@ -1142,7 +1098,7 @@ ServiceBuilder<
client.clone(),
network_status_sinks.clone(),
transaction_pool.clone(),
sc_informant::OutputFormat { enable_color: true, prefix: informant_prefix },
config.informant_output_format,
));

Ok(Service {
Expand Down
2 changes: 2 additions & 0 deletions client/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ pub struct Configuration {
pub announce_block: bool,
/// Base path of the configuration
pub base_path: Option<BasePath>,
/// Configuration of the output format that the informant uses.
pub informant_output_format: sc_informant::OutputFormat,
}

/// Type for tasks spawned by the executor.
Expand Down
1 change: 1 addition & 0 deletions client/service/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ fn node_config<G: RuntimeGenesis + 'static, E: ChainSpecExtension + Clone + 'sta
max_runtime_instances: 8,
announce_block: true,
base_path: Some(BasePath::new(root)),
informant_output_format: Default::default(),
}
}

Expand Down
1 change: 1 addition & 0 deletions primitives/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ codec = { package = "parity-scale-codec", version = "1.3.1", features = ["derive
parking_lot = "0.10.0"
serde = { version = "1.0", features = ["derive"] }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.8.0-rc3"}
wasm-timer = "0.2.4"

[dev-dependencies]
sp-test-primitives = { version = "2.0.0-rc3", path = "../../test-primitives" }
Expand Down
2 changes: 1 addition & 1 deletion primitives/consensus/common/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ pub(crate) fn import_single_block_metered<B: BlockT, V: Verifier<B>, Transaction
r => return Ok(r), // Any other successful result means that the block is already imported.
}

let started = std::time::Instant::now();
let started = wasm_timer::Instant::now();
let (mut import_block, maybe_keys) = verifier.verify(block_origin, header, justification, block.body)
.map_err(|msg| {
if let Some(ref peer) = peer {
Expand Down
3 changes: 2 additions & 1 deletion primitives/consensus/common/src/offline_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
//! Tracks offline validators.

use std::collections::HashMap;
use std::time::{Instant, Duration};
use std::time::Duration;
use wasm_timer::Instant;

// time before we report a validator.
const REPORT_TIME: Duration = Duration::from_secs(60 * 5);
Expand Down
4 changes: 4 additions & 0 deletions utils/browser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ where
max_runtime_instances: 8,
announce_block: true,
base_path: None,
informant_output_format: sc_informant::OutputFormat {
enable_color: false,
prefix: String::new(),
},
};

Ok(config)
Expand Down

0 comments on commit ad7b5ef

Please sign in to comment.