}
private static Profiler startProfiler(CeTask task) {
- return Profiler.create(LOG).startInfo("Execute task | project={} | type={} | id={}", task.getComponentKey(), task.getType(), task.getUuid());
+ Profiler profiler = Profiler.create(LOG);
+ return profiler.startInfo("Execute task | project={} | type={} | id={} | submitter='{}'",
+ task.getComponentKey(), task.getType(), task.getUuid(), getSubmitterLoginForLog(task));
}
private static void stopProfiler(Profiler profiler, CeTask task, CeActivityDto.Status status) {
if (status == CeActivityDto.Status.FAILED) {
- profiler.stopError("Executed task | project={} | type={} | id={}", task.getComponentKey(), task.getType(), task.getUuid());
+ profiler.stopError("Executed task | project={} | type={} | id={} | submitter='{}'",
+ task.getComponentKey(), task.getType(), task.getUuid(), getSubmitterLoginForLog(task));
} else {
- profiler.stopInfo("Executed task | project={} | type={} | id={}", task.getComponentKey(), task.getType(), task.getUuid());
+ profiler.stopInfo("Executed task | project={} | type={} | id={} | submitter='{}'",
+ task.getComponentKey(), task.getType(), task.getUuid(), getSubmitterLoginForLog(task));
}
}
+
+ private static String getSubmitterLoginForLog(CeTask task) {
+ if (task.getSubmitterLogin() == null) {
+ return "";
+ }
+ return task.getSubmitterLogin();
+ }
}
package org.sonar.server.computation.taskprocessor;
import com.google.common.base.Optional;
+import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mockito;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.log.CeLogging;
import org.sonar.ce.queue.CeTask;
import org.sonar.db.ce.CeActivityDto;
@Rule
public CeTaskProcessorRepositoryRule taskProcessorRepository = new CeTaskProcessorRepositoryRule();
+ @Rule
+ public LogTester logTester = new LogTester();
InternalCeQueue queue = mock(InternalCeQueue.class);
ReportTaskProcessor taskProcessor = mock(ReportTaskProcessor.class);
inOrder.verify(queue).remove(task, CeActivityDto.Status.FAILED, null);
inOrder.verify(ceLogging).clearForTask();
}
+
+ @Test
+ public void do_not_display_null_in_log_when_submitterLogin_is_not_set() throws Exception {
+ CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin(null).build();
+ when(queue.peek()).thenReturn(Optional.of(task));
+ taskProcessorRepository.setProcessorForTask(task.getType(), taskProcessor);
+
+ underTest.call();
+
+ List<String> logs = logTester.logs(LoggerLevel.INFO);
+ assertThat(logs).hasSize(4);
+ for (int i = 0; i < 4; i++) {
+ assertThat(logs.get(i)).contains(" | submitter=''");
+ }
+ }
+
+ @Test
+ public void display_submitterLogin_in_logs_when_set() throws Exception {
+ CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin("FooBar").build();
+ when(queue.peek()).thenReturn(Optional.of(task));
+ taskProcessorRepository.setProcessorForTask(task.getType(), taskProcessor);
+
+ underTest.call();
+
+ List<String> logs = logTester.logs(LoggerLevel.INFO);
+ assertThat(logs).hasSize(4);
+ for (int i = 0; i < 4; i++) {
+ assertThat(logs.get(i)).contains(" | submitter='FooBar'");
+ }
+ }
}