Server tools to backfill, tail, mirror, and verify PLC logs
49
fork

Configure Feed

Select the types of activity you want to include in your feed.

more client tweaks, whatever

phil 59cad5c3 30d8dc19

+11 -16
+11 -16
src/mirror.rs
··· 13 13 14 14 #[derive(Debug, Clone)] 15 15 struct State { 16 - upstream_client: Client, 17 - wrapped_client: Client, 16 + client: Client, 18 17 plc: Url, 19 18 upstream: Url, 20 19 } ··· 67 66 let mut url = url.clone(); 68 67 url.set_path("/_health"); 69 68 70 - let Ok(response) = client.get(url).send().await else { 69 + let Ok(response) = client.get(url).timeout(Duration::from_secs(3)).send().await else { 71 70 return (false, json!({"error": "cannot reach plc server"})); 72 71 }; 73 72 ··· 101 100 async fn health( 102 101 Data(State { 103 102 plc, 104 - wrapped_client, 103 + client, 105 104 upstream, 106 - upstream_client, 107 105 }): Data<&State>, 108 106 ) -> impl IntoResponse { 109 107 let mut overall_status = StatusCode::OK; 110 - let (ok, wrapped_status) = plc_status(plc, wrapped_client).await; 108 + let (ok, wrapped_status) = plc_status(plc, client).await; 111 109 if !ok { 112 110 overall_status = StatusCode::BAD_GATEWAY; 113 111 } 114 - let (ok, upstream_status) = plc_status(upstream, upstream_client).await; 112 + let (ok, upstream_status) = plc_status(upstream, client).await; 115 113 if !ok { 116 114 overall_status = StatusCode::BAD_GATEWAY; 117 115 } ··· 131 129 let mut target = state.plc.clone(); 132 130 target.set_path(req.uri().path()); 133 131 let upstream_res = state 134 - .upstream_client 132 + .client 135 133 .get(target) 134 + .timeout(Duration::from_secs(3)) // should be low latency to wrapped server 136 135 .headers(req.headers().clone()) 137 136 .send() 138 137 .await ··· 177 176 } 178 177 179 178 pub async fn serve(upstream: &Url, plc: Url, bind: SocketAddr) -> std::io::Result<()> { 180 - let wrapped_client = Client::builder() 181 - .timeout(Duration::from_secs(3)) 182 - .build() 183 - .unwrap(); 184 - let upstream_client = Client::builder() 179 + // not using crate CLIENT: don't want the retries etc 180 + let client = Client::builder() 185 181 .user_agent(UA) 186 - .timeout(Duration::from_secs(6)) 182 + .timeout(Duration::from_secs(10)) // fallback 187 183 .build() 188 184 .unwrap(); 189 185 190 186 let state = State { 191 - wrapped_client, 192 - upstream_client, 187 + client, 193 188 plc, 194 189 upstream: upstream.clone(), 195 190 };