1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 09:20:58 +01:00

Raise a setup issue for misconfigured Elasticsearch

Summary: Fixes T8274. That report is very light on details, but I think the issue is that their Elasticsearch is misconfigured and the new setup warning dies a little too hard if the server is just completely dead.

Test Plan: Set `search.elastic.host` to an invalid server, got a similar-looking exception (?), applied patch, got a setup warning instead.

Reviewers: btrahan, joshuaspence

Reviewed By: btrahan, joshuaspence

Subscribers: epriestley

Maniphest Tasks: T8274

Differential Revision: https://secure.phabricator.com/D12948
This commit is contained in:
epriestley 2015-05-20 14:21:46 -07:00
parent f99c7beb90
commit f5a9d1f8d4

View file

@ -7,44 +7,71 @@ final class PhabricatorElasticSearchSetupCheck extends PhabricatorSetupCheck {
} }
protected function executeChecks() { protected function executeChecks() {
if ($this->shouldUseElasticSearchEngine()) { if (!$this->shouldUseElasticSearchEngine()) {
$engine = new PhabricatorElasticSearchEngine(); return;
}
if (!$engine->indexExists()) { $engine = new PhabricatorElasticSearchEngine();
$summary = pht(
'You enabled Elasticsearch but the index does not exist.');
$message = pht( $index_exists = null;
'You likely enabled search.elastic.host without creating the '. $index_sane = null;
'index. Run `./bin/search init` to correct the index.'); try {
$index_exists = $engine->indexExists();
$this if ($index_exists) {
->newIssue('elastic.missing-index') $index_sane = $engine->indexIsSane();
->setName(pht('Elasticsearch index Not Found'))
->setSummary($summary)
->setMessage($message)
->addRelatedPhabricatorConfig('search.elastic.host');
} else if (!$engine->indexIsSane()) {
$summary = pht(
'Elasticsearch index exists but needs correction.');
$message = pht(
'Either the Phabricator schema for Elasticsearch has changed '.
'or Elasticsearch created the index automatically. Run '.
'`./bin/search init` to correct the index.');
$this
->newIssue('elastic.broken-index')
->setName(pht('Elasticsearch index Incorrect'))
->setSummary($summary)
->setMessage($message);
} }
} catch (Exception $ex) {
$summary = pht('Elasticsearch is not reachable as configured.');
$message = pht(
'Elasticsearch is configured (with the %s setting) but Phabricator '.
'encountered an exception when trying to test the index.'.
"\n\n".
'%s',
phutil_tag('tt', array(), 'search.elastic.host'),
phutil_tag('pre', array(), $ex->getMessage()));
$this->newIssue('elastic.misconfigured')
->setName(pht('Elasticsearch Misconfigured'))
->setSummary($summary)
->setMessage($message)
->addRelatedPhabricatorConfig('search.elastic.host');
return;
}
if (!$index_exists) {
$summary = pht(
'You enabled Elasticsearch but the index does not exist.');
$message = pht(
'You likely enabled search.elastic.host without creating the '.
'index. Run `./bin/search init` to correct the index.');
$this
->newIssue('elastic.missing-index')
->setName(pht('Elasticsearch index Not Found'))
->setSummary($summary)
->setMessage($message)
->addRelatedPhabricatorConfig('search.elastic.host');
} else if (!$index_sane) {
$summary = pht(
'Elasticsearch index exists but needs correction.');
$message = pht(
'Either the Phabricator schema for Elasticsearch has changed '.
'or Elasticsearch created the index automatically. Run '.
'`./bin/search init` to correct the index.');
$this
->newIssue('elastic.broken-index')
->setName(pht('Elasticsearch index Incorrect'))
->setSummary($summary)
->setMessage($message);
} }
} }
protected function shouldUseElasticSearchEngine() { protected function shouldUseElasticSearchEngine() {
$search_engine = PhabricatorSearchEngine::loadEngine(); $search_engine = PhabricatorSearchEngine::loadEngine();
return $search_engine instanceof PhabricatorElasticSearchEngine; return ($search_engine instanceof PhabricatorElasticSearchEngine);
} }
} }