From 16ad2a779e741558db94a05699c64c2002c93930 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 21 Jul 2016 19:32:09 -0700 Subject: [PATCH] Make statsd counts for MWCallableUpdate actually useful Include the method that made the callback in the key. Change-Id: Ifc7c486ee5c8d57b2516456569bb724cf7dc2b99 --- autoload.php | 1 + includes/deferred/AtomicSectionUpdate.php | 6 +++++- includes/deferred/AutoCommitUpdate.php | 6 +++++- includes/deferred/CallableUpdate.php | 18 +++++++++++------- includes/deferred/DeferrableCallback.php | 13 +++++++++++++ includes/deferred/DeferredUpdates.php | 10 +++++++--- 6 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 includes/deferred/DeferrableCallback.php diff --git a/autoload.php b/autoload.php index 5da06d83fb..09a2928394 100644 --- a/autoload.php +++ b/autoload.php @@ -330,6 +330,7 @@ $wgAutoloadLocalClasses = [ 'DateFormats' => __DIR__ . '/maintenance/language/date-formats.php', 'DateFormatter' => __DIR__ . '/includes/parser/DateFormatter.php', 'DeadendPagesPage' => __DIR__ . '/includes/specials/SpecialDeadendpages.php', + 'DeferrableCallback' => __DIR__ . '/includes/deferred/DeferrableCallback.php', 'DeferrableUpdate' => __DIR__ . '/includes/deferred/DeferrableUpdate.php', 'DeferredStringifier' => __DIR__ . '/includes/libs/DeferredStringifier.php', 'DeferredUpdates' => __DIR__ . '/includes/deferred/DeferredUpdates.php', diff --git a/includes/deferred/AtomicSectionUpdate.php b/includes/deferred/AtomicSectionUpdate.php index ccbd6b0eee..0da5d7dde3 100644 --- a/includes/deferred/AtomicSectionUpdate.php +++ b/includes/deferred/AtomicSectionUpdate.php @@ -4,7 +4,7 @@ * Deferrable Update for closure/callback updates via IDatabase::doAtomicSection() * @since 1.27 */ -class AtomicSectionUpdate implements DeferrableUpdate { +class AtomicSectionUpdate implements DeferrableUpdate, DeferrableCallback { /** @var IDatabase */ private $dbw; /** @var string */ @@ -39,4 +39,8 @@ class AtomicSectionUpdate implements DeferrableUpdate { $this->callback = null; } } + + public function getOrigin() { + return $this->fname; + } } diff --git a/includes/deferred/AutoCommitUpdate.php b/includes/deferred/AutoCommitUpdate.php index ddf2bb878d..ef5903b668 100644 --- a/includes/deferred/AutoCommitUpdate.php +++ b/includes/deferred/AutoCommitUpdate.php @@ -4,7 +4,7 @@ * Deferrable Update for closure/callback updates that should use auto-commit mode * @since 1.28 */ -class AutoCommitUpdate implements DeferrableUpdate { +class AutoCommitUpdate implements DeferrableUpdate, DeferrableCallback { /** @var IDatabase */ private $dbw; /** @var string */ @@ -53,4 +53,8 @@ class AutoCommitUpdate implements DeferrableUpdate { $this->callback = null; } } + + public function getOrigin() { + return $this->fname; + } } diff --git a/includes/deferred/CallableUpdate.php b/includes/deferred/CallableUpdate.php index 4b19c20066..d63c292ba9 100644 --- a/includes/deferred/CallableUpdate.php +++ b/includes/deferred/CallableUpdate.php @@ -3,22 +3,26 @@ /** * Deferrable Update for closure/callback */ -class MWCallableUpdate implements DeferrableUpdate { - /** @var Closure|callable */ +class MWCallableUpdate implements DeferrableUpdate, DeferrableCallback { + /** @var callable */ private $callback; + /** @var string */ + private $fname; /** * @param callable $callback - * @throws InvalidArgumentException + * @param string $fname Calling method */ - public function __construct( $callback ) { - if ( !is_callable( $callback ) ) { - throw new InvalidArgumentException( 'Not a valid callback/closure!' ); - } + public function __construct( callable $callback, $fname = 'unknown' ) { $this->callback = $callback; + $this->fname = $fname; } public function doUpdate() { call_user_func( $this->callback ); } + + public function getOrigin() { + return $this->fname; + } } diff --git a/includes/deferred/DeferrableCallback.php b/includes/deferred/DeferrableCallback.php new file mode 100644 index 0000000000..2eb0d5dfa0 --- /dev/null +++ b/includes/deferred/DeferrableCallback.php @@ -0,0 +1,13 @@ +increment( 'deferred_updates.' . $method . '.' . get_class( $update ) ); + + $name = $update instanceof DeferrableCallback + ? get_class( $update ) . '-' . $update->getOrigin() + : get_class( $update ); + $stats->increment( 'deferred_updates.' . $method . '.' . $name ); } // Delegate DataUpdate execution to the DataUpdate class -- 2.20.1