Skip to content

Commit 197d5ea

Browse files
committed
chore: add status event for oldest timestamp
1 parent fe657be commit 197d5ea

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/k8s/logging/logging.service.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ export class LoggingService {
235235
const until = since ? new Date(since.until) : undefined;
236236

237237
const endStream = () => {
238+
if (oldestTimestamp) {
239+
stream.emit(
240+
"data",
241+
JSON.stringify({
242+
oldest_timestamp: oldestTimestamp.toISOString(),
243+
}),
244+
);
245+
}
246+
238247
if (!streamEnded) {
239248
streamEnded = true;
240249
stream.end();
@@ -304,17 +313,23 @@ export class LoggingService {
304313
for (let data of text.split(/\n/)) {
305314
const { timestamp, log } = this.parseLog(data);
306315

307-
if (since) {
308-
if (new Date(timestamp)) {
309-
const latestTimestamp = new Date(timestamp);
310-
311-
if (!oldestTimestamp || oldestTimestamp > latestTimestamp) {
312-
oldestTimestamp = latestTimestamp;
316+
if (new Date(timestamp)) {
317+
const latestTimestamp = new Date(timestamp);
318+
319+
if (!oldestTimestamp || oldestTimestamp > latestTimestamp) {
320+
if (!oldestTimestamp) {
321+
stream.emit(
322+
"data",
323+
JSON.stringify({
324+
oldest_timestamp: latestTimestamp.toISOString(),
325+
}),
326+
);
313327
}
328+
oldestTimestamp = latestTimestamp;
329+
}
314330

315-
if (latestTimestamp && latestTimestamp >= until) {
316-
continue;
317-
}
331+
if (since && latestTimestamp && latestTimestamp >= until) {
332+
continue;
318333
}
319334
}
320335

0 commit comments

Comments
 (0)