Skip to content

fix(flush-sets): avoids attempting to send more than one data type to the same metric #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 111 additions & 6 deletions lib/influxdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,73 @@ function millisecondsSince(start) {

InfluxdbBackend.prototype.log = function (msg) {
util.log('[influxdb] ' + msg);
}
};

InfluxdbBackend.prototype.logResponse = function (msg, response) {
var output = '' + msg;

if (output === '') {
output = 'response';
}

output = JSON.stringify(output);

if (response !== null && typeof response === 'object') {
// build status code line
var temp = '';

if (typeof response.statusCode === 'number' && response.statusCode > 0) {
temp += response.statusCode;
}

output += ' ' + JSON.stringify(temp);

// build status text
temp = '';

if (typeof response.statusText === 'string' && response.statusText !== '') {
temp += response.statusText
}

output += ' ' + JSON.stringify(temp);

// build method + address
temp = '';

if (response.request !== null && typeof response.request === 'object') {
if (typeof response.request.method === 'string' && response.request.method !== '') {
temp += response.request.method;
}

if (typeof response.request.url === 'string' && response.request.url !== '') {
if (temp !== '') {
temp += ' ';
}

temp += response.request.url;
}
}

output += ' ' + JSON.stringify(temp);

// build headers
temp = [];

if (response.headers !== null && typeof response.headers === 'object') {
for (var key in response.headers) {
if (!response.headers.hasOwnProperty(key)) {
continue;
}

temp.push('' + key + ' = ' + response.headers[key]);
}
}

output += ' ' +JSON.stringify(temp.join('; '));
}

this.log(output);
};

InfluxdbBackend.prototype.logDebug = function (msg) {
if (this.debug) {
Expand All @@ -156,7 +222,7 @@ InfluxdbBackend.prototype.logDebug = function (msg) {

util.log('[influxdb] (DEBUG) ' + string);
}
}
};

/**
* Flush strategy handler
Expand Down Expand Up @@ -198,9 +264,48 @@ InfluxdbBackend.prototype.processFlush = function (timestamp, metrics) {
}

for (set in sets) {
sets[set].map(function (v) {
points.push(self.assembleEvent(set, [{value: v, time: timestamp,type:"set"}]));
})
// influxdb only allows one type per measurement per shard - check for any non-int values
var nonIntInSet = false;
for (var i = 0; i < sets[set].length; i++) {
var setValueStr = '' + sets[set][i]; // take the string value for checking...
var setValueInt = parseInt(setValueStr); // convert to int (well... float...)
// and check it's sane
if (!isFinite(setValueInt) || isNaN(setValueInt)) {
nonIntInSet = true;
break;
}
// convert setValueInt back to a string
setValueInt = '' + setValueInt;
// compare with the original, which is difficult because javascript numbers == float :(
if (setValueInt.length !== setValueStr.length) {
nonIntInSet = true;
break;
}
for (var j = 0; j < setValueStr.length; j++) {
var setValueStrChar = setValueStr.charAt(j);
// we only check the first 5 chars for exact match, after that we just check if numeric
if (j >= 5) {
if (setValueStrChar < '0' || setValueStrChar > '9') {
nonIntInSet = true;
break;
}
} else {
if (setValueInt.charAt(j) !== setValueStrChar) {
nonIntInSet = true;
break;
}
}
}
if (nonIntInSet) {
break;
}
}
if (!nonIntInSet) { // only add the original set values if they are all ints
sets[set].map(function (v) {
points.push(self.assembleEvent(set, [{value: v, time: timestamp,type:"set"}]));
});
}
// add the actual count
points.push(self.assembleEvent(set , [{value: sets[set].length, time: timestamp,type:"set_count"}]));
}

Expand Down Expand Up @@ -565,7 +670,7 @@ InfluxdbBackend.prototype.httpPOST_v14 = function (points) {
self.influxdbStats.httpResponseTime = millisecondsSince(startTime);

if (status >= 400) {
self.log(protocolName + ' Error: ' + status);
self.logResponse(protocolName + ' Error', res);
}
});

Expand Down