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 <[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