Phedenskog has uploaded a new change for review.

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

Change subject: Check the statsv limit size before sending metrics
......................................................................

Check the statsv limit size before sending metrics

Check the current limit of the URL length sent to statsv
and split into multiple request depending on the actual
length.

Bug: T114997
Change-Id: I676500b082e1b0abee6526874316770628c689c3
---
M lib/reporter/statsv.js
1 file changed, 28 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/performance/WebPageTest 
refs/changes/95/248295/1

diff --git a/lib/reporter/statsv.js b/lib/reporter/statsv.js
index 37c9a14..ba6d4b3 100644
--- a/lib/reporter/statsv.js
+++ b/lib/reporter/statsv.js
@@ -8,6 +8,22 @@
 'use strict';
 var request = require('request');
 
+var STATSV_MAX_LENGTH = 1000;
+
+function sendMetrics(url, endpoint) {
+    console.log('Will send:' + url);
+    request(url, function(error, response, body) { // jshint unused:false
+        if (!error) {
+            console.log('Succesfully sent metrics.');
+        } else {
+            // default testing to localhost, then skip error logging
+            if (endpoint.indexOf('http://localhost') === -1) {
+                console.error(error);
+            }
+        }
+    });
+}
+
 module.exports = {
     /**
      * Validate the input arguments.
@@ -39,33 +55,23 @@
             });
         });
 
-
-        // 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 + '?';
-
         var keys = Object.keys(flatten);
+        var newUrl;
         for (var i = 0; i < keys.length; i++) {
-
-            url += keys[i] + '=' + flatten[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 === 
flatten.length)) {
+            newUrl = url + keys[i] + '=' + flatten[keys[i]] + '&';
+            // If the new length is larger that the limit, send what we have
+            if (newUrl.length >= STATSV_MAX_LENGTH) {
                 url = url.slice(0, -1);
-                console.log(url);
-                request(url, function(error, response, body) { // jshint 
unused:false
-                    if (!error) {
-                        console.log('Succesfully sent metrics.');
-                    } else {
-                        // default testing to localhost, then skip error 
logging
-                        if (endpoint.indexOf('http://localhost') === -1) {
-                            console.error(error);
-                        }
-                    }
-                });
-                url = endpoint + '?';
+                sendMetrics(url, endpoint);
+                // Reset base url and add the new one
+                url = endpoint + '?' + keys[i] + '=' + flatten[keys[i]] + '&';
+            } else {
+                url = newUrl;
             }
         }
+        // send the last batch of metrics
+        url = url.slice(0, -1);
+        sendMetrics(url, endpoint);
     }
 };

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I676500b082e1b0abee6526874316770628c689c3
Gerrit-PatchSet: 1
Gerrit-Project: performance/WebPageTest
Gerrit-Branch: master
Gerrit-Owner: Phedenskog <phedens...@wikimedia.org>

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

Reply via email to