[MediaWiki-commits] [Gerrit] search/extra[master]: Add new Load Shedding Router

2017-09-04 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/370778 )

Change subject: Add new Load Shedding Router
..


Add new Load Shedding Router

Add a new load shedding router than can decide on a query
to run based on load information about the local node. This
should help to ride out problems with less user visible
effect.

TODO (maybe later):
* Custom stats output about how many times it was triggered.
 Unfortunately I havn't found any good way to hook into elasticsearch's
 stats collection yet.
* Use the size of some thread pool queue as a trigger condition. Have
 not investigated how viable this is.
* Use latency percentiles (p95, etc) as a trigger condition

Change-Id: I0abe91ccf2f628b03621a7f7f0fe634c52c039af
---
A docs/degraded_router.md
M src/main/java/org/wikimedia/search/extra/ExtraPlugin.java
A 
src/main/java/org/wikimedia/search/extra/router/DegradedRouterQueryBuilder.java
M src/test/java/org/wikimedia/search/extra/QueryBuilderTestUtils.java
A 
src/test/java/org/wikimedia/search/extra/router/DegradedRouterBuilderESTest.java
A 
src/test/java/org/wikimedia/search/extra/router/DegradedRouterQueryBuilderParserTest.java
M 
src/test/java/org/wikimedia/search/extra/router/TokenCountRouterBuilderESTest.java
7 files changed, 445 insertions(+), 3 deletions(-)

Approvals:
  jenkins-bot: Verified
  DCausse: Looks good to me, approved



diff --git a/docs/degraded_router.md b/docs/degraded_router.md
new file mode 100644
index 000..c727c2f
--- /dev/null
+++ b/docs/degraded_router.md
@@ -0,0 +1,48 @@
+degraded_router
+===
+
+The ```degraded_router``` is a simple query wrapper that allows
+routing queries based on the load of individual node. It's useful
+to prevent overloaded servers from having an outside effect on end
+user latency by running a cheaper query when the server is loaded.
+
+Example
+---
+
+GET /_search
+{
+"degraded_router": {
+"fallback": {
+"phrase_match": {
+"content": "what should we do today?",
+}
+}
+"conditions": [
+{
+"gte": 70,
+"type": "cpu",
+"query": {
+"match": {
+"content": "what should we do today?"
+}
+}
+}
+]
+}
+}
+
+A match query will be issued if system cpu usage is above 70%. Otherwise
+a phrase match query will be issued.
+
+Options
+---
+
+* `fallback` The query to apply if none of the conditions applies.
+* `conditions` Array of conditions (the first that matches wins):
+* `type`: The type of metric to compare against. Can be `cpu` for cpu%, or
+  `load`for 1 minute load average.
+* `predicate` : can be `eq`, `gt`, `gte`, `lt`, or `lte`, the value is the 
number
+to compare against the value reported by `type`
+* `query` The query to apply if the condition is met.
+
+Note that the query parser does not check the conditions coherence
diff --git a/src/main/java/org/wikimedia/search/extra/ExtraPlugin.java 
b/src/main/java/org/wikimedia/search/extra/ExtraPlugin.java
index 8b69695..229ccaa 100644
--- a/src/main/java/org/wikimedia/search/extra/ExtraPlugin.java
+++ b/src/main/java/org/wikimedia/search/extra/ExtraPlugin.java
@@ -1,7 +1,9 @@
 package org.wikimedia.search.extra;
 
+import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.index.analysis.TokenFilterFactory;
 import org.elasticsearch.indices.analysis.AnalysisModule.AnalysisProvider;
+import org.elasticsearch.monitor.os.OsService;
 import org.elasticsearch.plugins.AnalysisPlugin;
 import org.elasticsearch.plugins.Plugin;
 import org.elasticsearch.plugins.ScriptPlugin;
@@ -11,6 +13,7 @@
 import org.wikimedia.search.extra.fuzzylike.FuzzyLikeThisQueryBuilder;
 import org.wikimedia.search.extra.levenshtein.LevenshteinDistanceScoreBuilder;
 import org.wikimedia.search.extra.regex.SourceRegexQueryBuilder;
+import org.wikimedia.search.extra.router.DegradedRouterQueryBuilder;
 import org.wikimedia.search.extra.router.TokenCountRouterQueryBuilder;
 import org.wikimedia.search.extra.superdetectnoop.ChangeHandler;
 import org.wikimedia.search.extra.superdetectnoop.SetHandler;
@@ -31,6 +34,14 @@
  * Setup the Elasticsearch plugin.
  */
 public class ExtraPlugin extends Plugin implements SearchPlugin, 
