[MediaWiki-commits] [Gerrit] Check the statsv limit size before sending metrics - change (performance/WebPageTest)

2015-10-26 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

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, 30 insertions(+), 24 deletions(-)

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



diff --git a/lib/reporter/statsv.js b/lib/reporter/statsv.js
index 37c9a14..f9cb188 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 = 2000;
+
+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.
@@ -22,7 +38,7 @@
  */
 help: function() {
 console.log('   --endpoint   Where to send the statsv metrics 
' +
-'[https://www.example.com]');
+'[http://localhost]');
 },
 /**
  * Report the metrics by sending them to statsv.
@@ -30,7 +46,7 @@
  * @param {array} argv The input parameters for the run.
  */
 report: function(metrics, argv) {
-var endpoint = argv.endpoint || 'https://www.example.com';
+var endpoint = argv.endpoint || 'http://localhost';
 var flatten = {};
 // flatten the structure
 Object.keys(metrics).forEach(function(type) {
@@ -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: merged
Gerrit-Change-Id: I676500b082e1b0abee6526874316770628c689c3
Gerrit-PatchSet: 3
Gerrit-Project: performance/WebPageTest
Gerrit-Branch: master
Gerrit-Owner: Phedenskog 
Gerrit-Reviewer: Krinkle 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] Check the statsv limit size before sending metrics - change (performance/WebPageTest)

2015-10-23 Thread Phedenskog (Code Review)
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 

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


[MediaWiki-commits] [Gerrit] Check the statsv limit size before sending metrics - change (performance/WebPageTest)

2015-10-08 Thread Phedenskog (Code Review)
Phedenskog has uploaded a new change for review.

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

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

Check the statsv limit size before sending metrics

Changed the implementation to instead check the current limit
(1000 characters) so we send the metrics before we reach the limit
instead of sending 5 metrics at a time.

Bug: T114997
Change-Id: I1addda9394e309f6f834f7c92908c86bd55dc3e4
---
M lib/reporter/statsv.js
1 file changed, 26 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/performance/WebPageTest 
refs/changes/22/244422/1

diff --git a/lib/reporter/statsv.js b/lib/reporter/statsv.js
index aee5f9b..7f8bcae 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,32 +55,21 @@
 });
 });
 
-
-// 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);
 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)) {
+// if the new length is larger that the limit, send what we have
+if ((url + keys[i] + '=' + flatten[keys[i]] + '&').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);
-}
-}
-});
+sendMetrics(url, endpoint);
 url = endpoint + '?';
+} else {
+url += keys[i] + '=' + flatten[keys[i]] + '&';
+}
+// if it's the last iteration, send what we have
+if (i + 1 === keys.length) {
+url = url.slice(0, -1);
+sendMetrics(url, endpoint);
 }
 }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1addda9394e309f6f834f7c92908c86bd55dc3e4
Gerrit-PatchSet: 1
Gerrit-Project: performance/WebPageTest
Gerrit-Branch: master
Gerrit-Owner: Phedenskog 

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