From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id E1FCA646F8 for ; Fri, 28 Jan 2022 11:03:45 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D77BB2CF93 for ; Fri, 28 Jan 2022 11:03:45 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 0D4122CF89 for ; Fri, 28 Jan 2022 11:03:45 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id CC87846D24 for ; Fri, 28 Jan 2022 11:03:44 +0100 (CET) From: Markus Frank To: pve-devel@lists.proxmox.com Date: Fri, 28 Jan 2022 11:03:39 +0100 Message-Id: <20220128100339.21230-1-m.frank@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.005 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [influxdb.pm, influxdata.com] Subject: [pve-devel] [PATCH container v3] fix #3815: influxdb vmname should be string X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jan 2022 10:03:45 -0000 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. Whichever comes first decides how the "schema" is defined. To change that I added a $to_quote hashmap to define which value shouldn't get interpreted as number. In this case the value of name. Change: Conversion happends in prepare_value. nodename and host are tags in InfluxDB so the only value they are able to contain are strings: https://docs.influxdata.com/influxdb/v2.1/reference/syntax/line-protocol/ Signed-off-by: Markus Frank --- PVE/Status/InfluxDB.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/PVE/Status/InfluxDB.pm b/PVE/Status/InfluxDB.pm index def7e2fd..63a865df 100644 --- a/PVE/Status/InfluxDB.pm +++ b/PVE/Status/InfluxDB.pm @@ -276,6 +276,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) { @@ -286,7 +288,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') { @@ -331,9 +333,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; -- 2.30.2