From f5a9d1f8d47bff1b5ba5e59a7b096fd0746a83cc Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 20 May 2015 14:21:46 -0700 Subject: [PATCH] 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 --- .../PhabricatorElasticSearchSetupCheck.php | 87 ++++++++++++------- 1 file changed, 57 insertions(+), 30 deletions(-) diff --git a/src/applications/config/check/PhabricatorElasticSearchSetupCheck.php b/src/applications/config/check/PhabricatorElasticSearchSetupCheck.php index a573c14490..47a3cb4b18 100644 --- a/src/applications/config/check/PhabricatorElasticSearchSetupCheck.php +++ b/src/applications/config/check/PhabricatorElasticSearchSetupCheck.php @@ -7,44 +7,71 @@ final class PhabricatorElasticSearchSetupCheck extends PhabricatorSetupCheck { } protected function executeChecks() { - if ($this->shouldUseElasticSearchEngine()) { - $engine = new PhabricatorElasticSearchEngine(); + if (!$this->shouldUseElasticSearchEngine()) { + return; + } - if (!$engine->indexExists()) { - $summary = pht( - 'You enabled Elasticsearch but the index does not exist.'); + $engine = new PhabricatorElasticSearchEngine(); - $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 (!$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); + $index_exists = null; + $index_sane = null; + try { + $index_exists = $engine->indexExists(); + if ($index_exists) { + $index_sane = $engine->indexIsSane(); } + } 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() { $search_engine = PhabricatorSearchEngine::loadEngine(); - return $search_engine instanceof PhabricatorElasticSearchEngine; + return ($search_engine instanceof PhabricatorElasticSearchEngine); } }