diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2025-01-06 16:42:03 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2025-01-06 16:42:03 +0000 |
commit | 63912b24a3cbb6bb63597d35c3cc40bc53a3150c (patch) | |
tree | c5fced96377bb4e5f981ede3749002df78de84da | |
parent | fe82b55550876835bbba36060cedc81e2ea1f93d (diff) | |
parent | bfbf97cee024343bf9dbbf2e11f08592c6a4c380 (diff) | |
download | mediawikicore-63912b24a3cbb6bb63597d35c3cc40bc53a3150c.tar.gz mediawikicore-63912b24a3cbb6bb63597d35c3cc40bc53a3150c.zip |
Merge "PoolCounter: holding-the-lock otel spans"
-rw-r--r-- | includes/ServiceWiring.php | 3 | ||||
-rw-r--r-- | includes/poolcounter/PoolCounter.php | 28 | ||||
-rw-r--r-- | includes/poolcounter/PoolCounterFactory.php | 7 |
3 files changed, 36 insertions, 2 deletions
diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index ae082345b897..22ae29d34fa9 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -1776,7 +1776,8 @@ return [ return new PoolCounterFactory( $mainConfig->get( MainConfigNames::PoolCounterConf ), $mainConfig->get( MainConfigNames::PoolCountClientConf ), - LoggerFactory::getInstance( 'poolcounter' ) + LoggerFactory::getInstance( 'poolcounter' ), + $services->getTracer() ); }, diff --git a/includes/poolcounter/PoolCounter.php b/includes/poolcounter/PoolCounter.php index 74046b53a8a7..3555819cf89c 100644 --- a/includes/poolcounter/PoolCounter.php +++ b/includes/poolcounter/PoolCounter.php @@ -24,6 +24,9 @@ use MediaWiki\Status\Status; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; +use Wikimedia\Telemetry\NoopTracer; +use Wikimedia\Telemetry\SpanInterface; +use Wikimedia\Telemetry\TracerInterface; /** * Semaphore semantics to restrict how many workers may concurrently perform a task. @@ -67,6 +70,7 @@ abstract class PoolCounter implements LoggerAwareInterface { /** @var string All workers with the same key share the lock */ protected $key; + protected string $type; /** @var int Maximum number of workers working on tasks with the same key simultaneously */ protected $workers; /** @@ -81,6 +85,8 @@ abstract class PoolCounter implements LoggerAwareInterface { /** @var int Maximum time in seconds to wait for the lock */ protected $timeout; protected LoggerInterface $logger; + protected TracerInterface $tracer; + protected ?SpanInterface $heldLockSpan = null; /** * @var bool Whether the key is a "might wait" key @@ -110,11 +116,13 @@ abstract class PoolCounter implements LoggerAwareInterface { } $this->fastStale = $conf['fastStale'] ?? false; $this->logger = new NullLogger(); + $this->tracer = new NoopTracer(); if ( $this->slots ) { $key = $this->hashKeyIntoSlots( $type, $key, $this->slots ); } + $this->type = $type; $this->key = $key; $this->isMightWaitKey = !preg_match( '/^nowait:/', $this->key ); } @@ -190,6 +198,13 @@ abstract class PoolCounter implements LoggerAwareInterface { */ final protected function onAcquire() { self::$acquiredMightWaitKey |= $this->isMightWaitKey; + $this->heldLockSpan = $this->tracer->createSpan( "PoolCounterLocked::{$this->type}" )->start(); + $this->heldLockSpan->activate(); + if ( $this->heldLockSpan->getContext()->isSampled() ) { + $this->heldLockSpan->setAttributes( [ + 'org.wikimedia.poolcounter.key' => $this->key, + ] ); + } } /** @@ -198,6 +213,10 @@ abstract class PoolCounter implements LoggerAwareInterface { */ final protected function onRelease() { self::$acquiredMightWaitKey &= !$this->isMightWaitKey; + if ( $this->heldLockSpan ) { + $this->heldLockSpan->end(); + $this->heldLockSpan = null; + } } /** @@ -236,6 +255,15 @@ abstract class PoolCounter implements LoggerAwareInterface { } /** + * @since 1.45 + * @param TracerInterface $tracer + * @return void + */ + public function setTracer( TracerInterface $tracer ) { + $this->tracer = $tracer; + } + + /** * @internal For use in PoolCounterWork only * @return LoggerInterface */ diff --git a/includes/poolcounter/PoolCounterFactory.php b/includes/poolcounter/PoolCounterFactory.php index 9031cdc41312..80a1f3916b40 100644 --- a/includes/poolcounter/PoolCounterFactory.php +++ b/includes/poolcounter/PoolCounterFactory.php @@ -2,6 +2,7 @@ namespace MediaWiki\PoolCounter; use Psr\Log\LoggerInterface; +use Wikimedia\Telemetry\TracerInterface; /** * @since 1.40 @@ -11,6 +12,7 @@ class PoolCounterFactory { private ?array $typeConfigs; private array $clientConf; private LoggerInterface $logger; + private TracerInterface $tracer; /** * @internal For use by ServiceWiring @@ -18,10 +20,12 @@ class PoolCounterFactory { * @param array $clientConf See $wgPoolCountClientConf * @param LoggerInterface $logger */ - public function __construct( ?array $typeConfigs, array $clientConf, LoggerInterface $logger ) { + public function __construct( ?array $typeConfigs, array $clientConf, + LoggerInterface $logger, TracerInterface $tracer ) { $this->typeConfigs = $typeConfigs; $this->clientConf = $clientConf; $this->logger = $logger; + $this->tracer = $tracer; } private function getClientManager(): PoolCounterConnectionManager { @@ -52,6 +56,7 @@ class PoolCounterFactory { /** @var PoolCounter $poolCounter */ $poolCounter = new $class( $conf, $type, $key ); $poolCounter->setLogger( $this->logger ); + $poolCounter->setTracer( $this->tracer ); // Support subclass for back-compat with the extension if ( $poolCounter instanceof PoolCounterClient ) { |