@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+55 -28
+55 -28
src/applications/config/check/PhabricatorElasticSearchSetupCheck.php
··· 7 7 } 8 8 9 9 protected function executeChecks() { 10 - if ($this->shouldUseElasticSearchEngine()) { 11 - $engine = new PhabricatorElasticSearchEngine(); 10 + if (!$this->shouldUseElasticSearchEngine()) { 11 + return; 12 + } 12 13 13 - if (!$engine->indexExists()) { 14 - $summary = pht( 15 - 'You enabled Elasticsearch but the index does not exist.'); 14 + $engine = new PhabricatorElasticSearchEngine(); 16 15 17 - $message = pht( 18 - 'You likely enabled search.elastic.host without creating the '. 19 - 'index. Run `./bin/search init` to correct the index.'); 16 + $index_exists = null; 17 + $index_sane = null; 18 + try { 19 + $index_exists = $engine->indexExists(); 20 + if ($index_exists) { 21 + $index_sane = $engine->indexIsSane(); 22 + } 23 + } catch (Exception $ex) { 24 + $summary = pht('Elasticsearch is not reachable as configured.'); 25 + $message = pht( 26 + 'Elasticsearch is configured (with the %s setting) but Phabricator '. 27 + 'encountered an exception when trying to test the index.'. 28 + "\n\n". 29 + '%s', 30 + phutil_tag('tt', array(), 'search.elastic.host'), 31 + phutil_tag('pre', array(), $ex->getMessage())); 32 + 33 + $this->newIssue('elastic.misconfigured') 34 + ->setName(pht('Elasticsearch Misconfigured')) 35 + ->setSummary($summary) 36 + ->setMessage($message) 37 + ->addRelatedPhabricatorConfig('search.elastic.host'); 38 + return; 39 + } 40 + 41 + if (!$index_exists) { 42 + $summary = pht( 43 + 'You enabled Elasticsearch but the index does not exist.'); 44 + 45 + $message = pht( 46 + 'You likely enabled search.elastic.host without creating the '. 47 + 'index. Run `./bin/search init` to correct the index.'); 20 48 21 - $this 22 - ->newIssue('elastic.missing-index') 23 - ->setName(pht('Elasticsearch index Not Found')) 24 - ->setSummary($summary) 25 - ->setMessage($message) 26 - ->addRelatedPhabricatorConfig('search.elastic.host'); 27 - } else if (!$engine->indexIsSane()) { 28 - $summary = pht( 29 - 'Elasticsearch index exists but needs correction.'); 49 + $this 50 + ->newIssue('elastic.missing-index') 51 + ->setName(pht('Elasticsearch index Not Found')) 52 + ->setSummary($summary) 53 + ->setMessage($message) 54 + ->addRelatedPhabricatorConfig('search.elastic.host'); 55 + } else if (!$index_sane) { 56 + $summary = pht( 57 + 'Elasticsearch index exists but needs correction.'); 30 58 31 - $message = pht( 32 - 'Either the Phabricator schema for Elasticsearch has changed '. 33 - 'or Elasticsearch created the index automatically. Run '. 34 - '`./bin/search init` to correct the index.'); 59 + $message = pht( 60 + 'Either the Phabricator schema for Elasticsearch has changed '. 61 + 'or Elasticsearch created the index automatically. Run '. 62 + '`./bin/search init` to correct the index.'); 35 63 36 - $this 37 - ->newIssue('elastic.broken-index') 38 - ->setName(pht('Elasticsearch index Incorrect')) 39 - ->setSummary($summary) 40 - ->setMessage($message); 41 - } 64 + $this 65 + ->newIssue('elastic.broken-index') 66 + ->setName(pht('Elasticsearch index Incorrect')) 67 + ->setSummary($summary) 68 + ->setMessage($message); 42 69 } 43 70 } 44 71 45 72 protected function shouldUseElasticSearchEngine() { 46 73 $search_engine = PhabricatorSearchEngine::loadEngine(); 47 - return $search_engine instanceof PhabricatorElasticSearchEngine; 74 + return ($search_engine instanceof PhabricatorElasticSearchEngine); 48 75 } 49 76 50 77 }