From bcf563ef38b59b8d2e1e614887986543229c8624 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 5 Mar 2019 11:31:55 -0800 Subject: [PATCH] objectcache: add metrics for WAN cache deletes and check key touches/resets Change-Id: I3dc707af53e480b27b7349aca53292f3bb26c45a --- includes/libs/objectcache/WANObjectCache.php | 30 ++++++++++++------- .../libs/objectcache/WANObjectCacheTest.php | 4 +-- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/includes/libs/objectcache/WANObjectCache.php b/includes/libs/objectcache/WANObjectCache.php index bed7965149..9598b3ddfe 100644 --- a/includes/libs/objectcache/WANObjectCache.php +++ b/includes/libs/objectcache/WANObjectCache.php @@ -696,16 +696,17 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface { * @return bool True if the item was purged or not found, false on failure */ final public function delete( $key, $ttl = self::HOLDOFF_TTL ) { - $key = self::VALUE_KEY_PREFIX . $key; - if ( $ttl <= 0 ) { // Publish the purge to all datacenters - $ok = $this->relayDelete( $key ); + $ok = $this->relayDelete( self::VALUE_KEY_PREFIX . $key ); } else { // Publish the purge to all datacenters - $ok = $this->relayPurge( $key, $ttl, self::HOLDOFF_NONE ); + $ok = $this->relayPurge( self::VALUE_KEY_PREFIX . $key, $ttl, self::HOLDOFF_NONE ); } + $kClass = $this->determineKeyClassForStats( $key ); + $this->stats->increment( "wanobjectcache.$kClass.delete." . ( $ok ? 'ok' : 'error' ) ); + return $ok; } @@ -860,7 +861,12 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface { */ final public function touchCheckKey( $key, $holdoff = self::HOLDOFF_TTL ) { // Publish the purge to all datacenters - return $this->relayPurge( self::TIME_KEY_PREFIX . $key, self::CHECK_KEY_TTL, $holdoff ); + $ok = $this->relayPurge( self::TIME_KEY_PREFIX . $key, self::CHECK_KEY_TTL, $holdoff ); + + $kClass = $this->determineKeyClassForStats( $key ); + $this->stats->increment( "wanobjectcache.$kClass.ck_touch." . ( $ok ? 'ok' : 'error' ) ); + + return $ok; } /** @@ -892,7 +898,12 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface { */ final public function resetCheckKey( $key ) { // Publish the purge to all datacenters - return $this->relayDelete( self::TIME_KEY_PREFIX . $key ); + $ok = $this->relayDelete( self::TIME_KEY_PREFIX . $key ); + + $kClass = $this->determineKeyClassForStats( $key ); + $this->stats->increment( "wanobjectcache.$kClass.ck_reset." . ( $ok ? 'ok' : 'error' ) ); + + return $ok; } /** @@ -1288,8 +1299,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface { $touchedCb = $opts['touchedCallback'] ?? null; $initialTime = $this->getCurrentTime(); - // Get a collection name to describe this class of key - $kClass = $this->determineKeyClass( $key ); + $kClass = $this->determineKeyClassForStats( $key ); // Get the current key value $curTTL = self::PASS_BY_REF; @@ -2299,9 +2309,9 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface { /** * @param string $key String of the format :[:]... - * @return string + * @return string A collection name to describe this class of key */ - protected function determineKeyClass( $key ) { + protected function determineKeyClassForStats( $key ) { $parts = explode( ':', $key ); return $parts[1] ?? $parts[0]; // sanity diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index 87c1d1edc6..017d745e49 100644 --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@ -1841,14 +1841,14 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { /** * @dataProvider statsKeyProvider - * @covers WANObjectCache::determineKeyClass + * @covers WANObjectCache::determineKeyClassForStats */ public function testStatsKeyClass( $key, $class ) { $wanCache = TestingAccessWrapper::newFromObject( new WANObjectCache( [ 'cache' => new HashBagOStuff ] ) ); - $this->assertEquals( $class, $wanCache->determineKeyClass( $key ) ); + $this->assertEquals( $class, $wanCache->determineKeyClassForStats( $key ) ); } } -- 2.20.1