@@ -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