diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d5da0c..f5f66a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +5.1.3 - 2025-09-01 +- Add support for Sentinel password + 5.1.2 - 2025-07-07 - Textual changes diff --git a/Queue/Backend/Sentinel.php b/Queue/Backend/Sentinel.php index 271feec..fc73d8a 100644 --- a/Queue/Backend/Sentinel.php +++ b/Queue/Backend/Sentinel.php @@ -22,6 +22,11 @@ class Sentinel extends Redis { private $masterName = ''; + /* + * @var bool + */ + private $usePasswordForSentinelInstances = false; + protected function connect() { $hosts = explode(',', $this->host); @@ -36,6 +41,9 @@ protected function connect() $configuredClient = new \Credis_Client($host, $ports[$index], $timeout = 0.5, $persistent = false); $configuredClient->forceStandalone(); $configuredClient->connect(); + if ($this->usePasswordForSentinelInstances && !empty($this->password)) { + $configuredClient->auth($this->password); + } $configuredSentinel = new \Credis_Sentinel($configuredClient); $master = $configuredSentinel->getMasterAddressByName($this->masterName); @@ -64,6 +72,11 @@ public function setSentinelMasterName($name) $this->masterName = $name; } + public function setUsePasswordForSentinelInstances(bool $usePasswordForSentinelInstances) + { + $this->usePasswordForSentinelInstances = $usePasswordForSentinelInstances; + } + protected function evalScript($script, $keys, $args) { return $this->redis->eval($script, $keys, $args); diff --git a/Queue/Factory.php b/Queue/Factory.php index 887801f..e2d4c28 100644 --- a/Queue/Factory.php +++ b/Queue/Factory.php @@ -72,6 +72,9 @@ public static function makeBackendFromSettings(SystemSettings $settings) $redis = new Queue\Backend\Sentinel(); $redis->setSentinelMasterName($masterName); $redis->setDatabase($database); + if (!empty($settings->getUsePasswordForSentinelInstances())) { + $redis->setUsePasswordForSentinelInstances(true); + } } } elseif ($settings->isUsingClusterBackend()) { $redis = new Queue\Backend\RedisCluster(); diff --git a/SystemSettings.php b/SystemSettings.php index fd90759..d8722b4 100644 --- a/SystemSettings.php +++ b/SystemSettings.php @@ -60,6 +60,9 @@ class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings /** @var Setting */ public $sentinelMasterName; + /** @var Setting */ + public $usePasswordForSentinelInstances; + public function getAvailableRedisBackendTypes() { return array( @@ -83,6 +86,7 @@ protected function init() $this->backend = $this->createBackendSetting(); $this->useWhatRedisBackendType = $this->createUseWhatRedisBackendType(); $this->sentinelMasterName = $this->createSetSentinelMasterName(); + $this->usePasswordForSentinelInstances = $this->createUsePasswordForSentinelInstances(); $this->redisHost = $this->createRedisHostSetting(); $this->redisPort = $this->createRedisPortSetting(); $this->redisTimeout = $this->createRedisTimeoutSetting(); @@ -114,6 +118,11 @@ public function getSentinelMasterName() return $this->sentinelMasterName->getValue(); } + public function getUsePasswordForSentinelInstances() + { + return $this->usePasswordForSentinelInstances->getValue(); + } + public function isUsingUnixSocket() { return substr($this->redisHost->getValue(), 0, 1) === '/'; @@ -373,6 +382,16 @@ private function createSetSentinelMasterName() }); } + private function createUsePasswordForSentinelInstances() + { + return $this->makeSetting('usePasswordForSentinelInstances', $default = false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) { + $field->title = Piwik::translate('QueuedTracking_UsePasswordForSentinelsTitle'); + $field->condition = 'backend=="redis"'; + $field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX; + $field->inlineHelp = Piwik::translate('QueuedTracking_UsePasswordForSentinelsHelp', ['

']) . '
'; + }); + } + public function checkMatchHostsAndPorts() { $hosts = $this->redisHost->getValue(); diff --git a/lang/en.json b/lang/en.json index 2e2f6fe..1b2f7df 100644 --- a/lang/en.json +++ b/lang/en.json @@ -33,6 +33,8 @@ "MasterNameFieldTitle": "Redis Sentinel Master name", "MasterNameFieldHelp": "The sentinel master name only needs to be configured if Sentinel is enabled.", "NumHostsNotMatchNumPorts": "The number of configured hosts doesn't match the number of configured ports.", - "MultipleServersOnlyConfigurableIfSentinelEnabled": "Multiple hosts or ports can be only configured when Redis Sentinel is on. The plugin README will tell you how to do so." + "MultipleServersOnlyConfigurableIfSentinelEnabled": "Multiple hosts or ports can be only configured when Redis Sentinel is on. The plugin README will tell you how to do so.", + "UsePasswordForSentinelsTitle": "Use password with Redis Sentinels", + "UsePasswordForSentinelsHelp": "Only relevant if Sentinel is enabled.%1$sIf enabled, the Redis password will also be used when authenticating with Sentinel instances to obtain the master connection information. Otherwise, the password is only used to authenticate with the Redis master." } } diff --git a/plugin.json b/plugin.json index 569f699..1875b6b 100644 --- a/plugin.json +++ b/plugin.json @@ -1,6 +1,6 @@ { "name": "QueuedTracking", - "version": "5.1.2", + "version": "5.1.3", "description": "Scale your large traffic Matomo service by queuing tracking requests in Redis or MySQL for better performance and reliability when experiencing peaks.", "theme": false, "keywords": ["tracker", "tracking", "queue", "redis"], diff --git a/tests/UI/expected-ui-screenshots/QueuedTrackingSettings_settings_page.png b/tests/UI/expected-ui-screenshots/QueuedTrackingSettings_settings_page.png index efcd3df..1cf2af0 100644 Binary files a/tests/UI/expected-ui-screenshots/QueuedTrackingSettings_settings_page.png and b/tests/UI/expected-ui-screenshots/QueuedTrackingSettings_settings_page.png differ diff --git a/tests/UI/expected-ui-screenshots/QueuedTrackingSettings_settings_page_sentinel.png b/tests/UI/expected-ui-screenshots/QueuedTrackingSettings_settings_page_sentinel.png index ed487d4..b275782 100644 Binary files a/tests/UI/expected-ui-screenshots/QueuedTrackingSettings_settings_page_sentinel.png and b/tests/UI/expected-ui-screenshots/QueuedTrackingSettings_settings_page_sentinel.png differ diff --git a/tests/UI/expected-ui-screenshots/QueuedTrackingSettings_settings_save_error.png b/tests/UI/expected-ui-screenshots/QueuedTrackingSettings_settings_save_error.png index ce97a85..779188a 100644 Binary files a/tests/UI/expected-ui-screenshots/QueuedTrackingSettings_settings_save_error.png and b/tests/UI/expected-ui-screenshots/QueuedTrackingSettings_settings_save_error.png differ