]> source.dussan.org Git - sonarqube.git/commitdiff
Improve Profiling output for *Index Classes
authorStephane Gamard <stephane.gamard@searchbox.com>
Mon, 4 Aug 2014 10:29:26 +0000 (12:29 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Mon, 4 Aug 2014 12:05:09 +0000 (14:05 +0200)
server/sonar-server/src/main/java/org/sonar/server/search/ESNode.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java

index 3e8d0dfdcdb71a00bfae243038751e977934866f..d10ccad680edb881c17cbb03447a9d923b720793 100644 (file)
@@ -189,40 +189,40 @@ public class ESNode implements Startable {
     esSettings
       .put("index.mapper.dynamic", false)
 
-      // Sortable text analyzer
+        // Sortable text analyzer
       .put("index.analysis.analyzer.sortable.type", "custom")
       .put("index.analysis.analyzer.sortable.tokenizer", "keyword")
       .putArray("index.analysis.analyzer.sortable.filter", "trim", "lowercase", "truncate")
 
-      // Edge NGram index-analyzer
+        // Edge NGram index-analyzer
       .put("index.analysis.analyzer.index_grams.type", "custom")
       .put("index.analysis.analyzer.index_grams.tokenizer", "whitespace")
       .putArray("index.analysis.analyzer.index_grams.filter", "trim", "lowercase", "gram_filter")
 
-      // Edge NGram search-analyzer
+        // Edge NGram search-analyzer
       .put("index.analysis.analyzer.search_grams.type", "custom")
       .put("index.analysis.analyzer.search_grams.tokenizer", "whitespace")
       .putArray("index.analysis.analyzer.search_grams.filter", "trim", "lowercase")
 
-      // Word index-analyzer
+        // Word index-analyzer
       .put("index.analysis.analyzer.index_words.type", "custom")
       .put("index.analysis.analyzer.index_words.tokenizer", "standard")
       .putArray("index.analysis.analyzer.index_words.filter",
         "standard", "word_filter", "lowercase", "stop", "asciifolding", "porter_stem")
 
-      // Word search-analyzer
+        // Word search-analyzer
       .put("index.analysis.analyzer.search_words.type", "custom")
       .put("index.analysis.analyzer.search_words.tokenizer", "standard")
       .putArray("index.analysis.analyzer.search_words.filter",
         "standard", "lowercase", "stop", "asciifolding", "porter_stem")
 
-      // Edge NGram filter
+        // Edge NGram filter
       .put("index.analysis.filter.gram_filter.type", "edgeNGram")
       .put("index.analysis.filter.gram_filter.min_gram", 2)
       .put("index.analysis.filter.gram_filter.max_gram", 15)
       .putArray("index.analysis.filter.gram_filter.token_chars", "letter", "digit", "punctuation", "symbol")
 
-      // Word filter
+        // Word filter
       .put("index.analysis.filter.word_filter.type", "word_delimiter")
       .put("index.analysis.filter.word_filter.generate_word_parts", true)
       .put("index.analysis.filter.word_filter.catenate_words", true)
@@ -233,7 +233,7 @@ public class ESNode implements Startable {
       .put("index.analysis.filter.word_filter.split_on_numerics", true)
       .put("index.analysis.filter.word_filter.stem_english_possessive", true)
 
-      // Path Analyzer
+        // Path Analyzer
       .put("index.analysis.analyzer.path_analyzer.type", "custom")
       .put("index.analysis.analyzer.path_analyzer.tokenizer", "path_hierarchy");
 
@@ -289,16 +289,25 @@ public class ESNode implements Startable {
     return client;
   }
 
-  public <K extends ActionResponse> K execute(ActionRequestBuilder action) {
+  public <K extends ActionResponse> K execute(ActionRequestBuilder request) {
     StopWatch basicProfile = profiling.start("search", Profiling.Level.BASIC);
     StopWatch fullProfile = profiling.start("search", Profiling.Level.FULL);
-    ListenableActionFuture acc = action.execute();
+    ListenableActionFuture acc = request.execute();
     try {
 
+      K response = (K) acc.get();
+
       if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
-        basicProfile.stop("ES Request: %s", action.toString().replaceAll("\n", ""));
+        if (ToXContent.class.isAssignableFrom(request.getClass())) {
+          XContentBuilder debugResponse = XContentFactory.jsonBuilder();
+          debugResponse.startObject();
+          ((ToXContent) request).toXContent(debugResponse, ToXContent.EMPTY_PARAMS);
+          debugResponse.endObject();
+          fullProfile.stop("ES Request: %s", debugResponse.string());
+        } else {
+          fullProfile.stop("ES Request: %s", request.toString().replaceAll("\n", ""));
+        }
       }
-      K response = (K) acc.get();
 
       if (profiling.isProfilingEnabled(Profiling.Level.FULL)) {
         if (ToXContent.class.isAssignableFrom(response.getClass())) {
index 27e50982d8be0cb74d289a159c25bb9c83d882a7..e6dfc1c40b0b96fafb93b6b931f1e05ed17a3875 100644 (file)
@@ -66,7 +66,8 @@ import static org.fest.assertions.Fail.fail;
 public class RuleIndexMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester();
+  public static ServerTester tester = new ServerTester()
+    .setProperty("sonar.log.profilingLevel", "FULL");
 
   RuleDao dao = tester.get(RuleDao.class);
   RuleIndex index = tester.get(RuleIndex.class);
@@ -615,7 +616,7 @@ public class RuleIndexMediumTest {
 
     // 4. get all active rules on profile
     result = index.search(new RuleQuery().setActivation(true)
-      .setQProfileKey(qualityProfileDto2.getKey()),
+        .setQProfileKey(qualityProfileDto2.getKey()),
       new QueryOptions());
     assertThat(result.getHits()).hasSize(1);
     assertThat(result.getHits().get(0).name()).isEqualTo(rule1.getName());
@@ -652,7 +653,7 @@ public class RuleIndexMediumTest {
       ActiveRuleDto.createFor(qualityProfileDto2, rule3)
         .setSeverity("BLOCKER")
         .setInheritance(ActiveRule.Inheritance.INHERITED.name())
-      );
+    );
 
     dbSession.commit();
 
@@ -674,52 +675,52 @@ public class RuleIndexMediumTest {
 
     // 3. get Inherited Rules on profile1
     result = index.search(new RuleQuery().setActivation(true)
-      .setQProfileKey(qualityProfileDto1.getKey())
-      .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.INHERITED.name())),
+        .setQProfileKey(qualityProfileDto1.getKey())
+        .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.INHERITED.name())),
       new QueryOptions()
-      );
+    );
     assertThat(result.getHits()).hasSize(0);
 
     // 4. get Inherited Rules on profile2
     result = index.search(new RuleQuery().setActivation(true)
-      .setQProfileKey(qualityProfileDto2.getKey())
-      .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.INHERITED.name())),
+        .setQProfileKey(qualityProfileDto2.getKey())
+        .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.INHERITED.name())),
       new QueryOptions()
