Katie Horn has submitted this change and it was merged.

Change subject: Add MinFraud Query Limit Alarm to DI
......................................................................


Add MinFraud Query Limit Alarm to DI

We don't have a method to know when we need to buy more minfraud
queries. Now we do :)

Change-Id: I82f2b6f1908166002b50d85cf9768cdf23be4f09
---
M DonationInterface.php
M extras/custom_filters/filters/minfraud/minfraud.body.php
M extras/extras.body.php
3 files changed, 39 insertions(+), 0 deletions(-)

Approvals:
  Katie Horn: Verified; Looks good to me, approved



diff --git a/DonationInterface.php b/DonationInterface.php
index 810b9f8..bca2250 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -558,6 +558,13 @@
 
        // Timeout in seconds for communicating with MaxMind
        $wgMinFraudTimeout = 2;
+
+       /**
+        * When to send an email to $wgEmergencyContact that we're
+        * running low on minfraud queries. Will continue to send
+        * once per day until the limit is once again over the limit.
+        */
+       $wgDonationInterfaceMinfraudAlarmLimit = 25000;
 }
 
 //Referrer Filter globals
diff --git a/extras/custom_filters/filters/minfraud/minfraud.body.php 
b/extras/custom_filters/filters/minfraud/minfraud.body.php
index 03fbcc2..29c348f 100644
--- a/extras/custom_filters/filters/minfraud/minfraud.body.php
+++ b/extras/custom_filters/filters/minfraud/minfraud.body.php
@@ -254,6 +254,7 @@
                
                // Write the query/response to the log before we go mad.
                $this->log_query();
+               $this->health_check();
                
                try {
                        $this->cfo->addRiskScore( 
$this->minfraudResponse['riskScore'], 'minfraud_filter' );
@@ -386,4 +387,31 @@
 
                return TRUE;
        }
+
+       /**
+        * Perform a health check on minfraud data; send an email alarm on 
violation.
+        *
+        * Right now this only checks the number of queries remaining.
+        */
+       protected function health_check() {
+               global $wgEmergencyContact, $wgServerName, $wgMemc;
+
+               if ( array_key_exists( 'queriesRemaining', 
$this->minfraudResponse ) ) {
+                       $queries = intval( 
$this->minfraudResponse['queriesRemaining'] );
+
+                       if ( $queries < $this->gateway_adapter->getGlobal( 
'MinfraudAlarmLimit' ) ) {
+                               $key = wfMemcKey( 'DonationInterface', 
'MinFraud', 'QueryAlarmLast' );
+                               $lastAlarmAt = $wgMemc->get( $key ) | 0;
+                               if ( $lastAlarmAt < time() - ( 60 * 60 * 24 ) ) 
{
+                                       $wgMemc->set( $key, time() );
+                                       UserMailer::send(
+                                               $wgEmergencyContact,
+                                               'donationinterface@' . 
$wgServerName,
+                                               'Minfraud Queries Remaining 
Low',
+                                               'Queries remaining: ' . $queries
+                                       );
+                               }
+                       }
+               }
+       }
 }
diff --git a/extras/extras.body.php b/extras/extras.body.php
index 82b85b1..4385ee4 100644
--- a/extras/extras.body.php
+++ b/extras/extras.body.php
@@ -10,6 +10,10 @@
         * @var
         */
        public $log_fh = NULL;
+
+       /**
+        * @var GatewayAdapter
+        */
        public $gateway_adapter;
 
        public function __construct( &$gateway_adapter ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I82f2b6f1908166002b50d85cf9768cdf23be4f09
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>
Gerrit-Reviewer: Adamw <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to