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
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: 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: 0.01,
}
}
}
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
30 changes: 30 additions & 0 deletions 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")
.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)
.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 = 0.01; // default to 1%
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,19 @@ fn run<E: EthSpec>(
_ => "lighthouse".to_string(),
});

// Calculate sample percent as a ratio (percentage / 100)
telemetry_sample_ratio = (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),
));

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 @@ -824,6 +853,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
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;
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;
assert!(
(actual_ratio - expected_ratio).abs() < float_tolerance,
"Expected {}, got {}",
expected_ratio,
actual_ratio
);
});
}