Server tools to backfill, tail, mirror, and verify PLC logs
at a0c0d8b2bef79f8c6540e436ea5014f9d9aba0dd 89 lines 2.1 kB view raw
1use serde::Deserialize; 2 3mod backfill; 4mod client; 5mod mirror; 6mod plc_pg; 7mod poll; 8mod ratelimit; 9mod weekly; 10 11pub use backfill::backfill; 12pub use client::{CLIENT, UA}; 13pub use mirror::{ListenConf, serve}; 14pub use plc_pg::{Db, backfill_to_pg, pages_to_pg}; 15pub use poll::{PageBoundaryState, get_page, poll_upstream}; 16pub use ratelimit::GovernorMiddleware; 17pub use weekly::{BundleSource, FolderSource, HttpSource, Week, pages_to_weeks, week_to_pages}; 18 19pub type Dt = chrono::DateTime<chrono::Utc>; 20 21/// One page of PLC export 22/// 23/// plc.directory caps /export at 1000 ops; backfill tasks may send more in a page. 24#[derive(Debug)] 25pub struct ExportPage { 26 pub ops: Vec<String>, 27} 28 29impl ExportPage { 30 pub fn is_empty(&self) -> bool { 31 self.ops.is_empty() 32 } 33} 34 35/// A fully-deserialized plc operation 36/// 37/// including the plc's wrapping with timestmap and nullified state 38#[derive(Debug, Deserialize)] 39#[serde(rename_all = "camelCase")] 40pub struct Op<'a> { 41 pub did: &'a str, 42 pub cid: &'a str, 43 pub created_at: Dt, 44 pub nullified: bool, 45 #[serde(borrow)] 46 pub operation: &'a serde_json::value::RawValue, 47} 48 49/// Database primary key for an op 50#[derive(Debug, PartialEq)] 51pub struct OpKey { 52 pub did: String, 53 pub cid: String, 54} 55 56impl From<&Op<'_>> for OpKey { 57 fn from(Op { did, cid, .. }: &Op<'_>) -> Self { 58 Self { 59 did: did.to_string(), 60 cid: cid.to_string(), 61 } 62 } 63} 64 65pub fn logo(name: &str) -> String { 66 format!( 67 r" 68 69 \ | | | | 70 _ \ | | -_) _` | -_) _` | | | | ({name}) 71 _/ _\ _| _| \___| \__, | \___| \__,_| _| \_, | (v{}) 72 ____| __/ 73", 74 env!("CARGO_PKG_VERSION"), 75 ) 76} 77 78pub fn bin_init(name: &str) { 79 if std::env::var_os("RUST_LOG").is_none() { 80 unsafe { std::env::set_var("RUST_LOG", "info") }; 81 } 82 let filter = tracing_subscriber::EnvFilter::from_default_env(); 83 tracing_subscriber::fmt() 84 .with_writer(std::io::stderr) 85 .with_env_filter(filter) 86 .init(); 87 88 log::info!("{}", logo(name)); 89}