Skip to content

Commit

Permalink
[Core] Feature Smile-SA#3432, add the generic warning message about c…
Browse files Browse the repository at this point in the history
…luster misconfig
  • Loading branch information
vahonc committed Nov 25, 2024
1 parent f5f2e8f commit c416056
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 523 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,123 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Vadym Honcharuk <[email protected]>
* @copyright 2024 Smile
* @license Open Software License ("OSL") v. 3.0
*/

namespace Smile\ElasticsuiteCore\Model\System\Message;

use Magento\Framework\UrlInterface;
use Magento\Framework\Notification\MessageInterface;
use Smile\ElasticsuiteCore\Healthcheck\HealthcheckList;

/**
* Class GenericWarningAboutClusterMisconfig
*/
class GenericWarningAboutClusterMisconfig implements MessageInterface
{
/**
* Route to Elasticsuite -> Healthcheck page.
*/
private const ROUTE_ELASTICSUITE_HEALTHCHECK = 'smile_elasticsuite/healthcheck/index';

/**
* @var HealthcheckList
*/
private $healthcheckList;

/**
* @var UrlInterface
*/
private $urlBuilder;

public const WARNING_STATUS = 'warning';

/**
* Constructor.
*
* @param HealthcheckList $healthcheckList Health check list object.
* @param UrlInterface $urlBuilder URL builder.
*/
public function __construct(
HealthcheckList $healthcheckList,
UrlInterface $urlBuilder
) {
$this->healthcheckList = $healthcheckList;
$this->urlBuilder = $urlBuilder;
}

/**
* {@inheritdoc}
*/
public function isDisplayed()
{
return $this->getIssueCount() > 0;
}

/**
* {@inheritdoc}
*/
public function getIdentity()
{
return hash('sha256', 'ELASTICSUITE_GENERIC_WARNING');
}

/**
* {@inheritdoc}
*/
public function getSeverity()
{
return self::SEVERITY_MAJOR;
}

/**
* {@inheritdoc}
*/
public function getText()
{
$issuesCount = $this->getIssueCount();

return __(
'You have <strong>%1 health checks</strong> in a <strong>warning</strong> state. '
. 'Please head to the <a href="%2"><strong>Elasticsuite Healthcheck</strong></a> page to get more details and see how to fix them.',
$issuesCount,
$this->getElasticsuiteHealthcheckUrl()
);
}

/**
* Counts the number of health check issues in an error state.
*
* @return int
*/
private function getIssueCount(): int
{
$issuesCount = 0;

foreach ($this->healthcheckList->getChecks() as $check) {
if ($check->getStatus() === self::WARNING_STATUS) {
$issuesCount++;
}
}

return $issuesCount;
}

/**
* Retrieve a URL to the Elasticsuite Healthcheck page for more information.
*
* @return string
*/
private function getElasticsuiteHealthcheckUrl(): string
{
return $this->urlBuilder->getUrl(self::ROUTE_ELASTICSUITE_HEALTHCHECK);
}
}

This file was deleted.

14 changes: 13 additions & 1 deletion src/module-elasticsuite-core/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@
<arguments>
<argument name="messages" xsi:type="array">
<item name="elasticsuite" xsi:type="string">Smile\ElasticsuiteCore\Model\System\Message\NotificationAboutVersions</item>
<item name="elasticsuite_cluster_replicas_misconfig_warning" xsi:type="string">Smile\ElasticsuiteCore\Model\System\Message\WarningAboutClusterReplicasMisconfig</item>
<!-- Generic warning class -->
<item name="elasticsuite_cluster_generic_misconfig_warning" xsi:type="string">Smile\ElasticsuiteCore\Model\System\Message\GenericWarningAboutClusterMisconfig</item>
</argument>
</arguments>
</type>

<!-- Elasticsuite Health Check -->
<type name="Smile\ElasticsuiteCore\Healthcheck\HealthcheckList">
<arguments>
<argument name="checks" xsi:type="array">
<item name="ghost_indices_check" xsi:type="object">Smile\ElasticsuiteCore\Healthcheck\GhostIndicesCheck</item>
<item name="shards_config_check" xsi:type="object">Smile\ElasticsuiteCore\Healthcheck\ShardsConfigCheck</item>
<item name="replicas_config_check" xsi:type="object">Smile\ElasticsuiteCore\Healthcheck\ReplicasConfigCheck</item>
</argument>
</arguments>
</type>
Expand Down
Loading

0 comments on commit c416056

Please sign in to comment.