]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4898 - Added FULL/BASIC profiling for ES Querying
authorStephane Gamard <stephane.gamard@searchbox.com>
Mon, 28 Jul 2014 12:29:44 +0000 (14:29 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Mon, 28 Jul 2014 12:29:44 +0000 (14:29 +0200)
server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndex.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java

index 92f94cb12301a9142d9791560135e6aee1303705..2bb4a22bd97a037c742885e6d70c3af244f9f215 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.core.activity.Activity;
 import org.sonar.core.activity.db.ActivityDto;
 import org.sonar.core.cluster.WorkQueue;
 import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
 import org.sonar.server.search.BaseIndex;
 import org.sonar.server.search.ESNode;
 import org.sonar.server.search.IndexDefinition;
@@ -90,11 +91,16 @@ public class ActivityIndex extends BaseIndex<Activity, ActivityDto, String> {
   }
 
   public Result<Activity> findAll() {
-    return new Result<Activity>(this, getClient().prepareSearch(this.getIndexName())
+    StopWatch fullProfile = profiling.start("es", Profiling.Level.FULL);
+    StopWatch basicProfile = profiling.start("es", Profiling.Level.BASIC);
+    SearchRequestBuilder request = getClient().prepareSearch(this.getIndexName())
       .setQuery(QueryBuilders.matchAllQuery())
       .setTypes(this.getIndexType())
-      .setSize(Integer.MAX_VALUE)
-      .get());
+      .setSize(Integer.MAX_VALUE);
+    basicProfile.stop(request.toString());
+    SearchResponse response = request.get();
+    fullProfile.stop(response.toString());
+    return new Result<Activity>(this, response);
   }
 
   public SearchResponse search(ActivityQuery query, QueryOptions options) {
@@ -104,6 +110,9 @@ public class ActivityIndex extends BaseIndex<Activity, ActivityDto, String> {
   public SearchResponse search(ActivityQuery query, QueryOptions options,
                                @Nullable FilterBuilder domainFilter) {
 
+    StopWatch fullProfile = profiling.start("es", Profiling.Level.FULL);
+    StopWatch basicProfile = profiling.start("es", Profiling.Level.BASIC);
+
     // Prepare query
     SearchRequestBuilder esSearch = getClient()
       .prepareSearch(this.getIndexName())
@@ -144,6 +153,10 @@ public class ActivityIndex extends BaseIndex<Activity, ActivityDto, String> {
       esSearch.setScroll(TimeValue.timeValueMinutes(3));
     }
 
-    return esSearch.get();
+    basicProfile.stop(esSearch.toString());
+    SearchResponse response = esSearch.get();
+    fullProfile.stop(response.toString());
+
+    return response;
   }
 }
index 4dbfd203599d8636d274827bd8dcbb0511df77e4..a77c50062b8758bdc2cf3ca5f4966ff5a6dff266 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.core.cluster.WorkQueue;
 import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
 import org.sonar.core.qualityprofile.db.ActiveRuleDto;
 import org.sonar.core.qualityprofile.db.ActiveRuleKey;
 import org.sonar.server.qualityprofile.ActiveRule;
@@ -119,6 +120,8 @@ public class ActiveRuleIndex extends BaseIndex<ActiveRule, ActiveRuleDto, Active
    * finder methods
    */
   public List<ActiveRule> findByRule(RuleKey key) {
+    StopWatch fullProfile = profiling.start("es", Profiling.Level.FULL);
+    StopWatch basicProfile = profiling.start("es", Profiling.Level.BASIC);
     SearchRequestBuilder request = getClient().prepareSearch(this.getIndexName())
       .setQuery(QueryBuilders
         .hasParentQuery(this.getParentType(),
@@ -129,7 +132,9 @@ public class ActiveRuleIndex extends BaseIndex<ActiveRule, ActiveRuleDto, Active
         // TODO replace by scrolling
       .setSize(Integer.MAX_VALUE);
 
+    basicProfile.stop(request.toString());
     SearchResponse response = request.get();
+    fullProfile.stop(response.toString());
 
     List<ActiveRule> activeRules = new ArrayList<ActiveRule>();
     for (SearchHit hit : response.getHits()) {
@@ -139,13 +144,16 @@ public class ActiveRuleIndex extends BaseIndex<ActiveRule, ActiveRuleDto, Active
   }
 
   public List<ActiveRule> findByProfile(String key) {
+    StopWatch fullProfile = profiling.start("es", Profiling.Level.FULL);
+    StopWatch basicProfile = profiling.start("es", Profiling.Level.BASIC);
     SearchRequestBuilder request = getClient().prepareSearch(getIndexName())
       .setQuery(QueryBuilders.termQuery(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field(), key))
       .setRouting(key)
         // TODO replace by scrolling
       .setSize(Integer.MAX_VALUE);
+    basicProfile.stop(request.toString());
     SearchResponse response = request.get();
-
+    fullProfile.stop(response.toString());
     List<ActiveRule> activeRules = new ArrayList<ActiveRule>();
     for (SearchHit hit : response.getHits()) {
       activeRules.add(toDoc(hit.getSource()));
@@ -176,6 +184,8 @@ public class ActiveRuleIndex extends BaseIndex<ActiveRule, ActiveRuleDto, Active
   }
 
   public Map<String, Multimap<String, FacetValue>> getStatsByProfileKeys(List<String> keys) {
+    StopWatch fullProfile = profiling.start("es", Profiling.Level.FULL);
+    StopWatch basicProfile = profiling.start("es", Profiling.Level.BASIC);
     SearchRequestBuilder request = getClient().prepareSearch(this.getIndexName())
       .setQuery(QueryBuilders.filteredQuery(
         QueryBuilders.termsQuery(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field(), keys),
@@ -191,8 +201,9 @@ public class ActiveRuleIndex extends BaseIndex<ActiveRule, ActiveRuleDto, Active
         .subAggregation(AggregationBuilders.count("countActiveRules")))
       .setSize(0)
       .setTypes(this.getIndexType());
-
+    basicProfile.stop(request.toString());
     SearchResponse response = request.get();
+    fullProfile.stop(response.toString());
     Map<String, Multimap<String, FacetValue>> stats = new HashMap<String, Multimap<String, FacetValue>>();
     Aggregation aggregation = response.getAggregations().get(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field());
     for (Terms.Bucket value : ((Terms) aggregation).getBuckets()) {