Skip to content

Commit e1845b6

Browse files
committed
fix(logs): restart without previous logs
resolves #24
1 parent 66f8019 commit e1845b6

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/widget/log.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl Log {
7272
previous: true,
7373
..Default::default()
7474
},
75+
true,
7576
));
7677

7778
Self {
@@ -191,15 +192,16 @@ fn log_stream<'a>(
191192
pod: Arc<Pod>,
192193
tx: UnboundedSender<String>,
193194
params: LogParams,
195+
retry: bool,
194196
) -> BoxFuture<'a, Result<()>> {
195197
async move {
196-
let client = Api::<Pod>::namespaced(client.clone(), &pod.namespace().unwrap());
198+
let pod_client = Api::<Pod>::namespaced(client.clone(), &pod.namespace().unwrap());
197199

198200
let containers = try_join_all(pod.containers(None).iter().map(|c| {
199201
let mut params = params.clone();
200202
params.container = Some(c.name_any());
201203

202-
container_stream(&client, c, params)
204+
container_stream(&pod_client, c, params)
203205
}))
204206
.await?;
205207

@@ -211,6 +213,21 @@ fn log_stream<'a>(
211213

212214
tracing::debug!(pod = pod.name_any(), "stream ended");
213215

216+
// The api server is a little finicky about streaming previous logs. It is
217+
// possible that the request succeeds, but also that the stream finishes
218+
// immediately. If this happens, retry without the previous flag. Because we're
219+
// not clearing out the buffer on the widget side of things, the logs will be
220+
// duplicated. Before the restart, we send a simple message to tell the user
221+
// what happened.
222+
if retry {
223+
tx.send("Stream terminated, retrying without previous logs".to_string())?;
224+
225+
let mut new_params = params.clone();
226+
new_params.previous = false;
227+
228+
return log_stream(client, pod, tx, new_params, false).await;
229+
}
230+
214231
Ok(())
215232
}
216233
.boxed()

0 commit comments

Comments
 (0)