graph query exceeeds param limit

node.js has some built-in http header limit. when this gets exceeded,
it terminates the connection and all the queued queries fail as well
This commit is contained in:
Girish Ramakrishnan
2020-04-18 21:25:10 -07:00
parent 6ee7e75465
commit d087ed2349

View File

@@ -1440,22 +1440,34 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
};
Client.prototype.graphs = function (targets, from, options, callback) {
var config = {
params: {
target: targets,
format: 'json',
from: from
}
};
// if we have a lot of apps, targets can be very large. node will just disconnect since it exceeds header size
var size = 10, chunks = [];
for (var i = 0; i < targets.length; i += size) {
chunks.push(targets.slice(i, i+size));
}
if (options.noNullPoints) config.params.noNullPoints = true;
var result = [];
asyncForEach(chunks, function (chunk, iteratorCallback) {
var config = {
params: {
target: chunk,
format: 'json',
from: from
}
};
get('/api/v1/cloudron/graphs', config, function (error, data, status) {
if (error) return callback(error);
if (status !== 200) return callback(new ClientError(status, data));
if (options.noNullPoints) config.params.noNullPoints = true;
// the datapoint returned here is an [value, timestamp]
callback(null, data);
get('/api/v1/cloudron/graphs', config, function (error, data, status) {
if (error) return iteratorCallback(error);
if (status !== 200) return iteratorCallback(new ClientError(status, data));
// the datapoint returned here is an [value, timestamp]
result = result.concat(data);
iteratorCallback(null);
});
}, function iteratorDone(error) {
callback(error, result);
});
};