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
Influxdb incorrect storage types #3354
Changes from 1 commit
a988e83
f9fda59
933e163
761f55b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1252,10 +1252,28 @@ function function_check($function) { | |
return function_exists($function); | ||
} | ||
|
||
function force_influx_data($type,$data) { | ||
if ($type == 'f' || $type == 'float') { | ||
return(sprintf("%.1f",$data)); | ||
function force_influx_data($data) { | ||
/* | ||
* It is not trivial to detect if something is a float or an integer, and | ||
* therefore may cause breakages on inserts. | ||
* Just setting every number to a float gets around this, but may introduce | ||
* inefficiencies. | ||
* I've left the detection statement in there for a possible change in future, | ||
* but currently everything just gets set to a float. | ||
*/ | ||
|
||
if (is_numeric($data)) { | ||
// If it is an Integer | ||
if (ctype_digit($data)) { | ||
return floatval($data); | ||
// Else it is a float | ||
} else { | ||
return floatval($data); | ||
} | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another } else { :) |
||
return $data; | ||
} | ||
|
||
}// end force_influx_data | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ | |
$value = $data_array[0][$oid]; | ||
} | ||
else { | ||
$value = 'U'; | ||
$value = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason this is changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH, this entire loop can probably go. Its duplicating what is already done in includes/rrdtool.inc.php:rrdtool_update This was changed as this will create the influx field as a string if it is the first data to be inserted. This is no good when the actual data if it is not defined is a numeric value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The U is for rrdtools' benefit rather than influx. Think it needs to go back to U. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I wasn't too clear. In the rrd_update function which is called a little later, the following occurs: foreach ($options as $k => $v) {
if (!is_numeric($v)) {
$v = U;
}
$values[] = $v;
} This sets U for non numeric data before inserting into the RRD. This bit of code here is doing that again, but on a specific subset of the data. In my opinion, munging the data for inclusion into a datastore should belong in that datastores insert function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case either revert the change and leave it as it was or remove the code if it's not needed. |
||
} | ||
$fields[$oid] = $value; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change any } else {
to
}
else {