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

Commit 8cee4fe

Browse files
authored
Make verbosity level mandatory with telemetry opt (#5057)
* Make verbosity level mandatory instead of defaulting to 0 when using --telemetry-url * Update README docs * Change TelemetryError struct to enum * Return TelemetryParsingError instead of a Boxed dyn error * Replace spaces by tabs * Add example of expected format for telemetry-url * Remove UrlParsingError; Call to_string instead of parse for TelemetryEndpoints url
1 parent aeee195 commit 8cee4fe

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

bin/node-template/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ cargo run -- \
5656
--chain=local \
5757
--alice \
5858
--node-key 0000000000000000000000000000000000000000000000000000000000000001 \
59-
--telemetry-url ws://telemetry.polkadot.io:1024 \
59+
--telemetry-url 'ws://telemetry.polkadot.io:1024 0' \
6060
--validator
6161
```
6262

@@ -69,7 +69,7 @@ cargo run -- \
6969
--chain=local \
7070
--bob \
7171
--port 30334 \
72-
--telemetry-url ws://telemetry.polkadot.io:1024 \
72+
--telemetry-url 'ws://telemetry.polkadot.io:1024 0' \
7373
--validator
7474
```
7575

client/cli/src/commands/runcmd.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use std::path::PathBuf;
1818
use std::net::SocketAddr;
1919
use std::fs;
20+
use std::fmt;
2021
use log::info;
2122
use structopt::{StructOpt, clap::arg_enum};
2223
use names::{Generator, Name};
@@ -172,8 +173,8 @@ pub struct RunCmd {
172173
///
173174
/// This flag can be passed multiple times as a means to specify multiple
174175
/// telemetry endpoints. Verbosity levels range from 0-9, with 0 denoting
175-
/// the least verbosity. If no verbosity level is specified the default is
176-
/// 0.
176+
/// the least verbosity.
177+
/// Expected format is 'URL VERBOSITY', e.g. `--telemetry-url 'wss://foo/bar 0'`.
177178
#[structopt(long = "telemetry-url", value_name = "URL VERBOSITY", parse(try_from_str = parse_telemetry_endpoints))]
178179
pub telemetry_endpoints: Vec<(String, u8)>,
179180

@@ -565,16 +566,30 @@ fn interface_str(
565566
}
566567
}
567568

568-
/// Default to verbosity level 0, if none is provided.
569-
fn parse_telemetry_endpoints(s: &str) -> Result<(String, u8), Box<dyn std::error::Error>> {
569+
#[derive(Debug)]
570+
enum TelemetryParsingError {
571+
MissingVerbosity,
572+
VerbosityParsingError(std::num::ParseIntError),
573+
}
574+
575+
impl std::error::Error for TelemetryParsingError {}
576+
577+
impl fmt::Display for TelemetryParsingError {
578+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
579+
match &*self {
580+
TelemetryParsingError::MissingVerbosity => write!(f, "Verbosity level missing"),
581+
TelemetryParsingError::VerbosityParsingError(e) => write!(f, "{}", e),
582+
}
583+
}
584+
}
585+
586+
fn parse_telemetry_endpoints(s: &str) -> Result<(String, u8), TelemetryParsingError> {
570587
let pos = s.find(' ');
571588
match pos {
572-
None => {
573-
Ok((s.to_owned(), 0))
574-
},
589+
None => Err(TelemetryParsingError::MissingVerbosity),
575590
Some(pos_) => {
576-
let verbosity = s[pos_ + 1..].parse()?;
577-
let url = s[..pos_].parse()?;
591+
let url = s[..pos_].to_string();
592+
let verbosity = s[pos_ + 1..].parse().map_err(TelemetryParsingError::VerbosityParsingError)?;
578593
Ok((url, verbosity))
579594
}
580595
}

docs/README.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ cargo run --release \-- \
291291
--chain=local \
292292
--alice \
293293
--node-key 0000000000000000000000000000000000000000000000000000000000000001 \
294-
--telemetry-url ws://telemetry.polkadot.io:1024 \
294+
--telemetry-url 'ws://telemetry.polkadot.io:1024 0' \
295295
--validator
296296

297297
In the second terminal, we'll run the following to start Bob's Substrate node on a different TCP port of 30334, and with his chain database stored locally at `/tmp/bob`. We'll specify a value for the `--bootnodes` option that will connect his node to Alice's Bootnode ID on TCP port 30333:
@@ -303,7 +303,7 @@ cargo run --release \-- \
303303
--chain=local \
304304
--bob \
305305
--port 30334 \
306-
--telemetry-url ws://telemetry.polkadot.io:1024 \
306+
--telemetry-url 'ws://telemetry.polkadot.io:1024 0' \
307307
--validator
308308

309309
Additional Substrate CLI usage options are available and may be shown by running `cargo run \-- --help`.

0 commit comments

Comments
 (0)