Merge "objectcache: add metrics for WAN cache deletes and check key touches/resets"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 8 Mar 2019 21:40:12 +0000 (21:40 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 8 Mar 2019 21:40:12 +0000 (21:40 +0000)
1  2 
includes/libs/objectcache/WANObjectCache.php

@@@ -214,6 -214,12 +214,6 @@@ class WANObjectCache implements IExpiri
        const FLD_FLAGS = 4; // key to the flags bitfield (reserved number)
        const FLD_HOLDOFF = 5; // key to any hold-off TTL
  
 -      const ERR_NONE = 0; // no error
 -      const ERR_NO_RESPONSE = 1; // no response
 -      const ERR_UNREACHABLE = 2; // can't connect
 -      const ERR_UNEXPECTED = 3; // response gave some error
 -      const ERR_RELAY = 4; // relay broadcast failed
 -
        const VALUE_KEY_PREFIX = 'WANCache:v:';
        const INTERIM_KEY_PREFIX = 'WANCache:i:';
        const TIME_KEY_PREFIX = 'WANCache:t:';
         * @param array $params
         *   - cache    : BagOStuff object for a persistent cache
         *   - logger   : LoggerInterface object
 -       *   - stats    : LoggerInterface object
 +       *   - stats    : StatsdDataFactoryInterface object
         *   - asyncHandler : A function that takes a callback and runs it later. If supplied,
         *       whenever a preemptive refresh would be triggered in getWithSetCallback(), the
         *       current cache value is still used instead. However, the async-handler function
         * @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;
        }
  
         */
        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;
        }
  
        /**
         */
        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;
        }
  
        /**
                $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;
  
        /**
         * @param string $key String of the format <scope>:<class>[:<class or variable>]...
-        * @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