MaxSem has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/372214 )

Change subject: Log usage statistics
......................................................................

Log usage statistics

Bug: T170345
Change-Id: I7ec1214800062d9a22cd3fe0ce2ee9031fc9e21e
(cherry picked from commit 3b9faadf7d924e3983ef4d43dcc2a6e4737a7044)
---
M includes/Hooks.php
M includes/LoginNotify.php
2 files changed, 21 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/LoginNotify 
refs/changes/14/372214/1

diff --git a/includes/Hooks.php b/includes/Hooks.php
index 9ce77d8..7fe5b72 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -151,7 +151,7 @@
         *
         * @param User $user The user who logged in.
         */
-       public static function doSuccessfulLogin( User $user ) {
+       private static function doSuccessfulLogin( User $user ) {
                $loginNotify = new LoginNotify();
                $loginNotify->clearCounters( $user );
                $loginNotify->sendSuccessNotice( $user );
@@ -163,7 +163,7 @@
         *
         * @param User $user The user that failed to log in.
         */
-       public static function doFailedLogin( User $user ) {
+       private static function doFailedLogin( User $user ) {
                $loginNotify = new LoginNotify();
                $loginNotify->recordFailure( $user );
        }
diff --git a/includes/LoginNotify.php b/includes/LoginNotify.php
index 4060072..91a1938 100644
--- a/includes/LoginNotify.php
+++ b/includes/LoginNotify.php
@@ -12,6 +12,7 @@
 use CentralAuthUser;
 use Config;
 use EchoEvent;
+use IBufferingStatsdDataFactory;
 use JobQueueGroup;
 use JobSpecification;
 use MediaWiki\MediaWikiServices;
@@ -55,6 +56,8 @@
        private $gSalt;
        /** @var string */
        private $secret;
+       /** @var IBufferingStatsdDataFactory */
+       private $stats;
 
        /**
         * Constructor
@@ -83,6 +86,8 @@
 
                $log = LoggerFactory::getInstance( 'LoginNotify' );
                $this->log = $log;
+
+               $this->stats = 
MediaWikiServices::getInstance()->getStatsdDataFactory();
        }
 
        /**
@@ -618,6 +623,7 @@
                        $this->config->get( 'LoginNotifyExpiryNewIP' )
                );
                if ( $count ) {
+                       $this->incrStats( 'fail.unknown.notifications' );
                        $this->sendNotice( $user, 'login-fail-new', $count );
                }
        }
@@ -637,6 +643,7 @@
                        $this->config->get( 'LoginNotifyExpiryKnownIP' )
                );
                if ( $count ) {
+                       $this->incrStats( 'fail.known.notifications' );
                        $this->sendNotice( $user, 'login-fail-known', $count );
                }
        }
@@ -704,6 +711,7 @@
         * @param User $user User in question
         */
        public function recordFailure( User $user ) {
+               $this->incrStats( 'fail.total' );
                $known = $this->isKnownSystemFast( $user, $user->getRequest() );
                if ( $known === self::USER_KNOWN ) {
                        $this->recordLoginFailureFromKnownSystem( $user );
@@ -737,6 +745,7 @@
                if ( !$this->config->get( 'LoginNotifyEnableOnSuccess' ) ) {
                        return;
                }
+               $this->incrStats( 'success.total' );
                $result = $this->isKnownSystemFast( $user, $user->getRequest() 
);
                if ( $result !== self::USER_KNOWN ) {
                        $this->createJob( DeferredChecksJob::TYPE_LOGIN_SUCCESS,
@@ -755,6 +764,7 @@
        public function sendSuccessNoticeDeferred( User $user, $subnet, 
$resultSoFar ) {
                $isKnown = $this->isKnownSystemSlow( $user, $subnet, 
$resultSoFar );
                if ( !$isKnown ) {
+                       $this->incrStats( 'success.notifications' );
                        $this->sendNotice( $user, 'login-success' );
                }
        }
@@ -779,4 +789,13 @@
                );
                JobQueueGroup::singleton()->lazyPush( $job );
        }
+
+       /**
+        * Increments the given statistic
+        *
+        * @param string $metric
+        */
+       private function incrStats( $metric ) {
+               $this->stats->increment( "loginnotify.$metric" );
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/372214
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ec1214800062d9a22cd3fe0ce2ee9031fc9e21e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/LoginNotify
Gerrit-Branch: wmf/1.30.0-wmf.14
Gerrit-Owner: MaxSem <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to