kfaraz commented on code in PR #18341:
URL: https://github.com/apache/druid/pull/18341#discussion_r2264536306
##########
processing/src/main/java/org/apache/druid/tasklogs/SwitchingTaskLogs.java:
##########
@@ -17,47 +17,52 @@
* under the License.
*/
-package org.apache.druid.indexing.common.tasklogs;
+package org.apache.druid.tasklogs;
import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.google.inject.name.Named;
-import org.apache.druid.tasklogs.TaskLogs;
+import org.apache.druid.common.config.Configs;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+/**
+ * Implements {@link TaskLogs} by delegating to different task log providers
based on the functionality required.
+ * This allows for different handling of reports, streaming logs, and pushing
logs with a default fallback.
+ */
+
public class SwitchingTaskLogs implements TaskLogs
{
- public static final String PROPERTY_PREFIX_SWITCHING =
"druid.indexer.logs.switching";
- public static final String PROPERTY_KEY_SWITCHING_DEFAULT_TYPE =
PROPERTY_PREFIX_SWITCHING + ".defaultType";
- public static final String PROPERTY_KEY_SWITCHING_PUSH_TYPE =
PROPERTY_PREFIX_SWITCHING + ".pushType";
- public static final String PROPERTY_KEY_SWITCHING_STREAM_TYPE =
PROPERTY_PREFIX_SWITCHING + ".streamType";
- public static final String PROPERTY_KEY_SWITCHING_REPORTS_TYPE =
PROPERTY_PREFIX_SWITCHING + ".reportsType";
+ public static final String PROPERTY_PREFIX = "druid.indexer.logs.switching";
+ public static final String PROPERTY_DEFAULT_TYPE = PROPERTY_PREFIX +
".defaultType";
+ public static final String PROPERTY_KEY_SWITCHING_PUSH_TYPE =
PROPERTY_PREFIX + ".logPushType";
Review Comment:
Similar change for other props:
```suggestion
public static final String PROPERTY_LOG_PUSH_TYPE = PROPERTY_PREFIX +
".logPushType";
```
##########
indexing-service/src/main/java/org/apache/druid/guice/IndexingServiceTaskLogsModule.java:
##########
@@ -113,4 +79,23 @@ public void configure(Binder binder)
binder.bind(TaskLogKiller.class).to(TaskLogs.class);
binder.bind(TaskPayloadManager.class).to(TaskLogs.class);
}
+
+ private void bindTaskLogImplementation(
+ Binder binder,
+ String propertyKeySwitchingStreamType,
+ String keySwitchingStream
Review Comment:
```suggestion
String typeName
```
##########
processing/src/test/java/org/apache/druid/tasklogs/SwitchingTaskLogsTest.java:
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.tasklogs;
+
+import com.google.common.base.Optional;
+import org.easymock.EasyMock;
+import org.easymock.EasyMockRunner;
+import org.easymock.EasyMockSupport;
+import org.easymock.Mock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+
+@RunWith(EasyMockRunner.class)
+public class SwitchingTaskLogsTest extends EasyMockSupport
+{
+ @Mock
+ private TaskLogs defaultTaskLogs;
+
+ @Mock
+ private TaskLogs reportTaskLogs;
+
+ @Mock
+ private TaskLogs streamerTaskLogs;
+
+ @Mock
+ private TaskLogs pusherTaskLogs;
+
+ private SwitchingTaskLogs taskLogs;
+
+ @Before
+ public void setUp()
+ {
+ taskLogs = new SwitchingTaskLogs(defaultTaskLogs, reportTaskLogs,
streamerTaskLogs, pusherTaskLogs);
+ }
+
+ @Test
+ public void test_streamTaskLog_shouldUseStreamerTaskLogs() throws IOException
+ {
+ String taskId = "test-task-id";
+ long offset = 0L;
+ InputStream logStream = new ByteArrayInputStream("test log
content".getBytes(StandardCharsets.UTF_8));
+
+ EasyMock.expect(streamerTaskLogs.streamTaskLog(taskId,
offset)).andReturn(Optional.of(logStream));
+ replayAll();
+
+ Optional<InputStream> actualLogStream = taskLogs.streamTaskLog(taskId,
offset);
+ Assert.assertTrue(actualLogStream.isPresent());
+ Assert.assertEquals(logStream, actualLogStream.get());
+
+ verifyAll();
+ }
+
+ @Test
+ public void test_streamTaskReports_shouldUseReportTaskLogs() throws
IOException
+ {
+ String taskId = "test-task-id";
+ InputStream reportStream = new ByteArrayInputStream("test report
content".getBytes(StandardCharsets.UTF_8));
+
+
EasyMock.expect(reportTaskLogs.streamTaskReports(taskId)).andReturn(Optional.of(reportStream));
+ replayAll();
+
+ Optional<InputStream> actualReportStream =
taskLogs.streamTaskReports(taskId);
+ Assert.assertTrue(actualReportStream.isPresent());
+ Assert.assertEquals(reportStream, actualReportStream.get());
+
+ verifyAll();
+ }
+
+ @Test
+ public void test_streamTaskStatus_shouldUseReportTaskLogs() throws
IOException
+ {
+ String taskId = "test-task-id";
+ InputStream statusStream = new ByteArrayInputStream("test status
content".getBytes(StandardCharsets.UTF_8));
+
+
EasyMock.expect(reportTaskLogs.streamTaskStatus(taskId)).andReturn(Optional.of(statusStream));
+ replayAll();
+
+ Optional<InputStream> actualStatusStream =
taskLogs.streamTaskStatus(taskId);
+ Assert.assertTrue(actualStatusStream.isPresent());
+ Assert.assertEquals(statusStream, actualStatusStream.get());
+
+ verifyAll();
+ }
+
+ @Test
+ public void test_streamTaskPayload_shouldUseReportTaskLogs() throws
IOException
+ {
+ String taskId = "test-task-id";
+ InputStream payloadStream = new ByteArrayInputStream("test payload
content".getBytes(StandardCharsets.UTF_8));
+
+
EasyMock.expect(reportTaskLogs.streamTaskPayload(taskId)).andReturn(Optional.of(payloadStream));
+ replayAll();
+
+ Optional<InputStream> actualPayloadStream =
taskLogs.streamTaskPayload(taskId);
+ Assert.assertTrue(actualPayloadStream.isPresent());
+ Assert.assertEquals(payloadStream, actualPayloadStream.get());
+
+ verifyAll();
+ }
+
+ @Test
+ public void test_pushTaskLog_shouldUsePusherTaskLogs() throws IOException
+ {
+ String taskId = "test-task-id";
+ File logFile = new File("test.log");
+
+ pusherTaskLogs.pushTaskLog(taskId, logFile);
+ EasyMock.expectLastCall();
+ replayAll();
+
+ taskLogs.pushTaskLog(taskId, logFile);
+
+ verifyAll();
+ }
+
+ @Test
+ public void test_pushTaskReports_shouldUseReportTaskLogs() throws IOException
+ {
+ String taskId = "test-task-id";
+ File logFile = new File("test.log");
+
+ reportTaskLogs.pushTaskReports(taskId, logFile);
+ EasyMock.expectLastCall();
+ replayAll();
+
+ taskLogs.pushTaskReports(taskId, logFile);
+
+ verifyAll();
+ }
+
+ @Test
+ public void test_pushTaskStatus_shouldUseReportTaskLogs() throws IOException
+ {
+ String taskId = "test-task-id";
+ File logFile = new File("test.log");
+
+ reportTaskLogs.pushTaskStatus(taskId, logFile);
+ EasyMock.expectLastCall();
+ replayAll();
+
+ taskLogs.pushTaskStatus(taskId, logFile);
+
+ verifyAll();
+ }
+
+ @Test
+ public void test_pushTaskPayload_shouldUseReportTaskLogs() throws IOException
+ {
+ String taskId = "test-task-id";
+ File logFile = new File("test.log");
+
+ reportTaskLogs.pushTaskPayload(taskId, logFile);
+ EasyMock.expectLastCall();
+ replayAll();
+
+ taskLogs.pushTaskPayload(taskId, logFile);
+
+ verifyAll();
+ }
+
+ @Test
+ public void test_killAll_shouldUseReportTaskLogs() throws IOException
+ {
+ reportTaskLogs.killAll();
+ EasyMock.expectLastCall();
+ replayAll();
+
+ taskLogs.killAll();
+
+ verifyAll();
+ }
+
+ @Test
+ public void test_killOlderThan_shouldUseReportTaskLogs() throws IOException
Review Comment:
Nit: `uses` instead of `shouldUse` reads better.
```suggestion
public void test_killOlderThan_usesReportTaskLogs() throws IOException
```
##########
indexing-service/src/main/java/org/apache/druid/guice/IndexingServiceTaskLogsModule.java:
##########
@@ -113,4 +79,23 @@ public void configure(Binder binder)
binder.bind(TaskLogKiller.class).to(TaskLogs.class);
binder.bind(TaskPayloadManager.class).to(TaskLogs.class);
}
+
+ private void bindTaskLogImplementation(
+ Binder binder,
+ String propertyKeySwitchingStreamType,
Review Comment:
```suggestion
String propertyKey,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]