summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2017-04-19 22:52:00 +0200
committerDylan William Hardison <dylan@hardison.net>2017-05-24 20:24:54 +0200
commitffe838a923696f81e8d8e1f24c5dc7a568cbc6ac (patch)
tree92894c1e927204b529759e8c3e9078720ce5e8bc
parent50fc9d77128db4f8565265047166c6ef61bac5c5 (diff)
downloadbugzilla-ffe838a923696f81e8d8e1f24c5dc7a568cbc6ac.tar.gz
bugzilla-ffe838a923696f81e8d8e1f24c5dc7a568cbc6ac.tar.xz
Bug 1348380 - Add param and user setting to control elasticsearch behavior
1) add an 'elasticsearch' param (configured via admin.cgi) that turns off all code that would attempt to connect to elasticsearch. 2) add a user preference that controls using elasticsearch for searches, which defaults to off for logged-in users. Anonymous users will default to using elasticsearch for the greater good. Note that elasticsearch, if available, will still power user-autocompletion (unless turned off as by the above parameter).
-rw-r--r--Bugzilla/Config/Elastic.pm29
-rw-r--r--Bugzilla/Elastic.pm15
-rw-r--r--Bugzilla/Install.pm6
-rwxr-xr-xbuglist.cgi11
-rw-r--r--template/en/default/admin/params/elastic.html.tmpl2
-rw-r--r--template/en/default/global/setting-descs.none.tmpl1
6 files changed, 47 insertions, 17 deletions
diff --git a/Bugzilla/Config/Elastic.pm b/Bugzilla/Config/Elastic.pm
index 2b2513f1b..690f5fac5 100644
--- a/Bugzilla/Config/Elastic.pm
+++ b/Bugzilla/Config/Elastic.pm
@@ -16,18 +16,23 @@ use Bugzilla::Config::Common;
our $sortkey = 1550;
sub get_param_list {
- return (
- {
- name => 'elasticsearch_nodes',
- type => 't',
- default => 'localhost:9200',
- },
- {
- name => 'elasticsearch_index',
- type => 't',
- default => 'bugzilla',
- },
- );
+ return (
+ {
+ name => 'elasticsearch',
+ type => 'b',
+ default => 0,
+ },
+ {
+ name => 'elasticsearch_nodes',
+ type => 't',
+ default => 'localhost:9200',
+ },
+ {
+ name => 'elasticsearch_index',
+ type => 't',
+ default => 'bugzilla',
+ },
+ );
}
1;
diff --git a/Bugzilla/Elastic.pm b/Bugzilla/Elastic.pm
index 6384269fd..fa032d2a6 100644
--- a/Bugzilla/Elastic.pm
+++ b/Bugzilla/Elastic.pm
@@ -16,6 +16,12 @@ with 'Bugzilla::Elastic::Role::HasIndexName';
sub suggest_users {
my ($self, $text) = @_;
+
+ unless (Bugzilla->params->{elasticsearch}) {
+ # optimization: faster than a regular method call.
+ goto &_suggest_users_fallback;
+ }
+
my $field = 'suggest_user';
if ($text =~ /^:(.+)$/) {
$text = $1;
@@ -38,10 +44,15 @@ sub suggest_users {
}
else {
warn "suggest_users error: $@";
- my $users = Bugzilla::User::match($text, 25, 0);
- return [ map { { real_name => $_->name, name => $_->login } } @$users];
+ # optimization: faster than a regular method call.
+ goto &_suggest_users_fallback;
}
}
+sub _suggest_users_fallback {
+ my ($self, $text) = @_;
+ my $users = Bugzilla::User::match($text, 25, 0);
+ return [ map { { real_name => $_->name, name => $_->login } } @$users];
+}
1;
diff --git a/Bugzilla/Install.pm b/Bugzilla/Install.pm
index edadbfecb..982f4a4fb 100644
--- a/Bugzilla/Install.pm
+++ b/Bugzilla/Install.pm
@@ -175,6 +175,12 @@ sub SETTINGS {
default => 'off',
category => 'API'
},
+ {
+ name => 'use_elasticsearch',
+ options => ['on', 'off'],
+ default => 'off',
+ category => 'Searching'
+ },
];
};
diff --git a/buglist.cgi b/buglist.cgi
index fa6bb060f..d2c6545b7 100755
--- a/buglist.cgi
+++ b/buglist.cgi
@@ -692,11 +692,18 @@ my $fallback_search = Bugzilla::Search->new(fields => [@selectcolumns],
order => [@order_columns],
sharer => $sharer_id);
+# Not-logged-in users get elasticsearch if possible
+my $elastic_default = !$user->id || $user->setting('use_elasticsearch') eq 'on';
+
my $search;
-my $elastic = $cgi->param('elastic') // 1;
+my $elastic = $cgi->param('elastic') // $elastic_default;
if (defined $cgi->param('elastic')) {
- $vars->{was_elastic} = 1;
+ $vars->{was_elastic} = $elastic;
}
+
+# If turned off in the admin section, it is always off.
+$elastic = 0 unless Bugzilla->params->{elasticsearch};
+
if ($elastic) {
local $SIG{__DIE__} = undef;
local $SIG{__WARN__} = undef;
diff --git a/template/en/default/admin/params/elastic.html.tmpl b/template/en/default/admin/params/elastic.html.tmpl
index 47ec088b5..dc5459920 100644
--- a/template/en/default/admin/params/elastic.html.tmpl
+++ b/template/en/default/admin/params/elastic.html.tmpl
@@ -11,8 +11,8 @@
%]
[% param_descs = {
+ elasticsearch => "Enable or disable elasticsearch feature."
elasticsearch_nodes =>
- "If this option is set, $terms.Bugzilla will integrate with Elasticsearch. " _
"Specify one of more server, separated by spaces, using hostname[:port] " _
"notation (for example: localhost).",
diff --git a/template/en/default/global/setting-descs.none.tmpl b/template/en/default/global/setting-descs.none.tmpl
index 368987da6..ba001ab6d 100644
--- a/template/en/default/global/setting-descs.none.tmpl
+++ b/template/en/default/global/setting-descs.none.tmpl
@@ -56,6 +56,7 @@
"possible_duplicates" => "Display possible duplicates when reporting a new $terms.bug",
"requestee_cc" => "Automatically add me to the CC list of $terms.bugs I am requested to review",
"api_key_only" => "Require API key authentication for API requests",
+ "use_elasticsearch" => "Use elasticsearch for $terms.bug searches when possible",
}
%]