-      );
+    );
     assertThat(result.getHits()).hasSize(2);
 
     // 5. get Overridden Rules on profile1
     result = index.search(new RuleQuery().setActivation(true)
-      .setQProfileKey(qualityProfileDto1.getKey())
-      .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.OVERRIDES.name())),
+        .setQProfileKey(qualityProfileDto1.getKey())
+        .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.OVERRIDES.name())),
       new QueryOptions()
-      );
+    );
     assertThat(result.getHits()).hasSize(0);
 
     // 6. get Overridden Rules on profile2
     result = index.search(new RuleQuery().setActivation(true)
-      .setQProfileKey(qualityProfileDto2.getKey())
-      .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.OVERRIDES.name())),
+        .setQProfileKey(qualityProfileDto2.getKey())
+        .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.OVERRIDES.name())),
       new QueryOptions()
-      );
+    );
     assertThat(result.getHits()).hasSize(1);
 
     // 7. get Inherited AND Overridden Rules on profile1
     result = index.search(new RuleQuery().setActivation(true)
-      .setQProfileKey(qualityProfileDto1.getKey())
-      .setInheritance(ImmutableSet.of(
-        ActiveRule.Inheritance.INHERITED.name(), ActiveRule.Inheritance.OVERRIDES.name())),
+        .setQProfileKey(qualityProfileDto1.getKey())
+        .setInheritance(ImmutableSet.of(
+          ActiveRule.Inheritance.INHERITED.name(), ActiveRule.Inheritance.OVERRIDES.name())),
       new QueryOptions()
-      );
+    );
     assertThat(result.getHits()).hasSize(0);
 
     // 8. get Inherited AND Overridden Rules on profile2
     result = index.search(new RuleQuery().setActivation(true)
-      .setQProfileKey(qualityProfileDto2.getKey())
-      .setInheritance(ImmutableSet.of(
-        ActiveRule.Inheritance.INHERITED.name(), ActiveRule.Inheritance.OVERRIDES.name())),
+        .setQProfileKey(qualityProfileDto2.getKey())
+        .setInheritance(ImmutableSet.of(
+          ActiveRule.Inheritance.INHERITED.name(), ActiveRule.Inheritance.OVERRIDES.name())),
       new QueryOptions()
-      );
+    );
     assertThat(result.getHits()).hasSize(3);
   }