metrics: influx: preprare value: rename $quote to $force_quote

to avoid implying that it's *only* quoted if that parameter is
truthy.

Also, check the boolean before looks_like_number call, as that is
more expensive to do.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
(cherry picked from commit b8608c53e773fad60d0008b0f1937e0cc5dd1c34)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-01-28 11:06:25 +01:00
parent 6ea437b237
commit 1185453a06

View File

@ -252,6 +252,7 @@ sub build_influxdb_payload {
# 'abc' and '123' are both valid hostnames, that confuses influx's type detection
my $to_quote = { name => 1 };
my @values = ();
foreach my $key (sort keys %$data) {
@ -307,10 +308,10 @@ sub get_recursive_values {
}
sub prepare_value {
my ($value, $quote) = @_;
my ($value, $force_quote) = @_;
# don't treat value like a number if quote is 1
if (looks_like_number($value) && !$quote) {
if (!$force_quote && looks_like_number($value)) {
if (isnan($value) || isinf($value)) {
# we cannot send influxdb NaN or Inf
return undef;