Skip to content

Commit 17b9f74

Browse files
George Shiqi WuFrankChen021
authored andcommitted
Fix empty logs and status messages for mmless ingestion (#15527)
* Fix empty logs and status messages for mmless ingestion * Add tests
1 parent ee4474f commit 17b9f74

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/KubernetesPeonLifecycle.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ private TaskStatus getTaskStatus(long duration)
288288
TaskStatus.class
289289
);
290290
} else {
291-
taskStatus = TaskStatus.failure(taskId.getOriginalTaskId(), "task status not found");
291+
log.info(
292+
"Peon for task [%s] did not push its task status. Check k8s logs and events for the pod to see what happened.",
293+
taskId
294+
);
295+
taskStatus = TaskStatus.failure(taskId.getOriginalTaskId(), "Peon did not report status successfully.");
292296
}
293297
}
294298
catch (IOException e) {
@@ -329,6 +333,15 @@ protected void saveLogs()
329333
FileUtils.copyInputStreamToFile(logWatch.getOutput(), file.toFile());
330334
} else {
331335
log.debug("Log stream not found for %s", taskId.getOriginalTaskId());
336+
FileUtils.writeStringToFile(
337+
file.toFile(),
338+
StringUtils.format(
339+
"Peon for task [%s] did not report any logs. Check k8s metrics and events for the pod to see what happened.",
340+
taskId
341+
),
342+
Charset.defaultCharset()
343+
);
344+
332345
}
333346
taskLogs.pushTaskLog(taskId.getOriginalTaskId(), file.toFile());
334347
}

extensions-contrib/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/KubernetesPeonLifecycleTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,15 @@ public void test_join_withoutJob_returnsFailedTaskStatus() throws IOException
276276
EasyMock.anyLong(),
277277
EasyMock.eq(TimeUnit.MILLISECONDS)
278278
)).andReturn(new JobResponse(null, PeonPhase.FAILED));
279-
EasyMock.expect(kubernetesClient.getPeonLogWatcher(k8sTaskId)).andReturn(Optional.of(logWatch));
279+
EasyMock.expect(kubernetesClient.getPeonLogWatcher(k8sTaskId)).andReturn(Optional.absent());
280280
EasyMock.expect(taskLogs.streamTaskStatus(ID)).andReturn(Optional.absent());
281+
281282
taskLogs.pushTaskLog(EasyMock.eq(ID), EasyMock.anyObject(File.class));
282283
EasyMock.expectLastCall();
283284
stateListener.stateChanged(KubernetesPeonLifecycle.State.RUNNING, ID);
284285
EasyMock.expectLastCall().once();
285286
stateListener.stateChanged(KubernetesPeonLifecycle.State.STOPPED, ID);
286287
EasyMock.expectLastCall().once();
287-
logWatch.close();
288-
EasyMock.expectLastCall();
289288

290289
replayAll();
291290

@@ -295,7 +294,7 @@ public void test_join_withoutJob_returnsFailedTaskStatus() throws IOException
295294

296295
Assert.assertTrue(taskStatus.isFailure());
297296
Assert.assertEquals(ID, taskStatus.getId());
298-
Assert.assertEquals("task status not found", taskStatus.getErrorMsg());
297+
Assert.assertEquals("Peon did not report status successfully.", taskStatus.getErrorMsg());
299298
Assert.assertEquals(KubernetesPeonLifecycle.State.STOPPED, peonLifecycle.getState());
300299
}
301300

@@ -436,16 +435,14 @@ public void test_join_withoutTaskStatus_returnsFailedTaskStatus() throws IOExcep
436435
EasyMock.anyLong(),
437436
EasyMock.eq(TimeUnit.MILLISECONDS)
438437
)).andReturn(new JobResponse(job, PeonPhase.SUCCEEDED));
439-
EasyMock.expect(kubernetesClient.getPeonLogWatcher(k8sTaskId)).andReturn(Optional.of(logWatch));
438+
EasyMock.expect(kubernetesClient.getPeonLogWatcher(k8sTaskId)).andReturn(Optional.absent());
440439
EasyMock.expect(taskLogs.streamTaskStatus(ID)).andReturn(Optional.absent());
441440
taskLogs.pushTaskLog(EasyMock.eq(ID), EasyMock.anyObject(File.class));
442441
EasyMock.expectLastCall();
443442
stateListener.stateChanged(KubernetesPeonLifecycle.State.RUNNING, ID);
444443
EasyMock.expectLastCall().once();
445444
stateListener.stateChanged(KubernetesPeonLifecycle.State.STOPPED, ID);
446445
EasyMock.expectLastCall().once();
447-
logWatch.close();
448-
EasyMock.expectLastCall();
449446

450447
Assert.assertEquals(KubernetesPeonLifecycle.State.NOT_STARTED, peonLifecycle.getState());
451448

@@ -457,7 +454,7 @@ public void test_join_withoutTaskStatus_returnsFailedTaskStatus() throws IOExcep
457454

458455
Assert.assertTrue(taskStatus.isFailure());
459456
Assert.assertEquals(ID, taskStatus.getId());
460-
Assert.assertEquals("task status not found", taskStatus.getErrorMsg());
457+
Assert.assertEquals("Peon did not report status successfully.", taskStatus.getErrorMsg());
461458
Assert.assertEquals(KubernetesPeonLifecycle.State.STOPPED, peonLifecycle.getState());
462459
}
463460

0 commit comments

Comments
 (0)