Mhurd has uploaded a new change for review. https://gerrit.wikimedia.org/r/217943
Change subject: Fix search sampling Bug: T102163 ...................................................................... Fix search sampling Bug: T102163 It was sending all events instead of sampling to 1% Change-Id: I0c8b6f525a8ccb51ca1cdc20e28a805a00be6f80 --- M Wikipedia/EventLogging/EventLoggingFunnel.h M Wikipedia/EventLogging/EventLoggingFunnel.m M Wikipedia/WMFSearchFunnel.m 3 files changed, 41 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia refs/changes/43/217943/1 diff --git a/Wikipedia/EventLogging/EventLoggingFunnel.h b/Wikipedia/EventLogging/EventLoggingFunnel.h index 2bbba9c..748b2cc 100644 --- a/Wikipedia/EventLogging/EventLoggingFunnel.h +++ b/Wikipedia/EventLogging/EventLoggingFunnel.h @@ -32,6 +32,17 @@ @property (nonatomic, assign) int revision; /** + * Sampling rate used to calculate sampling ratio. + * Rate: Ratio: Percent: + * 1 1/1 100% + * 2 1/2 50% + * 3 1/3 33% + * ... + * 100 1/100 1% + */ +@property (nonatomic, assign) NSInteger rate; + +/** * This constructor should be called internally by derived classes * to encapsulate the schema name and version. */ diff --git a/Wikipedia/EventLogging/EventLoggingFunnel.m b/Wikipedia/EventLogging/EventLoggingFunnel.m index 29dd320..4b322aa 100644 --- a/Wikipedia/EventLogging/EventLoggingFunnel.m +++ b/Wikipedia/EventLogging/EventLoggingFunnel.m @@ -17,6 +17,7 @@ if (self) { self.schema = schema; self.revision = revision; + self.rate = 1; } return self; } @@ -33,10 +34,18 @@ - (void)log:(NSDictionary*)eventData wiki:(NSString*)wiki { if ([SessionSingleton sharedInstance].shouldSendUsageReports) { - (void)[[EventLogger alloc] initAndLogEvent:[self preprocessData:eventData] - forSchema:self.schema - revision:self.revision - wiki:wiki]; + BOOL chosen = NO; + if (self.rate == 1) { + chosen = YES; + } else if (self.rate != 0) { + chosen = (self.getEventLogSamplingID % self.rate) == 0; + } + if (chosen) { + (void)[[EventLogger alloc] initAndLogEvent:[self preprocessData:eventData] + forSchema:self.schema + revision:self.revision + wiki:wiki]; + } } } @@ -55,4 +64,20 @@ return uuid; } +/** + * Persistent random integer id used for sampling. + * + * @return integer sampling id + */ +- (NSInteger)getEventLogSamplingID { + NSNumber* samplingId = [[NSUserDefaults standardUserDefaults] objectForKey:@"EventLogSamplingID"]; + if (!samplingId) { + NSInteger intId = arc4random_uniform(UINT32_MAX); + [[NSUserDefaults standardUserDefaults] setInteger:intId forKey:@"EventLogSamplingID"]; + return intId; + } else { + return samplingId.integerValue; + } +} + @end diff --git a/Wikipedia/WMFSearchFunnel.m b/Wikipedia/WMFSearchFunnel.m index da544df..5db3d8b 100644 --- a/Wikipedia/WMFSearchFunnel.m +++ b/Wikipedia/WMFSearchFunnel.m @@ -30,6 +30,7 @@ - (instancetype)init { self = [super initWithSchema:kSchemaName version:kSchemaVersion]; if (self) { + self.rate = 100; _appInstallId = [self persistentUUID:kSchemaName]; } return self; -- To view, visit https://gerrit.wikimedia.org/r/217943 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: master Gerrit-Owner: Mhurd <mh...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits