]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8332 document use of %reqAttribute{ID} in access logs + add IT 1389/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 15 Nov 2016 15:18:11 +0000 (16:18 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 15 Nov 2016 16:37:58 +0000 (17:37 +0100)
it/it-tests/src/test/java/it/serverSystem/LogsTest.java
sonar-application/src/main/assembly/conf/sonar.properties

index bd77db688bc3d9ccd79f2509ea70c58fc02e99dd..2a67c98e8a043be23bf8d7f49bee0411236ad4a5 100644 (file)
@@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class LogsTest {
 
-  public static final String ACCESS_LOGS_PATTERN = "\"%reqAttribute{LOGIN}\" \"%r\" %s";
+  public static final String ACCESS_LOGS_PATTERN = "\"%reqAttribute{ID}\" \"%reqAttribute{LOGIN}\" \"%r\" %s";
   private static final String PATH = "/called/from/LogsTest";
 
   @ClassRule
@@ -45,7 +45,7 @@ public class LogsTest {
    * SONAR-7581
    */
   @Test
-  public void test_access_logs() throws Exception {
+  public void verify_login_in_access_logs() throws Exception {
     // log "-" for anonymous
     sendHttpRequest(ItUtils.newWsClient(orchestrator), PATH);
     assertThat(accessLogsFile()).isFile().exists();
@@ -55,8 +55,18 @@ public class LogsTest {
     verifyLastAccessLogLine("admin", PATH, 404);
   }
 
+  @Test
+  public void verify_request_id_in_access_logs() throws IOException {
+    sendHttpRequest(ItUtils.newWsClient(orchestrator), PATH);
+    String lastAccessLog = readLastAccessLog();
+    assertThat(lastAccessLog).doesNotStartWith("\"\"").startsWith("\"");
+    int firstQuote = lastAccessLog.indexOf('"');
+    String requestId = lastAccessLog.substring(firstQuote + 1, lastAccessLog.indexOf('"', firstQuote + 1));
+    assertThat(requestId.length()).isGreaterThanOrEqualTo(20);
+  }
+
   private void verifyLastAccessLogLine(String login, String path, int status) throws IOException {
-    assertThat(readLastAccessLog()).isEqualTo(format("\"%s\" \"GET %s HTTP/1.1\" %d", login, path, status));
+    assertThat(readLastAccessLog()).endsWith(format("\"%s\" \"GET %s HTTP/1.1\" %d", login, path, status));
   }
 
   private String readLastAccessLog() throws IOException {
index cab60b6040b6ffc90e7602a6e27762f011282e9f..eeb779ad968e8a7efdbefe05ceb21d2ec6443d18 100644 (file)
 #    - else a custom pattern. See http://logback.qos.ch/manual/layouts.html#AccessPatternLayout.
 # The login of authenticated user is not implemented with "%u" but with "%reqAttribute{LOGIN}" (since version 6.1).
 # The value displayed for anonymous users is "-".
+# The SonarQube's HTTP request ID can be added to the pattern with "%reqAttribute{ID}" (since version 6.2).
 # If SonarQube is behind a reverse proxy, then the following value allows to display the correct remote IP address:
 #sonar.web.accessLogs.pattern=%i{X-Forwarded-For} %l %u [%t] "%r" %s %b "%i{Referer}" "%i{User-Agent}"
 # Default value is: