objectcache: Escape dots from cache keys in StatsD metrics
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 14 Sep 2019 02:04:26 +0000 (03:04 +0100)
committerKrinkle <krinklemail@gmail.com>
Sat, 14 Sep 2019 18:16:55 +0000 (18:16 +0000)
Bug: T232907
Change-Id: Ia61256e24fe35803e69a83a1ca235e18297c75cd

includes/libs/objectcache/wancache/WANObjectCache.php
tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php

index 629d2cd..70f3553 100644 (file)
@@ -2488,8 +2488,9 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt
         */
        private function determineKeyClassForStats( $key ) {
                $parts = explode( ':', $key, 3 );
-
-               return $parts[1] ?? $parts[0]; // sanity
+               // Sanity fallback in case the key was not made by makeKey.
+               // Replace dots because they are special in StatsD (T232907)
+               return strtr( $parts[1] ?? $parts[0], '.', '_' );
        }
 
        /**
index ac988e6..076bf52 100644 (file)
@@ -1981,6 +1981,8 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase {
                        [ 'domain:page:5', 'page' ],
                        [ 'domain:main-key', 'main-key' ],
                        [ 'domain:page:history', 'page' ],
+                       // Regression test for T232907
+                       [ 'domain:foo-bar-1.2:abc:v2', 'foo-bar-1_2' ],
                        [ 'missingdomainkey', 'missingdomainkey' ]
                ];
        }