-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from matomo-org/notifyemail
Send email notification when queue reaches a certain size
- Loading branch information
Showing
8 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* Piwik - free/libre analytics platform | ||
* | ||
* @link http://piwik.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
* | ||
*/ | ||
namespace Piwik\Plugins\QueuedTracking; | ||
|
||
use Piwik\Config; | ||
|
||
class Configuration | ||
{ | ||
public static $DEFAULT_NOTIFY_EMAILS = []; | ||
const DEFAULT_NOTIFY_THRESHOLD = 250000; | ||
const KEY_NOTIFY_EMAILS = 'notify_queue_threshold_emails'; | ||
const KEY_NOTIFY_THRESHOLD = 'notify_queue_threshold_single_queue'; | ||
|
||
public function install() | ||
{ | ||
$config = $this->getConfig(); | ||
|
||
if (empty($config->QueuedTracking)) { | ||
$config->QueuedTracking = array(); | ||
} | ||
$reports = $config->QueuedTracking; | ||
|
||
// we make sure to set a value only if none has been configured yet, eg in common config. | ||
if (empty($reports[self::KEY_NOTIFY_THRESHOLD])) { | ||
$reports[self::KEY_NOTIFY_THRESHOLD] = self::DEFAULT_NOTIFY_THRESHOLD; | ||
} | ||
if (empty($reports[self::KEY_NOTIFY_EMAILS])) { | ||
$reports[self::KEY_NOTIFY_EMAILS] = self::$DEFAULT_NOTIFY_EMAILS; | ||
} | ||
$config->QueuedTracking = $reports; | ||
|
||
$config->forceSave(); | ||
} | ||
|
||
public function uninstall() | ||
{ | ||
$config = $this->getConfig(); | ||
$config->QueuedTracking = array(); | ||
$config->forceSave(); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getNotifyThreshold() | ||
{ | ||
$value = $this->getConfigValue(self::KEY_NOTIFY_THRESHOLD, self::DEFAULT_NOTIFY_THRESHOLD); | ||
|
||
if ($value === false || $value === '' || $value === null) { | ||
$value = self::DEFAULT_NOTIFY_THRESHOLD; | ||
} | ||
|
||
return (int) $value; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getNotifyEmails() | ||
{ | ||
$value = $this->getConfigValue(self::KEY_NOTIFY_EMAILS, self::$DEFAULT_NOTIFY_EMAILS); | ||
|
||
if (empty($value)) { | ||
$value = self::$DEFAULT_NOTIFY_EMAILS; | ||
} | ||
if (!is_array($value)) { | ||
$value = array($value); | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
private function getConfig() | ||
{ | ||
return Config::getInstance(); | ||
} | ||
|
||
private function getConfigValue($name, $default) | ||
{ | ||
$config = $this->getConfig(); | ||
$attribution = $config->QueuedTracking; | ||
if (isset($attribution[$name])) { | ||
return $attribution[$name]; | ||
} | ||
return $default; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,17 @@ __Can I configure multiple Sentinel servers?__ | |
|
||
Yes, once Sentinel is enabled you can configure multiple servers by specifying multiple hosts and ports comma separated via the UI. | ||
|
||
__Can I be notified when a queue reaches a certain threshold?__ | ||
|
||
Yes, you can optionally receive an email when the number of requests queued in a single queue reaches a configured | ||
threshold. You can configure this in your `config/config.ini.php` config file using the following configuration: | ||
|
||
``` | ||
[QueuedTracking] | ||
notify_queue_threshold_emails[] = [email protected] | ||
notify_queue_threshold_single_queue = 250000 | ||
``` | ||
|
||
__Are there any known issues?__ | ||
|
||
* In case you are using bulk tracking the bulk tracking response varies compared to the regular one. We will always return | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
/** | ||
* Piwik - free/libre analytics platform | ||
* | ||
* @link http://piwik.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
* | ||
*/ | ||
namespace Piwik\Plugins\QueuedTracking\tests\Unit; | ||
|
||
use Piwik\Config; | ||
use Piwik\Plugins\QueuedTracking\Configuration; | ||
|
||
/** | ||
* @group QueuedTracking | ||
* @group Plugins | ||
*/ | ||
class ConfigurationTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Configuration | ||
*/ | ||
private $configuration; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->configuration = new Configuration(); | ||
} | ||
|
||
public function test_shouldInstallConfig() | ||
{ | ||
$this->configuration->install(); | ||
|
||
$QueuedTracking = Config::getInstance()->QueuedTracking; | ||
$this->assertEquals(array( | ||
'notify_queue_threshold_single_queue' => Configuration::DEFAULT_NOTIFY_THRESHOLD, | ||
'notify_queue_threshold_emails' => Configuration::$DEFAULT_NOTIFY_EMAILS | ||
), $QueuedTracking); | ||
} | ||
|
||
public function test_getNotifyThreshold_shouldReturnDefaultThreshold() | ||
{ | ||
$this->assertEquals(250000, $this->configuration->getNotifyThreshold()); | ||
} | ||
|
||
public function test_getNotifyThreshold_shouldBePossibleToChangeValue() | ||
{ | ||
Config::getInstance()->QueuedTracking = array( | ||
Configuration::KEY_NOTIFY_THRESHOLD => 150 | ||
); | ||
$this->assertEquals(150, $this->configuration->getNotifyThreshold()); | ||
} | ||
|
||
public function test_getNotifyThreshold_noConfig_shouldReturnDefault() | ||
{ | ||
Config::getInstance()->QueuedTracking = array(); | ||
$this->assertEquals(Configuration::DEFAULT_NOTIFY_THRESHOLD, $this->configuration->getNotifyThreshold()); | ||
} | ||
|
||
|
||
public function test_getNotifyEmails_shouldReturnDefaultThreshold() | ||
{ | ||
$this->assertEquals(array(), $this->configuration->getNotifyEmails()); | ||
} | ||
|
||
public function test_getNotifyEmails_shouldBePossibleToChangeValue() | ||
{ | ||
Config::getInstance()->QueuedTracking = array( | ||
Configuration::KEY_NOTIFY_EMAILS => ['[email protected]'] | ||
); | ||
$this->assertEquals(['[email protected]'], $this->configuration->getNotifyEmails()); | ||
} | ||
|
||
public function test_getNotifyEmails_noConfig_shouldReturnDefault() | ||
{ | ||
Config::getInstance()->QueuedTracking = array(); | ||
$this->assertEquals(Configuration::$DEFAULT_NOTIFY_EMAILS, $this->configuration->getNotifyEmails()); | ||
} | ||
|
||
|
||
} |