tangled
alpha
login
or
join now
ptr.pet
/
Allegedly
forked from
microcosm.blue/Allegedly
0
fork
atom
Server tools to backfill, tail, mirror, and verify PLC logs
0
fork
atom
overview
issues
pulls
pipelines
more client tweaks, whatever
bad-example.com
5 months ago
59cad5c3
30d8dc19
+11
-16
1 changed file
expand all
collapse all
unified
split
src
mirror.rs
+11
-16
src/mirror.rs
···
13
14
#[derive(Debug, Clone)]
15
struct State {
16
-
upstream_client: Client,
17
-
wrapped_client: Client,
18
plc: Url,
19
upstream: Url,
20
}
···
67
let mut url = url.clone();
68
url.set_path("/_health");
69
70
-
let Ok(response) = client.get(url).send().await else {
71
return (false, json!({"error": "cannot reach plc server"}));
72
};
73
···
101
async fn health(
102
Data(State {
103
plc,
104
-
wrapped_client,
105
upstream,
106
-
upstream_client,
107
}): Data<&State>,
108
) -> impl IntoResponse {
109
let mut overall_status = StatusCode::OK;
110
-
let (ok, wrapped_status) = plc_status(plc, wrapped_client).await;
111
if !ok {
112
overall_status = StatusCode::BAD_GATEWAY;
113
}
114
-
let (ok, upstream_status) = plc_status(upstream, upstream_client).await;
115
if !ok {
116
overall_status = StatusCode::BAD_GATEWAY;
117
}
···
131
let mut target = state.plc.clone();
132
target.set_path(req.uri().path());
133
let upstream_res = state
134
-
.upstream_client
135
.get(target)
0
136
.headers(req.headers().clone())
137
.send()
138
.await
···
177
}
178
179
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()
185
.user_agent(UA)
186
-
.timeout(Duration::from_secs(6))
187
.build()
188
.unwrap();
189
190
let state = State {
191
-
wrapped_client,
192
-
upstream_client,
193
plc,
194
upstream: upstream.clone(),
195
};
···
13
14
#[derive(Debug, Clone)]
15
struct State {
16
+
client: Client,
0
17
plc: Url,
18
upstream: Url,
19
}
···
66
let mut url = url.clone();
67
url.set_path("/_health");
68
69
+
let Ok(response) = client.get(url).timeout(Duration::from_secs(3)).send().await else {
70
return (false, json!({"error": "cannot reach plc server"}));
71
};
72
···
100
async fn health(
101
Data(State {
102
plc,
103
+
client,
104
upstream,
0
105
}): Data<&State>,
106
) -> impl IntoResponse {
107
let mut overall_status = StatusCode::OK;
108
+
let (ok, wrapped_status) = plc_status(plc, client).await;
109
if !ok {
110
overall_status = StatusCode::BAD_GATEWAY;
111
}
112
+
let (ok, upstream_status) = plc_status(upstream, client).await;
113
if !ok {
114
overall_status = StatusCode::BAD_GATEWAY;
115
}
···
129
let mut target = state.plc.clone();
130
target.set_path(req.uri().path());
131
let upstream_res = state
132
+
.client
133
.get(target)
134
+
.timeout(Duration::from_secs(3)) // should be low latency to wrapped server
135
.headers(req.headers().clone())
136
.send()
137
.await
···
176
}
177
178
pub async fn serve(upstream: &Url, plc: Url, bind: SocketAddr) -> std::io::Result<()> {
179
+
// not using crate CLIENT: don't want the retries etc
180
+
let client = Client::builder()
0
0
0
181
.user_agent(UA)
182
+
.timeout(Duration::from_secs(10)) // fallback
183
.build()
184
.unwrap();
185
186
let state = State {
187
+
client,
0
188
plc,
189
upstream: upstream.clone(),
190
};