Skip to content

Commit 707cbf4

Browse files
authored
Use pyroscope sample rate as config parameter (#3603)
## Motivation Right now for local runs, 100 samples per second seems to be a bit too aggressive and causes some local issues (connections fail, etc) ## Proposal Decrease local runs to have 10 samples per second, and make that part of the config ## Test Plan Ran locally, was significantly seeing connection failures before, now they're gone ## Release Plan - Nothing to do / These changes follow the usual release cycle.
1 parent 0e545df commit 707cbf4

File tree

8 files changed

+44
-1
lines changed

8 files changed

+44
-1
lines changed

configuration/compose/validator.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ port = 19100
99
metrics_port = 21100
1010
pyroscope_host = "docker-pyroscope"
1111
pyroscope_port = 4040
12+
pyroscope_sample_rate = 100
1213
internal_host = "proxy"
1314
internal_port = 20100
1415
[external_protocol]
@@ -22,24 +23,28 @@ port = 19100
2223
metrics_port = 21100
2324
pyroscope_host = "docker-pyroscope"
2425
pyroscope_port = 4040
26+
pyroscope_sample_rate = 100
2527

2628
[[shards]]
2729
host = "docker-shard-2"
2830
port = 19100
2931
metrics_port = 21100
3032
pyroscope_host = "docker-pyroscope"
3133
pyroscope_port = 4040
34+
pyroscope_sample_rate = 100
3235

3336
[[shards]]
3437
host = "docker-shard-3"
3538
port = 19100
3639
metrics_port = 21100
3740
pyroscope_host = "docker-pyroscope"
3841
pyroscope_port = 4040
42+
pyroscope_sample_rate = 100
3943

4044
[[shards]]
4145
host = "docker-shard-4"
4246
port = 19100
4347
metrics_port = 21100
4448
pyroscope_host = "docker-pyroscope"
4549
pyroscope_port = 4040
50+
pyroscope_sample_rate = 100

linera-rpc/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub struct ShardConfig {
5656
pub pyroscope_host: String,
5757
/// The port on which pyroscope is served.
5858
pub pyroscope_port: Option<u16>,
59+
/// The sample rate for pyroscope.
60+
pub pyroscope_sample_rate: u32,
5961
}
6062

6163
impl ShardConfig {
@@ -121,6 +123,8 @@ pub struct ValidatorInternalNetworkPreConfig<P> {
121123
pub pyroscope_host: String,
122124
/// The port of the pyroscope server.
123125
pub pyroscope_port: u16,
126+
/// The sample rate for pyroscope.
127+
pub pyroscope_sample_rate: u32,
124128
}
125129

126130
impl<P> ValidatorInternalNetworkPreConfig<P> {
@@ -134,6 +138,7 @@ impl<P> ValidatorInternalNetworkPreConfig<P> {
134138
metrics_port: self.metrics_port,
135139
pyroscope_host: self.pyroscope_host.clone(),
136140
pyroscope_port: self.pyroscope_port,
141+
pyroscope_sample_rate: self.pyroscope_sample_rate,
137142
}
138143
}
139144
}

linera-service/src/cli_wrappers/local_kubernetes_net.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ impl LocalKubernetesNet {
342342
let internal_port = 20100;
343343
let metrics_port = 21100;
344344
let pyroscope_port = 4040;
345+
let pyroscope_sample_rate = 10;
345346
let mut content = format!(
346347
r#"
347348
server_config_path = "server_{n}.json"
@@ -352,6 +353,7 @@ impl LocalKubernetesNet {
352353
metrics_port = {metrics_port}
353354
pyroscope_host = "linera-core-pyroscope.default.svc.cluster.local"
354355
pyroscope_port = {pyroscope_port}
356+
pyroscope_sample_rate = {pyroscope_sample_rate}
355357
[external_protocol]
356358
Grpc = "ClearText"
357359
[internal_protocol]
@@ -371,6 +373,7 @@ impl LocalKubernetesNet {
371373
metrics_port = {shard_metrics_port}
372374
pyroscope_host = "linera-core-pyroscope.default.svc.cluster.local"
373375
pyroscope_port = {shard_pyroscope_port}
376+
pyroscope_sample_rate = {pyroscope_sample_rate}
374377
"#
375378
));
376379
}

linera-service/src/cli_wrappers/local_net.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ impl LocalNet {
432432
let internal_port = Self::internal_port(n);
433433
let metrics_port = Self::proxy_metrics_port(n);
434434
let pyroscope_port = Self::proxy_pyroscope_port(n);
435+
let pyroscope_sample_rate = 100;
435436
let external_protocol = self.network.external.toml();
436437
let internal_protocol = self.network.internal.toml();
437438
let external_host = self.network.external.localhost();
@@ -447,6 +448,7 @@ impl LocalNet {
447448
metrics_port = {metrics_port}
448449
pyroscope_port = {pyroscope_port}
449450
pyroscope_host = "{pyroscope_host}"
451+
pyroscope_sample_rate = {pyroscope_sample_rate}
450452
external_protocol = {external_protocol}
451453
internal_protocol = {internal_protocol}
452454
"#
@@ -464,6 +466,7 @@ impl LocalNet {
464466
metrics_port = {shard_metrics_port}
465467
pyroscope_host = "{pyroscope_host}"
466468
pyroscope_port = {shard_pyroscope_port}
469+
pyroscope_sample_rate = {pyroscope_sample_rate}
467470
"#
468471
));
469472
}

linera-service/src/proxy/grpc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ where
261261
self.pyroscope_address(),
262262
"proxy".to_string(),
263263
shutdown_signal.clone(),
264+
self.0.internal_config.pyroscope_sample_rate,
264265
)?;
265266
}
266267