AnalysisPlugin, ScriptPlugin {
+
+private OsService osService;
+
+public ExtraPlugin(Settings settings) {
+// TODO: This collects way more info than we care about
+osService = new OsService(settings);
+}
+
 /**
  * Register our parsers.
  */
@@ -40,7 +51,8 @@
 return Arrays.asList(
 new QuerySpec<>(SourceRegexQueryBuilder.NAME, 
SourceRegexQueryBuilder::new, SourceRegexQueryBuilder::fromXContent),
 new QuerySpec<>(FuzzyLikeThisQueryBuilder.NAME, 

[MediaWiki-commits] [Gerrit] search/extra[master]: Add new Load Shedding Router

2017-08-08 Thread EBernhardson (Code Review)
EBernhardson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/370778 )

Change subject: Add new Load Shedding Router
..

Add new Load Shedding Router

Add a new load shedding router than can decide on a query
to run based on load information about the local node. This
should help to ride out problems with less user visible
effect.

TODO (maybe later):
* Custom stats output about how many times it was triggered.
 Unfortunately I havn't found any good way to hook into elasticsearch's
 stats collection yet.
* Use the size of some thread pool queue as a trigger condition. Have
 not investigated how viable this is.
* Use latency percentiles (p95, etc) as a trigger condition

Change-Id: I0abe91ccf2f628b03621a7f7f0fe634c52c039af
---
A docs/degraded_router.md
M src/main/java/org/wikimedia/search/extra/ExtraPlugin.java
M 
src/main/java/org/wikimedia/search/extra/router/AbstractRouterQueryBuilder.java
A 
src/main/java/org/wikimedia/search/extra/router/DegradedRouterQueryBuilder.java
M 
src/main/java/org/wikimedia/search/extra/router/TokenCountRouterQueryBuilder.java
A 
src/test/java/org/wikimedia/search/extra/router/DegradedRouterBuilderESTest.java
A 
src/test/java/org/wikimedia/search/extra/router/DegradedRouterQueryBuilderParserTest.java
M 
src/test/java/org/wikimedia/search/extra/router/TokenCountRouterBuilderESTest.java
M 
src/test/java/org/wikimedia/search/extra/router/TokenCountRouterQueryIntegrationTest.java
9 files changed, 477 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/search/extra 
refs/changes/78/370778/1

diff --git a/docs/degraded_router.md b/docs/degraded_router.md
new file mode 100644
index 000..c727c2f
--- /dev/null
+++ b/docs/degraded_router.md
@@ -0,0 +1,48 @@
+degraded_router
+===
+
+The ```degraded_router``` is a simple query wrapper that allows
+routing queries based on the load of individual node. It's useful
+to prevent overloaded servers from having an outside effect on end
+user latency by running a cheaper query when the server is loaded.
+
+Example
+---
+
+GET /_search
+{
+"degraded_router": {
+"fallback": {
+"phrase_match": {
+"content": "what should we do today?",
+}
+}
+"conditions": [
+{
+"gte": 70,
+"type": "cpu",
+"query": {
+"match": {
+"content": "what should we do today?"
+}
+}
+}
+]
+}
+}
+
+A match query will be issued if system cpu usage is above 70%. Otherwise
+a phrase match query will be issued.
+
+Options
+---
+
+* `fallback` The query to apply if none of the conditions applies.
+* `conditions` Array of conditions (the first that matches wins):
+* `type`: The type of metric to compare against. Can be `cpu` for cpu%, or
+  `load`for 1 minute load average.
+* `predicate` : can be `eq`, `gt`, `gte`, `lt`, or `lte`, the value is the 
number
+to compare against the value reported by `type`
+* `query` The query to apply if the condition is met.
+
+Note that the query parser does not check the conditions coherence
diff --git a/src/main/java/org/wikimedia/search/extra/ExtraPlugin.java 
b/src/main/java/org/wikimedia/search/extra/ExtraPlugin.java
index acbb84f..e9ed04c 100644
--- a/src/main/java/org/wikimedia/search/extra/ExtraPlugin.java
+++ b/src/main/java/org/wikimedia/search/extra/ExtraPlugin.java
@@ -1,7 +1,10 @@
 package org.wikimedia.search.extra;
 
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.index.IndexModule;
 import org.elasticsearch.index.analysis.TokenFilterFactory;
 import org.elasticsearch.indices.analysis.AnalysisModule.AnalysisProvider;
+import org.elasticsearch.monitor.os.OsService;
 import org.elasticsearch.plugins.AnalysisPlugin;
 import org.elasticsearch.plugins.Plugin;
 import org.elasticsearch.plugins.ScriptPlugin;
@@ -17,7 +20,8 @@
 import org.wikimedia.search.extra.superdetectnoop.VersionedDocumentHandler;
 import org.wikimedia.search.extra.superdetectnoop.WithinAbsoluteHandler;
 import org.wikimedia.search.extra.superdetectnoop.WithinPercentageHandler;
-import org.wikimedia.search.extra.tokencount.TokenCountRouterQueryBuilder;
+import org.wikimedia.search.extra.router.DegradedRouterQueryBuilder;
+import org.wikimedia.search.extra.router.TokenCountRouterQueryBuilder;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -31,6 +35,14 @@
  * Setup the Elasticsearch plugin.
  */
 public class ExtraPlugin extends Plugin implements SearchPlugin, 
AnalysisPlugin, ScriptPlugin {
+
+OsService osService;
+
+public ExtraPlugin(Settings settings) {
+// TODO: This collects way more info than we care about
+osService = new OsService(settings);
+}
+
 /**
  * Register our parsers.
  */
@@ -40,7