Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

configurable bind address

fixes #37 (at least for constellation)

Changed files
+37 -13
constellation
src
bin
+37 -13
constellation/src/bin/main.rs
··· 1 1 use anyhow::{bail, Result}; 2 2 use clap::{Parser, ValueEnum}; 3 3 use metrics_exporter_prometheus::PrometheusBuilder; 4 + use std::net::SocketAddr; 4 5 use std::num::NonZero; 5 6 use std::path::PathBuf; 6 7 use std::sync::{atomic::AtomicU32, Arc}; ··· 21 22 #[derive(Parser, Debug)] 22 23 #[command(version, about, long_about = None)] 23 24 struct Args { 24 - #[arg(short, long)] 25 + /// constellation server's listen address 26 + #[arg(long)] 27 + #[clap(default_value = "0.0.0.0:6789")] 28 + bind: SocketAddr, 29 + /// metrics server's listen address 30 + #[arg(long)] 31 + #[clap(default_value = "0.0.0.0:8765")] 32 + bind_metrics: SocketAddr, 25 33 /// Jetstream server to connect to (exclusive with --fixture). Provide either a wss:// URL, or a shorhand value: 26 34 /// 'us-east-1', 'us-east-2', 'us-west-1', or 'us-west-2' 27 35 #[arg(short, long)] ··· 77 85 78 86 let stream = jetstream_url(&args.jetstream); 79 87 println!("using jetstream server {stream:?}...",); 88 + 89 + let bind = args.bind; 90 + let metrics_bind = args.bind_metrics; 80 91 81 92 let stay_alive = CancellationToken::new(); 82 93 83 94 match args.backend { 84 - StorageBackend::Memory => run(MemStorage::new(), fixture, None, stream, stay_alive), 95 + StorageBackend::Memory => run( 96 + MemStorage::new(), 97 + fixture, 98 + None, 99 + stream, 100 + bind, 101 + metrics_bind, 102 + stay_alive, 103 + ), 85 104 #[cfg(feature = "rocks")] 86 105 StorageBackend::Rocks => { 87 106 let storage_dir = args.data.clone().unwrap_or("rocks.test".into()); ··· 96 115 rocks.start_backup(backup_dir, auto_backup, stay_alive.clone())?; 97 116 } 98 117 println!("rocks ready."); 99 - run(rocks, fixture, args.data, stream, stay_alive) 118 + run( 119 + rocks, 120 + fixture, 121 + args.data, 122 + stream, 123 + bind, 124 + metrics_bind, 125 + stay_alive, 126 + ) 100 127 } 101 128 } 102 129 } ··· 106 133 fixture: Option<PathBuf>, 107 134 data_dir: Option<PathBuf>, 108 135 stream: String, 136 + bind: SocketAddr, 137 + metrics_bind: SocketAddr, 109 138 stay_alive: CancellationToken, 110 139 ) -> Result<()> { 111 140 ctrlc::set_handler({ ··· 150 179 .build() 151 180 .expect("axum startup") 152 181 .block_on(async { 153 - install_metrics_server()?; 154 - serve(readable, "0.0.0.0:6789", staying_alive).await 182 + install_metrics_server(metrics_bind)?; 183 + serve(readable, bind, staying_alive).await 155 184 }) 156 185 .unwrap(); 157 186 stay_alive.drop_guard(); ··· 218 247 Ok(()) 219 248 } 220 249 221 - fn install_metrics_server() -> Result<()> { 250 + fn install_metrics_server(metrics_bind: SocketAddr) -> Result<()> { 222 251 println!("installing metrics server..."); 223 - let host = [0, 0, 0, 0]; 224 - let port = 8765; 225 252 PrometheusBuilder::new() 226 253 .set_quantiles(&[0.5, 0.9, 0.99, 1.0])? 227 254 .set_bucket_duration(time::Duration::from_secs(30))? 228 255 .set_bucket_count(NonZero::new(10).unwrap()) // count * duration = 5 mins. stuff doesn't happen that fast here. 229 256 .set_enable_unit_suffix(true) 230 - .with_http_listener((host, port)) 257 + .with_http_listener(metrics_bind) 231 258 .install()?; 232 - println!( 233 - "metrics server installed! listening on http://{}.{}.{}.{}:{port}", 234 - host[0], host[1], host[2], host[3] 235 - ); 259 + println!("metrics server installed! listening at {metrics_bind:?}"); 236 260 Ok(()) 237 261 } 238 262