linera-service/src/proxy/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ where
257257
self.get_pyroscope_address(),
258258
"proxy".to_string(),
259259
shutdown_signal.clone(),
260+
self.internal_config.pyroscope_sample_rate,
260261
)?;
261262
}
262263

linera-service/src/pyroscope_server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ pub fn start_pyroscope(
1010
address: String,
1111
application_name: String,
1212
shutdown_signal: CancellationToken,
13+
sample_rate: u32,
1314
) -> Result<(), PyroscopeError> {
1415
info!("Starting to push pyroscope data to {:?}", address);
15-
let pprof_config = PprofConfig::new().sample_rate(100);
16+
let pprof_config = PprofConfig::new().sample_rate(sample_rate);
1617
let backend_impl = pprof_backend(pprof_config);
1718

1819
let agent = PyroscopeAgent::builder(address, application_name)

linera-service/src/server.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ impl ServerContext {
120120
self.pyroscope_address(shard.pyroscope_host, port),
121121
"server".to_string(),
122122
shutdown_signal.clone(),
123+
shard.pyroscope_sample_rate,
123124
)?;
124125
}
125126

@@ -175,6 +176,7 @@ impl ServerContext {
175176
self.pyroscope_address(shard.pyroscope_host, port),
176177
"server".to_string(),
177178
shutdown_signal.clone(),
179+
shard.pyroscope_sample_rate,
178180
)?;
179181
}
180182

