From 371198dae084f5993603707adea697b8c7bc241f Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Mon, 28 Jul 2014 14:29:44 +0200 Subject: [PATCH] SONAR-4898 - Added FULL/BASIC profiling for ES Querying --- .../server/activity/index/ActivityIndex.java | 21 +++++++++++++++---- .../qualityprofile/index/ActiveRuleIndex.java | 15 +++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndex.java b/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndex.java index 92f94cb1230..2bb4a22bd97 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndex.java @@ -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 { } public Result findAll() { - return new Result(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(this, response); } public SearchResponse search(ActivityQuery query, QueryOptions options) { @@ -104,6 +110,9 @@ public class ActivityIndex extends BaseIndex { 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 { esSearch.setScroll(TimeValue.timeValueMinutes(3)); } - return esSearch.get(); + basicProfile.stop(esSearch.toString()); + SearchResponse response = esSearch.get(); + fullProfile.stop(response.toString()); + + return response; } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java index 4dbfd203599..a77c50062b8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java @@ -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 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 activeRules = new ArrayList(); for (SearchHit hit : response.getHits()) { @@ -139,13 +144,16 @@ public class ActiveRuleIndex extends BaseIndex 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 activeRules = new ArrayList(); for (SearchHit hit : response.getHits()) { activeRules.add(toDoc(hit.getSource())); @@ -176,6 +184,8 @@ public class ActiveRuleIndex extends BaseIndex> getStatsByProfileKeys(List 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> stats = new HashMap>(); Aggregation aggregation = response.getAggregations().get(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field()); for (Terms.Bucket value : ((Terms) aggregation).getBuckets()) { -- 2.39.5