AndyRussG has uploaded a new change for review.

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

Change subject: WIP Banner history logger: minify and cutoff for EL data
......................................................................

WIP Banner history logger: minify and cutoff for EL data

Change-Id: Iceb916ee0b4710032660837113e09dd830c9046c
---
M resources/subscribing/ext.centralNotice.bannerHistoryLogger.js
1 file changed, 76 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice 
refs/changes/60/231060/1

diff --git a/resources/subscribing/ext.centralNotice.bannerHistoryLogger.js 
b/resources/subscribing/ext.centralNotice.bannerHistoryLogger.js
index 51c9c00..7152f1f 100644
--- a/resources/subscribing/ext.centralNotice.bannerHistoryLogger.js
+++ b/resources/subscribing/ext.centralNotice.bannerHistoryLogger.js
@@ -12,7 +12,10 @@
                log,
 
                BANNER_HISTORY_KEY = 'banner_history',
-               EVENT_LOGGING_SCHEMA = 'CentralNoticeBannerHistory';
+               EVENT_LOGGING_SCHEMA = 'CentralNoticeBannerHistory',
+
+               // Max bytes for EventLogging payload; leaving around 100 bytes 
leeway
+               MAX_EL_PAYLOAD = 900;
 
        /**
         * Load the banner history log from KV storage
@@ -98,20 +101,83 @@
        }
 
        /**
-        * Return an object with data for EventLogging
+        * Return an object with data for EventLogging.
+        * We scrunch the data as small as possible due to the WMF 
infrastructure's
+        * EventLogging payload limit.
         * @returns {Object}
         */
        function makeEventLoggingData( rate ) {
 
-               var data = cn.data;
+               var data = cn.data,
+                       kvErrorLog = cn.getKVStorageErrorLog(),
+                       byteCount = 6, // initial value: outer curlies
+                       elData = {},
+                       kvErrorLogTime, i, logEntry, statusCode;
 
-               return {
-                       log: log,
-                       project: data.project,
-                       device: data.device,
-                       rate: rate,
-                       kvStorageErrorsLog: cn.getKVStorageErrorLog()
-               };
+               // sample rate
+               elData.r = rate;
+               byteCount += 2 + rate.toString().length;
+
+               // if applicable, time of last kv store error
+               if ( kvErrorLog.length > 0 ) {
+                       kvErrorLogTime = kvErrorLog[kvErrorLog.length - 1].time;
+                       elData.e = kvErrorLogTime;
+
+                       // comma after previous property, property name, colon, 
quotes, value
+                       byteCount += 9 + kvErrorLogTime.length;
+               }
+
+               if ( !log ) {
+                       return elData;
+               }
+
+               // total log length ("size")
+               // byteCount increase includes comma after previous property
+               elData.s = log.length;
+               byteCount += 3 + log.length.toString().length;
+
+               // banner history log entries
+               elData.l = [];
+
+               // comma after previous property and outer square brackets
+               byteCount += 7;
+
+               i = log.length - 1;
+               while ( i >= 0 ) {
+                       logEntry = log[i];
+
+                       // outer curlies
+                       byteCount += 6;
+
+                       // comma after previous entry, if applicable
+                       if ( i < log.length - 1) {
+                               byteCount += 1;
+                       }
+
+                       // property name, colon, quotes, val
+                       byteCount += 8 + logEntry.banner.encodeUri().length;
+
+                       // comma after previous property, property name, colon, 
quotes, val
+                       byteCount += 9 + logEntry.time.length;
+
+                       // TODO not respecting encapsulation here
+                       statusCode = cn.internal.state.STATUSES.indexOf( 
logEntry.status );
+
+                       // comma after previous property, property name, colon, 
val
+                       byteCount += 3 + statusCode.toString().length;
+
+                       if ( byetCount > MAX_EL_PAYLOAD ) {
+                               break;
+                       }
+
+                       elData.l.unshift {
+                               b: logEntry.banner,
+                               t: logEntry.time,
+                               s: logEntry.status
+                       }
+               }
+
+               return elData;
        }
 
        // Set a function to run after a campaign is chosen and after a banner 
for

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iceb916ee0b4710032660837113e09dd830c9046c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: campaign_mixins
Gerrit-Owner: AndyRussG <[email protected]>

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

Reply via email to