@@ -303,6 +305,9 @@ struct ValidatorOptions {
303305
/// The port for the pyroscope endpoint
304306
pyroscope_port: u16,
305307

308+
/// The sample rate for pyroscope.
309+
pyroscope_sample_rate: u32,
310+
306311
/// The host of the proxy in the internal network.
307312
internal_host: String,
308313

@@ -341,6 +346,7 @@ fn make_server_config<R: CryptoRng>(
341346
metrics_port: options.metrics_port,
342347
pyroscope_host: options.pyroscope_host,
343348
pyroscope_port: options.pyroscope_port,
349+
pyroscope_sample_rate: options.pyroscope_sample_rate,
344350
};
345351
let validator = ValidatorConfig {
346352
network,
@@ -491,6 +497,10 @@ enum ServerCommand {
491497
/// shard number.
492498
#[arg(long)]
493499
pyroscope_port: Option<String>,
500+
501+
/// The sample rate for pyroscope.
502+
#[arg(long, default_value = "100")]
503+
pyroscope_sample_rate: u32,
494504
},
495505
}
496506

@@ -670,6 +680,7 @@ async fn run(options: ServerOptions) {
670680
metrics_port,
671681
pyroscope_host,
672682
pyroscope_port,
683+
pyroscope_sample_rate,
673684
} => {
674685
let mut server_config =
675686
persistent::File::<ValidatorServerConfig>::read(&server_config_path)
@@ -681,6 +692,7 @@ async fn run(options: ServerOptions) {
681692
metrics_port,
682693
pyroscope_host,
683694
pyroscope_port,
695+
pyroscope_sample_rate,
684696
)
685697
.expect("Failed to generate shard configs");
686698
server_config.internal_network.shards = shards;
@@ -698,6 +710,7 @@ fn generate_shard_configs(
698710
metrics_port: Option<String>,
699711
pyroscope_host: String,
700712
pyroscope_port: Option<String>,
713+
pyroscope_sample_rate: u32,
701714
) -> anyhow::Result<Vec<ShardConfig>> {
702715
let mut shards = Vec::new();
703716
let len = num_shards.len();
@@ -736,6 +749,7 @@ fn generate_shard_configs(
736749
metrics_port,
737750
pyroscope_host,
738751
pyroscope_port,
752+
pyroscope_sample_rate,
739753
};
740754
shards.push(shard);
741755
}
@@ -759,6 +773,7 @@ mod test {
759773
metrics_port = 5000
760774
pyroscope_host = "pyroscope_host"
761775
pyroscope_port = 4000
776+
pyroscope_sample_rate = 100
762777
external_protocol = { Simple = "Tcp" }
763778
internal_protocol = { Simple = "Udp" }
764779
@@ -768,13 +783,15 @@ mod test {
768783
metrics_port = 5001
769784
pyroscope_host = "pyroscope_host"
770785
pyroscope_port = 4001
786+
pyroscope_sample_rate = 100
771787
772788
[[shards]]
773789
host = "host2"
774790
port = 9002
775791
metrics_port = 5002
776792
pyroscope_host = "pyroscope_host"
777793
pyroscope_port = 4002
794+
pyroscope_sample_rate = 100
778795
"#;
779796
let options: ValidatorOptions = toml::from_str(toml_str).unwrap();
780797
assert_eq!(
@@ -790,20 +807,23 @@ mod test {
790807
metrics_port: 5000,
791808
pyroscope_host: "pyroscope_host".into(),
792809
pyroscope_port: 4000,
810+
pyroscope_sample_rate: 100,
793811
shards: vec![
794812
ShardConfig {
795813
host: "host1".into(),
796814
port: 9001,
797815
metrics_port: Some(5001),
798816
pyroscope_host: "pyroscope_host".into(),
799817
pyroscope_port: Some(4001),
818+
pyroscope_sample_rate: 100,
800819
},
801820
ShardConfig {
802821
host: "host2".into(),
803822
port: 9002,
804823
metrics_port: Some(5002),
805824
pyroscope_host: "pyroscope_host".into(),
806825
pyroscope_port: Some(4002),
826+
pyroscope_sample_rate: 100,
807827
},
808828
],
809829
}
@@ -820,6 +840,7 @@ mod test {
820840
Some("11%%".into()),
821841
"pyroscope_host".into(),
822842
Some("40%%".into()),
843+
100,
823844
)
824845
.unwrap(),
825846
vec![
@@ -829,13 +850,15 @@ mod test {
829850
metrics_port: Some(1101),
830851
pyroscope_host: "pyroscope_host".into(),
831852
pyroscope_port: Some(4001),
853+
pyroscope_sample_rate: 100,
832854
},
833855
ShardConfig {
834856
host: "host02".into(),
835857
port: 1002,
836858
metrics_port: Some(1102),
837859
pyroscope_host: "pyroscope_host".into(),
838860
pyroscope_port: Some(4002),
861+
pyroscope_sample_rate: 100,
839862
},
840863
],
841864
);
@@ -847,6 +870,7 @@ mod test {
847870
Some("11%%".into()),
848871
"pyroscope_host".into(),
849872
Some("40%%".into()),
873+
100,
850874
)
851875
.is_err());
852876
}

0 commit comments

Comments
 (0)