Gergő Tisza has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/205869

Change subject: Log auth-related wfTrack events to statsd
......................................................................

Log auth-related wfTrack events to statsd

Depends on core commit I853f79a0e82f66eeb7c996505cf9f399292c3349
and ConfirmEdit commit If5f2ac37fe23886d833264166e613168b9c030f9

Bug: T91701
Change-Id: I7e5946316f62162cdd2bc7669fa40c1d44c22c2a
---
M WikimediaEvents.php
M WikimediaEventsHooks.php
2 files changed, 26 insertions(+), 1 deletion(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaEvents 
refs/changes/69/205869/1

diff --git a/WikimediaEvents.php b/WikimediaEvents.php
index 20d66f5..cb164c6 100644
--- a/WikimediaEvents.php
+++ b/WikimediaEvents.php
@@ -111,3 +111,8 @@
 $wgHooks['ListDefinedTags'][] = 'WikimediaEventsHooks::onListDefinedTags';
 $wgHooks['ChangeTagsListActive'][] = 'WikimediaEventsHooks::onListDefinedTags';
 $wgHooks['XAnalyticsSetHeader'][] = 'WikimediaEventsHooks::onXAnalyticsHeader';
+
+wfTrackSubscribe( 'captcha.display', 'WikimediaEventsHooks::onTrackAuth' );
+wfTrackSubscribe( 'captcha.submit', 'WikimediaEventsHooks::onTrackAuth' );
+wfTrackSubscribe( 'login', 'WikimediaEventsHooks::onTrackAuth' );
+wfTrackSubscribe( 'accountcreation', 'WikimediaEventsHooks::onTrackAuth' );
diff --git a/WikimediaEventsHooks.php b/WikimediaEventsHooks.php
index 5d02356..4d8abe4 100644
--- a/WikimediaEventsHooks.php
+++ b/WikimediaEventsHooks.php
@@ -8,7 +8,6 @@
  * @author Benny Situ <[email protected]>
  */
 class WikimediaEventsHooks {
-
        /**
         * Adds 'ext.wikimediaEvents.deprecate' logging module for logged-in 
users.
         *
@@ -335,4 +334,25 @@
                $tags[] = 'HHVM';
                return true;
        }
+
+       /**
+        * Count various authentication events.
+        *
+        * @param array $event see {@link wfTrackSubscribe}
+        */
+       public static function onTrackAuth( $event ) {
+               $topic = $event['topic'];
+               $context = defined( 'MW_API' ) ? 'api' : 'web';
+               $type = isset( $event['data']['type'] ) ? 
$event['data']['type'] : null;
+               $outcome = isset( $event['data']['successful'] ) ? ( 
$event['data']['successful'] ? 'success' : 'failure' ) : null;
+               $status = isset( $event['data']['status'] ) ? 
$event['data']['status'] : null;
+
+               $keyParts = array( $topic, $type, $context, $outcome );
+               if ( $outcome === 'failure' && $status !== null ) {
+                       $keyParts[] = $status;
+               }
+               $key = implode( '.', array_filter( $keyParts ) );
+
+               RequestContext::getMain()->getStats()->increment( $key );
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7e5946316f62162cdd2bc7669fa40c1d44c22c2a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikimediaEvents
Gerrit-Branch: master
Gerrit-Owner: GergÅ‘ Tisza <[email protected]>

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

Reply via email to