]> git.proxmox.com Git - pve-manager.git/commitdiff
fix #3815: metrics: influxdb: coerce guest name always to string
authorMarkus Frank <m.frank@proxmox.com>
Fri, 28 Jan 2022 10:03:39 +0000 (11:03 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 14 Mar 2022 09:44:20 +0000 (10:44 +0100)
InfluxDB interprets the guest name '66601' as a number and the guest
name 'vm42' as a String. This leads to problematic metrics, that will
be dropped by influxdb. Whichever comes first decides how the
"schema" is defined.

To change that add a $to_quote hashmap to define which value
shouldn't get interpreted as number by always send it quoted.

For now only quote 'name'.

Note, that while the 'nodename' and 'host' properties would have the
same problem, they are tags in InfluxDB which are always interpreted
as strings:
https://docs.influxdata.com/influxdb/v2.1/reference/syntax/line-protocol/

Signed-off-by: Markus Frank <m.frank@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
(cherry picked from commit 988150664900d447e7bdb5d0e23edadb4bd82f35)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/Status/InfluxDB.pm

index fcb28800fe1ce1120ec1bb04fd218d7f429755ae..0c6c88f38ebda36cf31880943f8b3d5c862bdc0a 100644 (file)
@@ -250,6 +250,8 @@ sub test_connection {
 sub build_influxdb_payload {
     my ($class, $txn, $data, $ctime, $tags, $excluded, $measurement, $instance) = @_;
 
+    # '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) {
@@ -260,7 +262,7 @@ sub build_influxdb_payload {
        if (!ref($value) && $value ne '') {
            # value is scalar
 
-           if (defined(my $v = prepare_value($value))) {
+           if (defined(my $v = prepare_value($value, $to_quote->{$key}))) {
                push @values, "$key=$v";
            }
        } elsif (ref($value) eq 'HASH') {
@@ -305,9 +307,10 @@ sub get_recursive_values {
 }
 
 sub prepare_value {
-    my ($value) = @_;
+    my ($value, $quote) = @_;
 
-    if (looks_like_number($value)) {
+    # don't treat value like a number if quote is 1
+    if (looks_like_number($value) && !$quote) {
        if (isnan($value) || isinf($value)) {
            # we cannot send influxdb NaN or Inf
            return undef;