Skip to content

Commit

Permalink
Merge pull request #241 from matomo-org/PG-3545-some-minor-improvements
Browse files Browse the repository at this point in the history
Improvements around TLS host connection and translations
  • Loading branch information
snake14 authored Jun 14, 2024
2 parents 0591733 + 2037215 commit 2b8cb1b
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 122 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

5.0.5
- Improved plugin reliability
- Added system settings to list of text that can be translated

5.0.4
- Added plugin category for Marketplace

Expand Down
4 changes: 2 additions & 2 deletions Commands/Monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ protected function doExecute(): int
$message = sprintf('%s (%s) request sets left in queue. %s used memory (%s peak). %d workers active. ',
array_sum($numInQueue),
implode('+', $numInQueue),
$memory['used_memory_human'],
$memory['used_memory_peak_human'],
$memory['used_memory_human'] ?? 'Unknown',
$memory['used_memory_peak_human'] ?? 'unknown',
$lock->getNumberOfAcquiredLocks());
$output->write("\x0D");
$output->write($message);
Expand Down
2 changes: 1 addition & 1 deletion Queue/Backend/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function getKeysMatchingPattern($pattern)
{
$this->connectIfNeeded();

return $this->redis->keys($pattern);
return $this->redis->keys($pattern) ?: [];
}

public function expireIfKeyHasValue($key, $value, $ttlInSeconds)
Expand Down
153 changes: 55 additions & 98 deletions SystemSettings.php

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
{
"QueuedTracking": {
"ExceptionValueIsNotInt": "The value is not an integer",
"RedisHostFieldTitle": "Redis host or unix socket",
"RedisHostFieldHelp": "Remote host or unix socket of the Redis server. Max 500 characters are allowed.",
"RedisHostFieldHelpExtended": "If your host requires a TLS connection, you can prepend the TLS protocol to your host like: tls://example-host.com. If that does not work, make sure that certificates are configured correctly on your Matomo server.",
"RedisHostFieldHelpExtendedSentinel": "As you are using Redis Sentinel, you can use a comma separated list. Make sure to specify as many hosts as you have specified ports. For example to configure two servers “127.0.0.1:26379” and “127.0.0.2:26879” specify “127.0.0.1,127.0.0.2” as host and “26379,26879” as ports.",
"RedisPortFieldTitle": "Redis port",
"RedisPortFieldHelp": "Port the Redis server is running on. Value should be between 1 and 65535. Use 0 if you are using unix socket to connect to Redis server.",
"RedisTimeoutFieldTitle": "Redis timeout",
"RedisTimeoutFieldHelp": "Redis connection timeout in seconds. “0.0” meaning unlimited. Can be a float eg “2.5” for a connection timeout of 2.5 seconds.",
"NumberOfQueueWorkersFieldTitle": "Number of queue workers",
"NumberOfQueueWorkersFieldHelp": "Number of allowed maximum queue workers. Accepts a number between 1 and 16. Best practice is to set the number of CPUs you want to make available for queue processing. Be aware you need to make sure to start the workers manually. We recommend to not use 9-15 workers, rather use 8 or 16 as the queue might not be distributed evenly into different queues.",
"RedisPasswordFieldTitle": "Redis password",
"RedisPasswordFieldHelp": "Password set on the Redis server, if any. Redis can be instructed to require a password before allowing clients to execute commands.",
"RedisDatabaseFieldTitle": "Redis database",
"RedisDatabaseFieldHelp": "In case you are using Redis for caching make sure to use a different database.",
"QueueEnabledFieldTitle": "Queue enabled",
"QueueEnabledFieldHelp": "If enabled, all tracking requests will be written into a queue instead of the directly into the database. Requires a Redis server and phpredis PHP extension if using Redis as a backend.",
"NumRequestsToProcessFieldTitle": "Number of requests that are processed in one batch",
"NumRequestsToProcessFieldHelp": "Defines how many requests will be picked out of the queue and processed at once. Enter a number which is >= 1.",
"ProcessDuringRequestFieldTitle": "Process during tracking request",
"ProcessDuringRequestFieldHelp": "If enabled, we will process all requests within a queue during a normal tracking request once there are enough requests in the queue. This will not slow down the tracking request. If disabled, you have to setup a cronjob that executes the %1$s./console queuedtracking:process%2$s console command eg every minute to process the queue.",
"BackendSettingFieldTitle": "Backend",
"BackendSettingFieldHelp": "Select the backend you want to use for this feature. If you do not have any experience with Redis or it is not available on your server, we recommend using Mysql.",
"UseSentinelFieldTitle": "Enable Redis Sentinel",
"UseSentinelFieldHelp": "If enabled, the Redis Sentinel feature will be used. Make sure to update host and port if needed. Once you have enabled and saved the change, you will be able to specify multiple hosts and ports comma separated.",
"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."
}
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "QueuedTracking",
"version": "5.0.4",
"version": "5.0.5",
"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"],
Expand Down
51 changes: 31 additions & 20 deletions tests/Integration/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Piwik\Plugins\QueuedTracking\SystemSettings;
use Piwik\Plugins\QueuedTracking\tests\Framework\TestCase\IntegrationTestCase;
use Piwik\Tests\Framework\Fixture;

/**
* @group QueuedTracking
Expand All @@ -28,6 +29,8 @@ public function setUp(): void
{
parent::setUp();

Fixture::loadAllTranslations();

$this->settings = new SystemSettings();
}

Expand All @@ -39,31 +42,31 @@ public function tearDown(): void
public function test_redisHost_ShouldFail_IfMoreThan300CharctersGiven()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Max 500 characters');
$this->expectExceptionMessage('should contain at most 500 characters');

$this->settings->redisHost->setValue(str_pad('3', 503, '4'));
}

public function test_redisPort_ShouldFail_IfPortIsTooLow()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Port has to be at least 1');
$this->expectExceptionMessage('The value needs to be at least 1');

$this->settings->redisPort->setValue(0);
}

public function test_redisPort_ShouldFail_IfPortIsTooHigh()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Port should be max 65535');
$this->expectExceptionMessage('The value should be at most 65535');

$this->settings->redisPort->setValue(65536);
}

public function test_redisTimeout_ShouldFail_IfTooLong()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Max 5 characters');
$this->expectExceptionMessage('should contain at most 5 characters');

$this->settings->redisTimeout->setIsWritableByCurrentUser(true);
$this->settings->redisTimeout->setValue('333.43');
Expand All @@ -72,7 +75,7 @@ public function test_redisTimeout_ShouldFail_IfTooLong()
public function test_redisTimeout_ShouldFail_IfNotNumeric()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('should be numeric');
$this->expectExceptionMessage('The value is not a number');

$this->settings->redisTimeout->setIsWritableByCurrentUser(true);
$this->settings->redisTimeout->setValue('33d3.43');
Expand All @@ -81,15 +84,15 @@ public function test_redisTimeout_ShouldFail_IfNotNumeric()
public function test_sentinelMasterName_ShouldFail_IfTooManyCharacters()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Max 200 characters are allowed');
$this->expectExceptionMessage('should contain at most 200 characters');

$this->settings->sentinelMasterName->setValue(str_pad('1', 201, '1'));
}

public function test_redisPassword_ShouldFail_IfMoreThan128CharctersGiven()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Max 128 characters');
$this->expectExceptionMessage('should contain at most 128 characters');

$this->settings->redisPassword->setValue(str_pad('4', 130, '4'));
}
Expand All @@ -114,63 +117,71 @@ public function test_queueEnabled_ShouldNotFail_IfEnabledButWrongConnectionDetai
public function test_numRequestsToProcess_ShouldFail_IfTooLow()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Number should be 1 or higher');
$this->expectExceptionMessage('The value needs to be at least 1');

$this->settings->numRequestsToProcess->setValue(0);
}

public function test_numRequestsToProcess_ShouldFail_IfNotNumeric()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Value should be a number');
$this->expectExceptionMessage('The value is not a number');

$this->settings->numRequestsToProcess->setValue('33d3.43');
}

public function test_redisDatabase_ShouldFail_IfIsNumericButFloat()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The database has to be an integer');
$this->expectExceptionMessage('The value is not an integer');

$this->settings->redisDatabase->setValue('5.34');
}

public function test_redisDatabase_ShouldFail_IfNotNumeric()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The database has to be an integer');
$this->expectExceptionMessage('The value is not a number');

$this->settings->redisDatabase->setValue('33d3.43');
}

public function test_redisDatabase_ShouldFail_IfTooLong()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Max 5 digits allowed');
$this->expectExceptionMessage('should contain at most 5 characters');

$this->settings->redisDatabase->setValue('333333');
}

public function test_numQueueWorkers_ShouldFail_IfNotNumeric()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('should be an integer');
$this->expectExceptionMessage('The value is not a number');

$this->settings->numQueueWorkers->setValue('1f');
}

public function test_numQueueWorkers_ShouldFail_IfIsNumericButFloat()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The value is not an integer');

$this->settings->numQueueWorkers->setValue('1.2');
}

public function test_numQueueWorkers_ShouldFail_IfTooHigh()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Only 1-16 workers allowed');
$this->expectExceptionMessage('The value should be at most 16');

$this->settings->numQueueWorkers->setValue('17');
}

public function test_numQueueWorkers_ShouldFail_IfTooLow()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Only 1-16 workers allowed');
$this->expectExceptionMessage('The value needs to be at least 1');

$this->settings->numQueueWorkers->setValue('0');
}
Expand Down Expand Up @@ -231,7 +242,7 @@ public function test_useSentinelBackend()
public function test_redisPort_ShouldFailWhenMultipleValuesGiven_IfSentinelNotEnabled()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('QueuedTracking_MultipleServersOnlyConfigurableIfSentinelEnabled');
$this->expectExceptionMessage('Multiple hosts or ports can be only configured when Redis Sentinel is on.');

$this->settings->redisPort->setValue('45,56,788');
}
Expand All @@ -246,7 +257,7 @@ public function test_redisPort_ShouldNotFailAndConvertToIntWhenMultipleValuesGiv
public function test_redisPort_ShouldValidateEachPortSeparately_WhenManySpecified()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('A port has to be a number');
$this->expectExceptionMessage('The value is not a number');

$this->enableRedisSentinel();
$this->settings->redisPort->setValue('55 , 44.34, 4mk ');
Expand All @@ -256,7 +267,7 @@ public function test_redisPort_ShouldValidateEachPortSeparately_WhenManySpecifie
public function test_redisHost_ShouldFailWhenMultipleValuesGiven_IfSentinelNotEnabled()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('QueuedTracking_MultipleServersOnlyConfigurableIfSentinelEnabled');
$this->expectExceptionMessage('Multiple hosts or ports can be only configured when Redis Sentinel is on.');

$this->settings->redisHost->setValue('10.0.0.1,127.0.0.1');
}
Expand Down Expand Up @@ -373,7 +384,7 @@ public function test_convertCommaSeparatedValueToArray($stringValue, $expectedAr
public function test_checkMultipleServersOnlyConfiguredWhenSentinelIsEnabled_shouldFailWhenMoreThanOneValue_IfSentinelNotEnabled($stringValue)
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('QueuedTracking_MultipleServersOnlyConfigurableIfSentinelEnabled');
$this->expectExceptionMessage('Multiple hosts or ports can be only configured when Redis Sentinel is on.');

$this->disableRedisSentinel();

Expand Down Expand Up @@ -402,7 +413,7 @@ public function getCommaSeparatedWithMultipleValues()
public function test_save_shouldFailIfPortAndHostMismatch()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('QueuedTracking_NumHostsNotMatchNumPorts');
$this->expectExceptionMessage('The number of configured hosts doesn\'t match the number of configured ports.');

$this->enableRedisSentinel();
$this->settings->redisPort->setValue('6379,6480,4393');
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2b8cb1b

Please sign in to comment.