Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

2 changes: 2 additions & 0 deletions beacon_node/client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct Config {
pub genesis_state_url: Option<String>,
pub genesis_state_url_timeout: Duration,
pub allow_insecure_genesis_sync: bool,
pub telemetry_sample_ratio: Option<f64> // for testing only
}

impl Default for Config {
Expand Down Expand Up @@ -107,6 +108,7 @@ impl Default for Config {
// This default value should always be overwritten by the CLI default value.
genesis_state_url_timeout: Duration::from_secs(60),
allow_insecure_genesis_sync: false,
telemetry_sample_ratio: None
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions book/src/help_bn.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ Options:
Override the OpenTelemetry service name. Defaults to 'lighthouse-bn'
for beacon node, 'lighthouse-vc' for validator client, or 'lighthouse'
for other subcommands.
--telemetry-trace-sample-rate <PERCENT>
OpenTelemetry trace sampling rate as a percentage (0-100). A value of
1 means 1% of traces are sampled. Lower values reduce resource
consumption. For more info see
https://opentelemetry.io/docs/concepts/sampling/#why-sampling
[default: 1]
--trusted-peers <TRUSTED_PEERS>
One or more comma-delimited trusted peer ids which always have the
highest score according to the peer scoring system.
Expand Down
6 changes: 6 additions & 0 deletions book/src/help_general.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ Options:
Override the OpenTelemetry service name. Defaults to 'lighthouse-bn'
for beacon node, 'lighthouse-vc' for validator client, or 'lighthouse'
for other subcommands.
--telemetry-trace-sample-rate <PERCENT>
OpenTelemetry trace sampling rate as a percentage (0-100). A value of
1 means 1% of traces are sampled. Lower values reduce resource
consumption. For more info see
https://opentelemetry.io/docs/concepts/sampling/#why-sampling
[default: 1]
-V, --version
Print version

Expand Down
6 changes: 6 additions & 0 deletions book/src/help_vc.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ Options:
Override the OpenTelemetry service name. Defaults to 'lighthouse-bn'
for beacon node, 'lighthouse-vc' for validator client, or 'lighthouse'
for other subcommands.
--telemetry-trace-sample-rate <PERCENT>
OpenTelemetry trace sampling rate as a percentage (0-100). A value of
1 means 1% of traces are sampled. Lower values reduce resource
consumption. For more info see
https://opentelemetry.io/docs/concepts/sampling/#why-sampling
[default: 1]
--validator-registration-batch-size <INTEGER>
Defines the number of validators per validator/register_validator
request sent to the BN. This value can be reduced to avoid timeouts
Expand Down
6 changes: 6 additions & 0 deletions book/src/help_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ Options:
Override the OpenTelemetry service name. Defaults to 'lighthouse-bn'
for beacon node, 'lighthouse-vc' for validator client, or 'lighthouse'
for other subcommands.
--telemetry-trace-sample-rate <PERCENT>
OpenTelemetry trace sampling rate as a percentage (0-100). A value of
1 means 1% of traces are sampled. Lower values reduce resource
consumption. For more info see
https://opentelemetry.io/docs/concepts/sampling/#why-sampling
[default: 1]

Flags:
--disable-log-timestamp
Expand Down
6 changes: 6 additions & 0 deletions book/src/help_vm_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ Options:
Override the OpenTelemetry service name. Defaults to 'lighthouse-bn'
for beacon node, 'lighthouse-vc' for validator client, or 'lighthouse'
for other subcommands.
--telemetry-trace-sample-rate <PERCENT>
OpenTelemetry trace sampling rate as a percentage (0-100). A value of
1 means 1% of traces are sampled. Lower values reduce resource
consumption. For more info see
https://opentelemetry.io/docs/concepts/sampling/#why-sampling
[default: 1]

Flags:
--disable-deposits
Expand Down
6 changes: 6 additions & 0 deletions book/src/help_vm_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ Options:
Override the OpenTelemetry service name. Defaults to 'lighthouse-bn'
for beacon node, 'lighthouse-vc' for validator client, or 'lighthouse'
for other subcommands.
--telemetry-trace-sample-rate <PERCENT>
OpenTelemetry trace sampling rate as a percentage (0-100). A value of
1 means 1% of traces are sampled. Lower values reduce resource
consumption. For more info see
https://opentelemetry.io/docs/concepts/sampling/#why-sampling
[default: 1]
--validators-file <PATH_TO_JSON_FILE>
The path to a JSON file containing a list of validators to be imported
to the validator client. This file is usually named "validators.json".
Expand Down
6 changes: 6 additions & 0 deletions book/src/help_vm_move.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ Options:
Override the OpenTelemetry service name. Defaults to 'lighthouse-bn'
for beacon node, 'lighthouse-vc' for validator client, or 'lighthouse'
for other subcommands.
--telemetry-trace-sample-rate <PERCENT>
OpenTelemetry trace sampling rate as a percentage (0-100). A value of
1 means 1% of traces are sampled. Lower values reduce resource
consumption. For more info see
https://opentelemetry.io/docs/concepts/sampling/#why-sampling
[default: 1]
--validators <STRING>
The validators to be moved. Either a list of 0x-prefixed validator
pubkeys or the keyword "all".
Expand Down
1 change: 1 addition & 0 deletions lighthouse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ network_utils = { workspace = true }
opentelemetry = { workspace = true }
opentelemetry-otlp = { workspace = true }
opentelemetry_sdk = { workspace = true }
mockall = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
Expand Down
31 changes: 30 additions & 1 deletion lighthouse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,23 @@ fn main() {
.global(true)
.display_order(0)
)
.arg(
Arg::new("telemetry-trace-sample-rate")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please write a test case for this flag. we have some example flag specific tests you can use as an example

.long("telemetry-trace-sample-rate")
.value_name("PERCENT")
.help(
"OpenTelemetry trace sampling rate as a percentage (0-100). \
A value of 1 means 1% of traces are sampled. \
Lower values reduce resource consumption. \
For more info see https://opentelemetry.io/docs/concepts/sampling/#why-sampling"
)
.requires("telemetry-collector-url")
.value_parser(clap::value_parser!(u8).range(0..=100))
.default_value("1")
.action(ArgAction::Set)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets set the default here explicitly via .default_value("1")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can also set a min and max value explicitly at the flag level

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure and we can use the range of value parser for min and max

.global(true)
.display_order(0)
)
.arg(
Arg::new("datadir")
.long("datadir")
Expand Down Expand Up @@ -657,6 +674,7 @@ fn run<E: EthSpec>(
.eth2_network_config(eth2_network_config)?
.build()?;

let mut telemetry_sample_ratio = None;
if let Some(telemetry_collector_url) = matches.get_one::<String>("telemetry-collector-url") {
let telemetry_layer = environment.runtime().block_on(async {
let exporter = opentelemetry_otlp::SpanExporter::builder()
Expand All @@ -675,8 +693,18 @@ fn run<E: EthSpec>(
_ => "lighthouse".to_string(),
});

// Calculate sample percent as a ratio (percentage / 100)
telemetry_sample_ratio = Some(matches
.get_one::<u8>("telemetry-trace-sample-rate")
.copied()
.unwrap_or(1) as f64 / 100.0);
let sampler = opentelemetry_sdk::trace::Sampler::ParentBased(Box::new(
opentelemetry_sdk::trace::Sampler::TraceIdRatioBased(telemetry_sample_ratio.unwrap()),
));

let provider = opentelemetry_sdk::trace::SdkTracerProvider::builder()
.with_batch_exporter(exporter)
.with_sampler(sampler)
.with_resource(
opentelemetry_sdk::Resource::builder()
.with_service_name(service_name)
Expand Down Expand Up @@ -823,6 +851,7 @@ fn run<E: EthSpec>(
let executor = context.executor.clone();
let mut config = beacon_node::get_config::<E>(matches, &context)?;
config.logger_config = logger_config;
config.telemetry_sample_ratio = telemetry_sample_ratio;
// Dump configs if `dump-config` or `dump-chain-config` flags are set
clap_utils::check_dump_configs::<_, E>(matches, &config, &context.eth2_config.spec)?;

Expand Down Expand Up @@ -868,4 +897,4 @@ fn run<E: EthSpec>(
ShutdownReason::Success(_) => Ok(()),
ShutdownReason::Failure(msg) => Err(msg.to_string()),
}
}
}
39 changes: 39 additions & 0 deletions lighthouse/tests/beacon_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2839,3 +2839,42 @@ fn invalid_block_roots_default_mainnet() {
assert!(config.chain.invalid_block_roots.is_empty());
})
}

#[test]
fn telemetry_sample_rate_default() {
let float_tolerance: f64 = 1e-3;
let expected_ratio = 0.01;

CommandLineTest::new()
.flag("telemetry-collector-url", Some("http://localhost:4317"))
.run_with_zero_port()
.with_config(|config| {
let actual_ratio = config.telemetry_sample_ratio.expect("telemetry_sample_ratio should be set");
assert!(
(actual_ratio - expected_ratio).abs() < float_tolerance,
"Expected {}, got {}",
expected_ratio,
actual_ratio
);
});
}

#[test]
fn telemetry_sample_rate_custom() {
let float_tolerance: f64 = 1e-3;
let expected_ratio = 0.05;

CommandLineTest::new()
.flag("telemetry-trace-sample-rate", Some("5"))
.flag("telemetry-collector-url", Some("http://localhost:4317"))
.run_with_zero_port()
.with_config(|config| {
let actual_ratio = config.telemetry_sample_ratio.expect("telemetry_sample_ratio should be set");
assert!(
(actual_ratio - expected_ratio).abs() < float_tolerance,
"Expected {}, got {}",
expected_ratio,
actual_ratio
);
});
}