Skip to content

Add circuit breaker cache adapter#69

Merged
ChiragAgg5k merged 10 commits into
masterfrom
feat/telemetry-aware-adapters
May 12, 2026
Merged

Add circuit breaker cache adapter#69
ChiragAgg5k merged 10 commits into
masterfrom
feat/telemetry-aware-adapters

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented May 11, 2026

Copy link
Copy Markdown
Member

What

Adds first-class circuit breaker support for cache adapters:

  • Adds Utopia\Cache\Adapter\CircuitBreaker, backed by utopia-php/circuit-breaker.
  • Adds a TelemetryAware adapter contract.
  • Propagates telemetry from Cache::setTelemetry() to adapters that implement TelemetryAware.
  • Makes Sharding telemetry-aware and forwards telemetry to telemetry-aware children.
  • Makes CircuitBreaker telemetry-aware and forwards telemetry to both the breaker and any telemetry-aware inner adapter.
  • Moves utopia-php/circuit-breaker to runtime require because the new source adapter depends on it.
  • Updates the supported PHP floor to >=8.2, matching the circuit breaker package.

Why

Cloud currently needs a circuit breaker cache wrapper and telemetry must be attached after cache construction. Putting the wrapper and telemetry propagation contract in utopia-php/cache avoids duplicating this logic in application repositories and keeps propagation typed instead of relying on method_exists.

Testing

  • ./vendor/bin/phpunit tests/Cache/CircuitBreakerTest.php
  • ./vendor/bin/phpunit tests/Cache/TelemetryTest.php
  • php -d memory_limit=512M ./vendor/bin/phpstan analyse --level max src tests
  • composer lint

Note: plain composer check hit the local default 128 MB PHP memory limit, so PHPStan was rerun directly with memory_limit=512M.

@greptile-apps

greptile-apps Bot commented May 11, 2026

Copy link
Copy Markdown

Greptile Summary

This PR introduces a CircuitBreaker cache adapter that wraps any Adapter + UtopiaCircuitBreaker pair, routes all cache operations through the breaker with typed fallbacks, and adds a Feature\Telemetry interface so telemetry can be forwarded to adapters that opt in. Issues flagged in earlier review rounds (dependency in require, exact version pin, telemetry not reaching the inner adapter) have all been addressed in this revision.

  • src/Cache/Adapter/CircuitBreaker.php — new production adapter; delegates all Adapter methods through the breaker and correctly propagates telemetry to both the breaker and any TelemetryAware inner adapter.
  • src/Cache/Cache.phpsetTelemetry() now also forwards to the adapter when it implements Feature\Telemetry; this fires once on construction (via NoTelemetry) and again on explicit caller assignment.
  • composer.jsonutopia-php/circuit-breaker promoted to require with a 0.3.* range; PHP floor raised to >=8.2 to match the package's requirement.

Confidence Score: 5/5

Safe to merge; the adapter is well-tested, dependency placement and version constraints are correct, and telemetry propagation works as documented.

All changes are additive and isolated to the new CircuitBreaker adapter and the telemetry hook in Cache::setTelemetry. The dependency is correctly placed in require, the version constraint allows patch updates, and the test suite covers healthy pass-through, fallback on failure, breaker short-circuiting, and telemetry propagation to both the breaker and inner adapters.

No files require special attention.

Important Files Changed

Filename Overview
src/Cache/Adapter/CircuitBreaker.php New adapter wrapping any Adapter + UtopiaCircuitBreaker; telemetry correctly propagated to both breaker and inner adapter; delegate() visibility should be protected.
src/Cache/Cache.php Adds Feature\Telemetry propagation in setTelemetry(), which is also called from the constructor — double-call on construction is tested and documented.
src/Cache/Feature/Telemetry.php New interface for the TelemetryAware contract; minimal and correct.
composer.json Moves utopia-php/circuit-breaker to require, upgrades PHP floor to >=8.2, and uses the 0.3.* constraint — previously raised issues resolved.
tests/Cache/CircuitBreakerTest.php Covers healthy pass-through, fallbacks on failure, breaker short-circuit, telemetry attachment, telemetry inner-adapter propagation, and the non-propagation through Sharding.
tests/Cache/TelemetryTest.php Verifies Cache propagates telemetry to a TelemetryAware adapter and that two calls occur (constructor + explicit set).
.github/workflows/test.yml Drops PHP 8.1, adds PHP 8.4, and fixes the missing trailing newline.
Dockerfile.php-8.4 Renames from Dockerfile.php-8.1, upgrades base image to php-8.4-1.0.0, and explicitly loads the Redis extension.

Reviews (11): Last reviewed commit: "Use camel case telemetry test name" | Re-trigger Greptile

Comment thread src/Cache/Adapter/Sharding.php Outdated
@ChiragAgg5k ChiragAgg5k force-pushed the feat/telemetry-aware-adapters branch 2 times, most recently from e2f99b4 to 87f8790 Compare May 12, 2026 02:55
Comment thread composer.json Outdated
Comment thread src/Cache/Adapter/CircuitBreaker.php
@ChiragAgg5k ChiragAgg5k force-pushed the feat/telemetry-aware-adapters branch from 87f8790 to b0cc209 Compare May 12, 2026 03:04
@ChiragAgg5k ChiragAgg5k changed the title Add telemetry-aware cache adapters Add circuit breaker cache adapter May 12, 2026
Comment thread composer.json Outdated
Comment thread .github/workflows/test.yml Outdated
Comment thread src/Cache/Adapter/CircuitBreaker.php Outdated
Comment thread src/Cache/Adapter/Sharding.php Outdated
Comment thread src/Cache/TelemetryAware.php Outdated
Comment thread tests/Cache/CircuitBreakerTest.php Outdated
@ChiragAgg5k ChiragAgg5k merged commit ef1d122 into master May 12, 2026
6 checks passed
@ChiragAgg5k ChiragAgg5k deleted the feat/telemetry-aware-adapters branch May 12, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants