mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Stop propagating telemetry through sharding
This commit is contained in:
3 files changed
+3
-41
No files matched your search
@@ -3,10 +3,8 @@
|
||||
namespace Utopia\Cache\Adapter;
|
||||
|
||||
use Utopia\Cache\Adapter;
|
||||
use Utopia\Cache\TelemetryAware;
|
||||
use Utopia\Telemetry\Adapter as Telemetry;
|
||||
|
||||
class Sharding implements Adapter, TelemetryAware
|
||||
class Sharding implements Adapter
|
||||
{
|
||||
/**
|
||||
* @var Adapter[]
|
||||
@@ -72,15 +70,6 @@ class Sharding implements Adapter, TelemetryAware
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTelemetry(Telemetry $telemetry): void
|
||||
{
|
||||
foreach ($this->adapters as $adapter) {
|
||||
if ($adapter instanceof TelemetryAware) {
|
||||
$adapter->setTelemetry($telemetry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param int $ttl time in seconds
|
||||
|
||||
@@ -84,7 +84,7 @@ class CircuitBreakerTest extends TestCase
|
||||
$this->assertSame($telemetry, $adapter->telemetry);
|
||||
}
|
||||
|
||||
public function test_cache_telemetry_propagates_to_circuit_breaker_adapters(): void
|
||||
public function test_cache_telemetry_does_not_propagate_through_sharding(): void
|
||||
{
|
||||
$telemetry = new TestTelemetry();
|
||||
$cache = new Cache(new Sharding([
|
||||
@@ -94,11 +94,9 @@ class CircuitBreakerTest extends TestCase
|
||||
$cache->setTelemetry($telemetry);
|
||||
|
||||
$this->assertSame('value', $cache->save('key', 'value'));
|
||||
/** @var object{values: list<int|float>} $calls */
|
||||
$calls = $telemetry->counters['breaker.calls'];
|
||||
/** @var object{values: list<int|float>} $operationDuration */
|
||||
$operationDuration = $telemetry->histograms['cache.operation.duration'];
|
||||
$this->assertSame([1], $calls->values);
|
||||
$this->assertArrayNotHasKey('breaker.calls', $telemetry->counters);
|
||||
$this->assertCount(1, $operationDuration->values);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Utopia\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Utopia\Cache\Adapter\Memory;
|
||||
use Utopia\Cache\Adapter\Sharding;
|
||||
use Utopia\Cache\Cache;
|
||||
use Utopia\Cache\TelemetryAware;
|
||||
use Utopia\Telemetry\Adapter as Telemetry;
|
||||
@@ -35,28 +34,4 @@ class TelemetryTest extends TestCase
|
||||
$this->assertSame($telemetry, $adapter->telemetry);
|
||||
$this->assertEquals(2, $adapter->calls);
|
||||
}
|
||||
|
||||
public function test_sharding_propagates_telemetry_to_adapters(): void
|
||||
{
|
||||
$adapter = new class extends Memory implements TelemetryAware
|
||||
{
|
||||
public ?Telemetry $telemetry = null;
|
||||
|
||||
public int $calls = 0;
|
||||
|
||||
public function setTelemetry(Telemetry $telemetry): void
|
||||
{
|
||||
$this->telemetry = $telemetry;
|
||||
$this->calls++;
|
||||
}
|
||||
};
|
||||
$plainAdapter = new Memory;
|
||||
$telemetry = new None;
|
||||
|
||||
$sharding = new Sharding([$adapter, $plainAdapter]);
|
||||
$sharding->setTelemetry($telemetry);
|
||||
|
||||
$this->assertSame($telemetry, $adapter->telemetry);
|
||||
$this->assertEquals(1, $adapter->calls);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user