Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-619] Base health checks on time instead of quantity. #3

Merged
merged 9 commits into from
Feb 20, 2019
84 changes: 54 additions & 30 deletions Command/HealthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use MauticPlugin\MauticHealthBundle\Model\HealthModel;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand All @@ -31,17 +32,29 @@ protected function configure()
{
$this->setName('mautic:health:check')
->setDescription('General all purpose health check.')
// ->addOption(
// 'campaign-rebuild-delay',
// null,
// InputOption::VALUE_OPTIONAL,
// 'The maximum number of contacts waiting to be ingested into a campaign from a segment.'
// )
->addOption(
'campaign-rebuild-threshold',
'campaign-kickoff-delay',
null,
InputOption::VALUE_OPTIONAL,
'The maximum number of contacts waiting to be ingested into a campaign from a segment.'
'The maximum number of seconds average allowed for kickoff events at the top of the campaign.'
)
->addOption(
'campaign-trigger-threshold',
'campaign-scheduled-delay',
null,
InputOption::VALUE_OPTIONAL,
'The maximum number of contacts waiting for scheduled campaign events to fire which are late.'
'The maximum number of seconds average allowed for scheduled events (beyond the intended delays).'
)
->addOption(
'campaign-inactive-delay',
null,
InputOption::VALUE_OPTIONAL,
'The maximum number of seconds average allowed for inactive events (decisions).'
);

parent::configure();
Expand All @@ -55,48 +68,59 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$verbose = $input->getOption('verbose');
$campaignRebuildThreshold = $input->getOption('campaign-rebuild-threshold');
$campaignTriggerThreshold = $input->getOption('campaign-trigger-threshold');
$quiet = $input->getOption('quiet');
$container = $this->getContainer();
$translator = $container->get('translator');
// $campaignRebuildDelay = $input->getOption('campaign-rebuild-delay');
$campaignKickoffDelay = $input->getOption('campaign-kickoff-delay');
$campaignScheduledDelay = $input->getOption('campaign-scheduled-delay');
$campaignInactiveDelay = $input->getOption('campaign-inactive-delay');
$quiet = $input->getOption('quiet');
$container = $this->getContainer();
$translator = $container->get('translator');

if ($quiet) {
$output = new NullOutput();
}
if (!$this->checkRunStatus($input, $output)) {
return 0;
}

/** @var HealthModel $healthModel */
$healthModel = $container->get('mautic.health.model.health');
if ($verbose) {
$output->writeln(
'<info>'.$translator->trans(
'mautic.health.running'
).'</info>'
);
}
$output->writeln('<info>'.$translator->trans('mautic.health.running').'</info>');
$settings = [];
if ($campaignRebuildThreshold) {
$settings['campaign_rebuild_threshold'] = $campaignRebuildThreshold;
// if ($campaignRebuildDelay) {
// $settings['campaign_rebuild_delay'] = $campaignRebuildDelay;
// }
if ($campaignKickoffDelay) {
$settings['campaign_kickoff_delay'] = $campaignKickoffDelay;
}
if ($campaignTriggerThreshold) {
$settings['campaign_trigger_threshold'] = $campaignTriggerThreshold;
if ($campaignScheduledDelay) {
$settings['campaign_scheduled_delay'] = $campaignScheduledDelay;
}
if ($campaignInactiveDelay) {
$settings['campaign_inactive_delay'] = $campaignInactiveDelay;
}
if ($settings) {
$healthModel->setSettings($settings);
}
$healthModel->campaignRebuildCheck($output, $verbose);
$healthModel->campaignTriggerCheck($output, $verbose);

$output->writeln('<info>'.$translator->trans('mautic.health.kickoff').'</info>');
$healthModel->campaignKickoffCheck($output);

$output->writeln('<info>'.$translator->trans('mautic.health.scheduled').'</info>');
$healthModel->campaignScheduledCheck($output);

// @todo - Add negative action path check.
// $healthModel->campaignRebuildCheck($output, $verbose);
$healthModel->setCache();

if (!$quiet) {
$healthModel->reportIncidents($output);
}
if ($verbose) {
$output->writeln(
'<info>'.$translator->trans(
'mautic.health.complete'
).'</info>'
);
}
$output->writeln(
'<info>'.$translator->trans(
'mautic.health.complete'
).'</info>'
);
$this->completeRun();

return 0;
Expand Down
12 changes: 11 additions & 1 deletion Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@
'author' => 'Mautic',

'services' => [
'models' => [
'models' => [
'mautic.health.model.health' => [
'class' => 'MauticPlugin\MauticHealthBundle\Model\HealthModel',
'arguments' => [
'doctrine.orm.entity_manager',
'mautic.helper.integration',
'mautic.campaign.model.campaign',
'mautic.campaign.model.event',
],
],
],
'events' => [
'mautic.health.dashboard.subscriber' => [
'class' => 'MauticPlugin\MauticHealthBundle\EventListener\DashboardSubscriber',
'arguments' => [
'mautic.health.model.health',
],
],
],
Expand Down
83 changes: 83 additions & 0 deletions EventListener/DashboardSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/*
* @copyright 2018 Mautic Contributors. All rights reserved
* @author Digital Media Solutions, LLC
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace MauticPlugin\MauticHealthBundle\EventListener;

use Mautic\DashboardBundle\Event\WidgetDetailEvent;
use Mautic\DashboardBundle\EventListener\DashboardSubscriber as MainDashboardSubscriber;
use MauticPlugin\MauticHealthBundle\Model\HealthModel;

/**
* Class DashboardSubscriber.
*/
class DashboardSubscriber extends MainDashboardSubscriber
{
/**
* Define the name of the bundle/category of the widget(s).
*
* @var string
*/
protected $bundle = 'campaign';

/**
* Define the widget(s).
*
* @var string
*/
protected $types = [
'campaign.health' => [],
];

/**
* @var HealthModel
*/
protected $healthModel;

/**
* DashboardSubscriber constructor.
*
* @param HealthModel $healthModel
*/
public function __construct(HealthModel $healthModel)
{
$this->healthModel = $healthModel;
}

/**
* Set a widget detail when needed.
*
* @param WidgetDetailEvent $event
*/
public function onWidgetDetailGenerate(WidgetDetailEvent $event)
{
// This always pulls from cached data from the cron task.
// if (!$event->isCached()) {
// }
$cache = $this->healthModel->getCache();
$widget = $event->getWidget();
if ($widget->getHeight() < 330) {
$widget->setHeight(330);
}
$params = $widget->getParams();
$data = [];
$data['params'] = $params;
scottshipman marked this conversation as resolved.
Show resolved Hide resolved
$data['height'] = $widget->getHeight();
$data['delays'] = isset($cache['delays']) ? $cache['delays'] : [];
$data['lastCached'] = isset($cache['lastCached']) ? $cache['lastCached'] : null;
$event->setTemplateData(['data' => $data]);

if ('campaign.health' == $event->getType()) {
$event->setTemplate('MauticHealthBundle:Widgets:health.html.php');
}

$event->stopPropagation();
}
}
40 changes: 31 additions & 9 deletions Integration/HealthIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function setComponentStatus($incidentStatus = null, $componentStatus = nu
}
if ($change) {
// Update/Close the incident.
if (!empty($lastUpdate)) {
if (!empty($lastUpdate) && is_array($lastUpdate['affected_components'])) {
foreach ($lastUpdate['affected_components'] as $affectedComponent) {
if (!empty($affectedComponent['id'])) {
$componentIds[] = $affectedComponent['id'];
Expand Down Expand Up @@ -368,25 +368,47 @@ public function getRequiredKeyFields()
public function appendToForm(&$builder, $data, $formArea)
{
if ('features' == $formArea) {
// $builder->add(
// 'campaign_rebuild_delay',
// 'number',
// [
// 'label' => $this->translator->trans('mautic.health.campaign_rebuild_delay'),
// 'data' => !isset($data['campaign_rebuild_delay']) ? 10000 : $data['campaign_rebuild_delay'],
// 'attr' => [
// 'tooltip' => $this->translator->trans('mautic.health.campaign_rebuild_delay.tooltip'),
// ],
// ]
// );
$builder->add(
'campaign_rebuild_threshold',
'campaign_kickoff_delay',
'number',
[
'label' => $this->translator->trans('mautic.health.campaign_rebuild_threshold'),
'data' => !isset($data['campaign_rebuild_threshold']) ? 10000 : $data['campaign_rebuild_threshold'],
'label' => $this->translator->trans('mautic.health.campaign_kickoff_delay'),
'data' => !isset($data['campaign_kickoff_delay']) ? 3600 : $data['campaign_kickoff_delay'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.health.campaign_rebuild_threshold.tooltip'),
'tooltip' => $this->translator->trans('mautic.health.campaign_kickoff_delay.tooltip'),
],
]
);
$builder->add(
'campaign_trigger_threshold',
'campaign_scheduled_delay',
'number',
[
'label' => $this->translator->trans('mautic.health.campaign_trigger_threshold'),
'data' => !isset($data['campaign_trigger_threshold']) ? 1000 : $data['campaign_trigger_threshold'],
'label' => $this->translator->trans('mautic.health.campaign_scheduled_delay'),
'data' => !isset($data['campaign_scheduled_delay']) ? 3600 : $data['campaign_scheduled_delay'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.health.campaign_trigger_threshold.tooltip'),
'tooltip' => $this->translator->trans('mautic.health.campaign_scheduled_delay.tooltip'),
],
]
);
$builder->add(
'campaign_inactive_delay',
'number',
[
'label' => $this->translator->trans('mautic.health.campaign_inactive_delay'),
'data' => !isset($data['campaign_inactive_delay']) ? 3600 : $data['campaign_inactive_delay'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.health.campaign_inactive_delay.tooltip'),
],
]
);
Expand Down
Loading