jenkins-bot has submitted this change and it was merged.

Change subject: Collect asset size per type
......................................................................


Collect asset size per type

Collect the asset size per type (html, js,
css and images) and the number of requests.

Also send X amount of metrics per request
to statsv.

Bug: T112629
Change-Id: I55a4e325128625807f8629377cae6d5dc18a2d9b
---
M lib/index.js
M lib/util.js
M test/utilTest.js
3 files changed, 62 insertions(+), 35 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/index.js b/lib/index.js
index a0b99d7..c6bae78 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -87,7 +87,7 @@
                 if (argv.sendMetrics) {
                     util.sendMetrics(collectedMetrics, endpoint);
                 } else {
-                    console.log('Dry run:' + collectedMetrics);
+                    console.log('Dry run: ' + JSON.stringify(collectedMetrics, 
null, 2));
                 }
                 callback();
             }
diff --git a/lib/util.js b/lib/util.js
index fa10c61..55eaee4 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -42,22 +42,32 @@
     // Note: It can differs depending on what agent that runs the tests.
     // Note 2: Make sure we don't hit the statsv limit of maximum chars in one 
request
     METRICS: ['SpeedIndex', 'render', 'TTFB', 'fullyLoaded'],
+    ASSET_TYPES: ['html','js','css','image'],
     sendMetrics: function(metrics, endpoint) {
+
+        // Lets do something smarter in the future, now
+        // cut after 5 keys and send a new request
+        var MAX_KEYS_PER_REQUEST = 5;
         var url = endpoint + '?';
 
-        metrics.forEach(function(metric) {
-            url += metric + '&';
-        });
+        var keys = Object.keys(metrics);
+        for (var i = 0; i < keys.length; i++) {
 
-        url = url.slice(0, -1);
-
-        request(url, function(error, response, body) { // jshint unused:false
-            if (!error) {
-                console.log('Succesfully sent metrics to ' + url);
-            } else {
-                console.error(error);
+            url += keys[i] + '=' + metrics[keys[i]] + '&';
+            // don't send first, and then for each MAX_KEYS_PER_REQUEST
+            // and the last time
+            if (i !== 0 && i % MAX_KEYS_PER_REQUEST === 0 || (i - 1 === 
keys.length)) {
+                url = url.slice(0, -1);
+                request(url, function(error, response, body) { // jshint 
unused:false
+                    if (!error) {
+                        console.log('Succesfully sent metrics to ' + url);
+                    } else {
+                        console.error(error);
+                    }
+                });
+                url = endpoint + '?';
             }
-        });
+        }
     },
     setupWPTOptions: function(argv) {
         // some default options here
@@ -86,7 +96,7 @@
     collectMetrics: function(wptJson, userStatus, namespace) {
 
         var self = this;
-        var metricsToSend = [];
+        var metricsToSend = {};
 
         VIEWS.forEach(function(view) {
             // if we are missing browser info from WPT (happens when using 
MotoG at least)
@@ -97,17 +107,26 @@
              wptJson.data.location.replace(/[^A-Za-z_]/g, '_');
 
             self.METRICS.forEach(function(metric) {
-                metricsToSend.push(namespace + '.' + userStatus + '.' + 
browser + '.' + view +
-                '.' + metric + '=' + wptJson.data.median[view][metric] + 'ms');
+                metricsToSend[namespace + '.' + userStatus + '.' + browser + 
'.' + view +
+                '.' + metric] =  wptJson.data.median[view][metric] + 'ms';
             });
 
             if (wptJson.data.median.firstView.userTimes) {
                 
Object.keys(wptJson.data.median.firstView.userTimes).forEach(function(userTiming)
 {
-                    metricsToSend.push(namespace + '.' + userStatus + '.' + 
browser + '.' + view +
-                     '.' + userTiming + '=' + 
wptJson.data.median[view].userTimes[userTiming] +
-                      'ms');
+                    metricsToSend[namespace + '.' + userStatus + '.' + browser 
+ '.' + view +
+                   '.' + userTiming ] =  
wptJson.data.median[view].userTimes[userTiming] +
+                    'ms';
                 });
             }
+
+            // collect sizes & assets
+            self.ASSET_TYPES.forEach(function(assetType) {
+                metricsToSend[namespace + '.' + userStatus + '.' + browser + 
'.' + view + '.' +
+                assetType + '.requests' ] = 
wptJson.data.median[view].breakdown[assetType].requests;
+                metricsToSend[namespace + '.' + userStatus + '.' + browser + 
'.' + view + '.' +
+                assetType + '.bytes' ] = 
wptJson.data.median[view].breakdown[assetType].bytes;
+            });
+
         });
 
         return metricsToSend;
diff --git a/test/utilTest.js b/test/utilTest.js
index 47f335a..797b766 100644
--- a/test/utilTest.js
+++ b/test/utilTest.js
@@ -62,20 +62,21 @@
     var userStatus = 'anonymous';
     var namespace = 'webpagetest';
     var metrics = util.collectMetrics(mobileJson, userStatus, namespace);
-    metrics.forEach(function(metric) {
+    Object.keys(metrics).forEach(function(key) {
       // verify that we aren't fetching any undefined values = values missing 
in the WPT file
-      assert.strictEqual(metric.indexOf('undefined'),-1,'We have an undefined 
value in ' + metric);
+      assert.strictEqual(metrics[key].toString().indexOf('undefined'), -1, 'We 
have an undefined value in ' + key);
     });
 
     // verify that we collect all the metrics that we want
     util.METRICS.forEach(function(definedMetric) {
-        var metricIncluded = false;
-        metrics.forEach(function(metric) {
-          if (metric.indexOf(definedMetric) > -1) {
-            metricIncluded = true;
-          }
-        });
-        assert.strictEqual(metricIncluded, true, 'We are missing metric ' + 
definedMetric);
+      var metricIncluded = false;
+      var keys = Object.keys(metrics);
+      for (var i = 0; i < keys.length; i++) {
+        if (keys[i].indexOf(definedMetric) > -1) {
+          metricIncluded = true;
+        }
+      }
+      assert.strictEqual(metricIncluded, true, 'We are missing metric ' + 
definedMetric);
     });
 
 
@@ -87,20 +88,27 @@
     var userStatus = 'anonymous';
     var namespace = 'webpagetest';
     var metrics = util.collectMetrics(desktopJson, userStatus, namespace);
-    metrics.forEach(function(metric) {
-      // verify that we aren't fetching any undefined values = values missing 
in the WPT file
-      assert.strictEqual(metric.indexOf('undefined'),-1,'We have an undefined 
value in ' + metric);
+    Object.keys(metrics).forEach(function(metricKey) {
+      assert.strictEqual(metrics[metricKey].toString().indexOf('undefined'), 
-1, 'We have an undefined value in ' + metricKey);
     });
 
     // verify that we collect all the metrics that we want
     util.METRICS.forEach(function(definedMetric) {
-        var metricIncluded = false;
-        metrics.forEach(function(metric) {
-          if (metric.indexOf(definedMetric) > -1) {
-            metricIncluded = true;
+      var included = false;
+      Object.keys(metrics).forEach(function(metric) {
+        if (metric.indexOf(definedMetric) > -1) {
+          included = true;
+        }
+      });
+
+      util.ASSET_TYPES.forEach(function(assetType) {
+        Object.keys(metrics).forEach(function(type) {
+          if (type.indexOf(assetType) > -1) {
+            included = true;
           }
         });
-        assert.strictEqual(metricIncluded, true, 'We are missing metric ' + 
definedMetric);
+        assert.strictEqual(included, true, 'We are missing metric ' + 
definedMetric);
+      });
     });
 
   });

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I55a4e325128625807f8629377cae6d5dc18a2d9b
Gerrit-PatchSet: 5
Gerrit-Project: performance/WebPageTest
Gerrit-Branch: master
Gerrit-Owner: Phedenskog <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to