Skip to content

Defer pool duration telemetry instruments#31

Merged
lohanidamodar merged 1 commit into
mainfrom
lazy-pool-telemetry
Jun 3, 2026
Merged

Defer pool duration telemetry instruments#31
lohanidamodar merged 1 commit into
mainfrom
lazy-pool-telemetry

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Summary

  • Upgrade utopia-php/telemetry to ^0.4 so pools can use lazy instrument factories.
  • Defer registration of pool wait/use duration histograms until their first record.
  • Keep steady-state pool gauges eager and add tests that lock in eager gauge vs lazy histogram behavior.

Testing

  • composer check
  • composer lint
  • ./vendor/bin/phpunit --configuration phpunit.xml --filter 'testPoolTelemetry|testPoolUseDurationTelemetryIsCreatedOnFirstUse'
  • composer audit

Notes

  • Full composer test exits with code 139 in the existing Utopia\Tests\Adapter\SwooleTest::testSwooleCoroutineStressTest after the new telemetry tests pass in both Stack and Swoole runs.

@greptile-apps

greptile-apps Bot commented Jun 3, 2026

Copy link
Copy Markdown

Greptile Summary

This PR defers registration of the pool.connection.wait_time and pool.connection.use_time histogram instruments until their first record() call by switching from $telemetry->createHistogram() to Histogram::lazy(), while keeping the four pool-state gauges eager. The utopia-php/telemetry dependency is also pinned to ^0.4 to match the new API.

  • Lazy histograms: both duration histograms are now created on the first pop() / use() call respectively, avoiding unnecessary instrument registration in pools that are configured but never exercised.
  • Eager gauges unchanged: open, active, idle, and capacity gauges continue to register at setTelemetry() time.
  • New tests: testPoolTelemetry gains assertions locking in the eager-gauge / lazy-histogram split; testPoolUseDurationTelemetryIsCreatedOnFirstUse verifies use_time appears only after the first use() call.

Confidence Score: 5/5

Safe to merge — the change is narrow, well-tested, and the lazy-init path is exercised by both the stack and Swoole test runs.

The logic change is confined to two Histogram::lazy() calls in setTelemetry(); all downstream record() call sites are untouched. The new tests verify the exact eager-vs-lazy boundary that this PR introduces, and the gauge behavior is unchanged. No correctness issues were found.

No files require special attention.

Important Files Changed

Filename Overview
src/Pools/Pool.php Replaces eager createHistogram() calls for wait_time and use_time with Histogram::lazy() so both instruments are only registered in the backend on first record() call; gauge creation remains eager as before.
tests/Pools/Scopes/PoolTestScope.php Adds assertions to testPoolTelemetry verifying gauges are created immediately while histograms are absent until first use; adds testPoolUseDurationTelemetryIsCreatedOnFirstUse covering the happy-path lazy init of use_time.
composer.json Pins utopia-php/telemetry to ^0.4 (was "*"), tightening the version constraint to match the new Histogram::lazy() API.
composer.lock Routine dependency bumps across open-telemetry/, symfony/, phpunit/* packages, and utopia-php/telemetry 0.2.0 → 0.4.0.

Reviews (1): Last reviewed commit: "Defer pool duration telemetry instrument..." | Re-trigger Greptile

@lohanidamodar lohanidamodar merged commit 19d8b82 into main Jun 3, 2026
4 checks passed
@ChiragAgg5k ChiragAgg5k deleted the lazy-pool-telemetry branch June 3, 2026 05:21
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