Fjalapeno has uploaded a new change for review.

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

Change subject: Fix search sampling Bug: T102163
......................................................................

Fix search sampling Bug: T102163

It was sending all events instead of sampling to 0.1%
This patch runs arc4rand before getting a session token.
If the user gets a session token, then all events for that session are logged.
If not, then all evens for that session are ignored.

Change-Id: I0c8b6f525a8ccb51ca1cdc20e28a805a00be6f80
---
M Wikipedia/WMFSearchFunnel.m
1 file changed, 17 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia 
refs/changes/72/217672/1

diff --git a/Wikipedia/WMFSearchFunnel.m b/Wikipedia/WMFSearchFunnel.m
index da544df..6687096 100644
--- a/Wikipedia/WMFSearchFunnel.m
+++ b/Wikipedia/WMFSearchFunnel.m
@@ -35,11 +35,11 @@
     return self;
 }
 
-- (NSString*)searchSessionToken {
-    if (!_searchSessionToken) {
-        _searchSessionToken = [[NSUUID UUID] UUIDString];
+- (void)log:(NSDictionary *)eventData{
+    if(!self.searchSessionToken){
+        return;
     }
-    return _searchSessionToken;
+    [super log:eventData];
 }
 
 - (NSDictionary*)preprocessData:(NSDictionary*)eventData {
@@ -49,8 +49,21 @@
     return [dict copy];
 }
 
+/**
+ *  Conditionally sets the search token if our super random number generator 
matches 500
+ *  This makes sure that events are only logged for 1 in 1000 search sessions 
(0.1%).
+ *  The log method will not send logs when the search token is nil.
+ */
+- (void)setSearchSessionTokenBasedOnSampleRate{
+    int random = arc4random() % 1000;
+    if(random == 500){
+        self.searchSessionToken = [[NSUUID UUID] UUIDString];
+    }
+}
+
 - (void)logSearchStart {
     self.searchSessionToken = nil;
+    [self setSearchSessionTokenBasedOnSampleRate];
     [self log:@{kActionKey: @"start"}];
 }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0c8b6f525a8ccb51ca1cdc20e28a805a00be6f80
Gerrit-PatchSet: 1
Gerrit-Project: apps/ios/wikipedia
Gerrit-Branch: 4.1.5
Gerrit-Owner: Fjalapeno <cfl...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to