[pve-devel] [PATCH v2 manager] fix #3440: influxdb: remove duplicate vmid tag

Lorenz Stechauner l.stechauner at proxmox.com
Wed May 26 11:25:11 CEST 2021


remove vmid from data part, it is already contained in object part.
this is accomplished by adding the parameter $excluded to
build_influxdb_payload().

Signed-off-by: Lorenz Stechauner <l.stechauner at proxmox.com>
---
changes to v1:
- not using `delete` anymore
- added parameter `excluded` to build_influxdb_payload()

 PVE/Status/InfluxDB.pm | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/PVE/Status/InfluxDB.pm b/PVE/Status/InfluxDB.pm
index 9e4b0d96..b2bd25d2 100644
--- a/PVE/Status/InfluxDB.pm
+++ b/PVE/Status/InfluxDB.pm
@@ -94,7 +94,8 @@ sub update_qemu_status {
     }
     $object =~ s/\s/\\ /g;
 
-    build_influxdb_payload($class, $txn, $data, $ctime, $object);
+    # Duplicate keys may result in unwanted behavior
+    build_influxdb_payload($class, $txn, $data, $ctime, $object, { 'vmid' => 1 });
 }
 
 sub update_lxc_status {
@@ -108,7 +109,8 @@ sub update_lxc_status {
     }
     $object =~ s/\s/\\ /g;
 
-    build_influxdb_payload($class, $txn, $data, $ctime, $object);
+    # Duplicate keys may result in unwanted behavior
+    build_influxdb_payload($class, $txn, $data, $ctime, $object, { 'vmid' => 1 });
 }
 
 sub update_storage_status {
@@ -246,11 +248,12 @@ sub test_connection {
 }
 
 sub build_influxdb_payload {
-    my ($class, $txn, $data, $ctime, $tags, $measurement, $instance) = @_;
+    my ($class, $txn, $data, $ctime, $tags, $excluded, $measurement, $instance) = @_;
 
     my @values = ();
 
     foreach my $key (sort keys %$data) {
+	next if defined($excluded) && $excluded->{$key};
 	my $value = $data->{$key};
 	next if !defined($value);
 
@@ -264,9 +267,9 @@ sub build_influxdb_payload {
 	    # value is a hash
 
 	    if (!defined($measurement)) {
-		build_influxdb_payload($class, $txn, $value, $ctime, $tags, $key);
+		build_influxdb_payload($class, $txn, $value, $ctime, $tags, $excluded, $key);
 	    } elsif(!defined($instance)) {
-		build_influxdb_payload($class, $txn, $value, $ctime, $tags, $measurement, $key);
+		build_influxdb_payload($class, $txn, $value, $ctime, $tags, $excluded, $measurement, $key);
 	    } else {
 		push @values, get_recursive_values($value);
 	    }
-- 
2.20.1





More information about the pve-devel mailing list