Added retry path coverage

This commit is contained in:
vladvildanov
2026-11-25 12:23:44 +02:00
parent ee955ff682
commit 754da8df19
2 changed files with 35 additions and 1 deletions
+10 -1
View File
@@ -29,11 +29,14 @@ use OpenTelemetry\SDK\Metrics\MeterProvider;
use OpenTelemetry\SDK\Metrics\MetricReader\ExportingReader;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use Predis\Client;
use Predis\Connection\Parameters;
use Predis\Observability\MetricGroup;
use Predis\Observability\MetricsConfig;
use Predis\Observability\ObservabilityInstance;
use Predis\Observability\OTelConfig;
use Predis\Response\ServerException;
use Predis\Retry\Retry;
use Predis\Retry\Strategy\ExponentialBackoff;
require __DIR__ . '/../vendor/autoload.php';
@@ -56,7 +59,8 @@ ObservabilityInstance::getInstance()->init(new OTelConfig(
$provider
));
$client = new Client($redis);
$client = new Client(Parameters::parse($redis) + ['retry' => new Retry(new ExponentialBackoff(1000, 10000), 3)]);
$admin = new Client($redis);
echo "Exporting to $collector for $seconds seconds as service 'predis-example'", PHP_EOL;
@@ -82,6 +86,11 @@ do {
$transaction->incr('otel:counter');
});
// Closes the connection server-side: the next command fails once, then succeeds on retry
// and is recorded with redis.client.operation.retry_attempts = 1.
$admin->executeRaw(['CLIENT', 'KILL', 'ID', $client->executeRaw(['CLIENT', 'ID'])]);
$client->get('otel:string');
$client->del('otel:string', 'otel:counter');
// PHP has no background exporter: nothing leaves the process until the provider is flushed.
@@ -19,6 +19,8 @@ use OpenTelemetry\SDK\Metrics\MeterProvider;
use OpenTelemetry\SDK\Metrics\MetricReader\ExportingReader;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use Predis\Response\ServerException;
use Predis\Retry\Retry;
use Predis\Retry\Strategy\NoBackoff;
use PredisTestCase;
/**
@@ -110,6 +112,29 @@ class OTelIntegrationTest extends PredisTestCase
$this->assertSeries($series, $name . '_bucket', ['db_operation_name' => 'SET', 'le' => '2.5']);
}
/**
* @group connected
* @group relay-incompatible
*/
public function testExportsRetryAttemptsThroughCollector(): void
{
$client = $this->createClient(['retry' => new Retry(new NoBackoff(), 3)]);
// Closes the connection server-side: the next command fails once, then succeeds on retry.
$this->createClient()->executeRaw(['CLIENT', 'KILL', 'ID', $client->executeRaw(['CLIENT', 'ID'])]);
$this->initObservability([MetricGroup::COMMAND]);
$this->assertNull($client->get('otel:missing'));
$this->assertTrue(ObservabilityInstance::getInstance()->forceFlush());
$name = 'db_client_operation_duration_seconds_count';
$series = $this->scrape($name, 1);
$this->assertSeries($series, $name, ['db_operation_name' => 'GET', 'redis_client_operation_retry_attempts' => '1']);
$this->assertStringNotContainsString('error_type', $series[0]);
}
/**
* Enables the given metric groups with a provider exporting to the collector.
*/