public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: markus frank <m.frank@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager] fix #3815: influxdb vmname should always be a string
Date: Thu, 27 Jan 2022 12:13:18 +0100	[thread overview]
Message-ID: <20220127111318.36615-1-m.frank@proxmox.com> (raw)

InfluxDB interprets the vmname 66601 as a number and the vmname vm42 as a String. This leads to problematic metrics, that will be dropped by influxdb.
To change that I added a $quoted hashmap (simular to $excluded) to quote a value. In this case the value of name.

Signed-off-by: markus frank <m.frank@proxmox.com>
---
 PVE/Status/InfluxDB.pm | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/PVE/Status/InfluxDB.pm b/PVE/Status/InfluxDB.pm
index def7e2fd..f49feac4 100644
--- a/PVE/Status/InfluxDB.pm
+++ b/PVE/Status/InfluxDB.pm
@@ -116,7 +116,7 @@ sub update_qemu_status {
     $object =~ s/\s/\\ /g;
 
     # VMID is already added in base $object above, so exclude it from being re-added
-    build_influxdb_payload($class, $txn, $data, $ctime, $object, { 'vmid' => 1 });
+    build_influxdb_payload($class, $txn, $data, $ctime, $object, { 'vmid' => 1 }, { 'name' => 1 });
 }
 
 sub update_lxc_status {
@@ -131,7 +131,7 @@ sub update_lxc_status {
     $object =~ s/\s/\\ /g;
 
     # VMID is already added in base $object above, so exclude it from being re-added
-    build_influxdb_payload($class, $txn, $data, $ctime, $object, { 'vmid' => 1 });
+    build_influxdb_payload($class, $txn, $data, $ctime, $object, { 'vmid' => 1 }, { 'name' => 1 });
 }
 
 sub update_storage_status {
@@ -274,7 +274,7 @@ sub test_connection {
 }
 
 sub build_influxdb_payload {
-    my ($class, $txn, $data, $ctime, $tags, $excluded, $measurement, $instance) = @_;
+    my ($class, $txn, $data, $ctime, $tags, $excluded, $quoted, $measurement, $instance) = @_;
 
     my @values = ();
 
@@ -283,6 +283,10 @@ sub build_influxdb_payload {
 	my $value = $data->{$key};
 	next if !defined($value);
 
+	if (defined($quoted) && $quoted->{$key}){
+	    $value =~ s/\"/\\\"/g;
+            $value = "\"$value\"";
+        }
 	if (!ref($value) && $value ne '') {
 	    # value is scalar
 
@@ -293,9 +297,9 @@ sub build_influxdb_payload {
 	    # value is a hash
 
 	    if (!defined($measurement)) {
-		build_influxdb_payload($class, $txn, $value, $ctime, $tags, $excluded, $key);
+		build_influxdb_payload($class, $txn, $value, $ctime, $tags, $excluded, $quoted, $key);
 	    } elsif(!defined($instance)) {
-		build_influxdb_payload($class, $txn, $value, $ctime, $tags, $excluded, $measurement, $key);
+		build_influxdb_payload($class, $txn, $value, $ctime, $tags, $excluded, $quoted, $measurement, $key);
 	    } else {
 		push @values, get_recursive_values($value);
 	    }
-- 
2.30.2





             reply	other threads:[~2022-01-27 11:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-27 11:13 markus frank [this message]
2022-01-27 11:38 ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220127111318.36615-1-m.frank@proxmox.com \
    --to=m.frank@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal