resourceloader: Use increment() for resourceloader_cache miss metric
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 1 Sep 2015 19:15:53 +0000 (21:15 +0200)
committerOri.livneh <ori@wikimedia.org>
Wed, 2 Sep 2015 04:22:40 +0000 (04:22 +0000)
This makes it consistent with how we handle the resourceloader_cache hit metric.

When I added the miss metric I figured it was nice to get both counts and timings
in a single metric, but I can't trust StatsD/Graphite not to screw this up so
let's untangle them to be sure.

Change-Id: I24f68e34a9fa491806fdb6023bdd757f6688c2ed

includes/resourceloader/ResourceLoader.php

index fd2263b..5fb6c96 100644 (file)
@@ -191,6 +191,7 @@ class ResourceLoader implements LoggerAwareInterface {
                }
                // Defaults
                $options += array( 'cache' => true, 'cacheReport' => false );
+               $stats = RequestContext::getMain()->getStats();
 
                // Don't filter empty content
                if ( trim( $data ) === '' ) {
@@ -211,18 +212,16 @@ class ResourceLoader implements LoggerAwareInterface {
                        $cache = wfGetCache( wfIsHHVM() ? CACHE_ACCEL : CACHE_ANYTHING );
                        $cacheEntry = $cache->get( $key );
                        if ( is_string( $cacheEntry ) ) {
-                               wfIncrStats( "resourceloader_cache.$filter.hit" );
+                               $stats->increment( "resourceloader_cache.$filter.hit" );
                                return $cacheEntry;
                        }
                        $result = '';
                        try {
-                               $stats = RequestContext::getMain()->getStats();
                                $statStart = microtime( true );
-
                                $result = self::applyFilter( $filter, $data, $this->config );
-
                                $statTiming = microtime( true ) - $statStart;
-                               $stats->timing( "resourceloader_cache.$filter.miss", 1000 * $statTiming );
+                               $stats->increment( "resourceloader_cache.$filter.miss" );
+                               $stats->timing( "resourceloader_cache.$filter.timing", 1000 * $statTiming );
                                if ( $options['cacheReport'] ) {
                                        $result .= "\n/* cache key: $key */";
                                }