From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <t.lamprecht@proxmox.com>
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 F1FA1645E3
 for <pve-devel@lists.proxmox.com>; Fri, 28 Jan 2022 07:08:34 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id E55FA2AFA6
 for <pve-devel@lists.proxmox.com>; Fri, 28 Jan 2022 07:08:34 +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 1D5062AF99
 for <pve-devel@lists.proxmox.com>; Fri, 28 Jan 2022 07:08:34 +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 D5843456E0
 for <pve-devel@lists.proxmox.com>; Fri, 28 Jan 2022 07:08:33 +0100 (CET)
Message-ID: <3c729f28-c8e9-0ca4-a7a8-35be5bb98c47@proxmox.com>
Date: Fri, 28 Jan 2022 07:08:32 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:97.0) Gecko/20100101
 Thunderbird/97.0
Content-Language: en-US
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Markus Frank <m.frank@proxmox.com>
References: <20220127125255.65105-1-m.frank@proxmox.com>
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
In-Reply-To: <20220127125255.65105-1-m.frank@proxmox.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.062 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
 NICE_REPLY_A           -0.001 Looks like a legit reply (A)
 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. [influxdata.com, influxdb.pm]
Subject: Re: [pve-devel] [PATCH manager v2] 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 <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Fri, 28 Jan 2022 06:08:35 -0000

On 27.01.22 13:52, Markus Frank wrote:
> 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 $quoted hashmap to quote a value.
> In this case the value of name.
> 
> nodename and host are tags in InfluxDB so the only value they are able
> to contain are strings:

ah great, thanks for clearing that up to me! 

Some more comments because it seems I only checked out surrounding code more
closely now, argh.

> https://docs.influxdata.com/influxdb/v2.1/reference/syntax/line-protocol/
> 
> Signed-off-by: Markus Frank <m.frank@proxmox.com>
> ---
>  PVE/Status/InfluxDB.pm | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/PVE/Status/InfluxDB.pm b/PVE/Status/InfluxDB.pm
> index def7e2fd..d63e18ac 100644
> --- a/PVE/Status/InfluxDB.pm
> +++ b/PVE/Status/InfluxDB.pm
> @@ -276,6 +276,7 @@ sub test_connection {
>  sub build_influxdb_payload {
>      my ($class, $txn, $data, $ctime, $tags, $excluded, $measurement, $instance) = @_;
>

can we add a small comment here, something like:

# 'abc' and '123' are both valid hostnames, that confuses influx's type detection
  
> +    my $quoted = { name => 1 };
>      my @values = ();
>  
>      foreach my $key (sort keys %$data) {
> @@ -283,6 +284,10 @@ sub build_influxdb_payload {
>  	my $value = $data->{$key};
>  	next if !defined($value);
>  
> +	if (defined($quoted) && $quoted->{$key}) {

The defined check is not required anymore as we always define that variable
locally now.

> +	    $value =~ s/\"/\\\"/g;
> +	    $value = "\"$value\"";
> +	}
so this actually looks quite Ok, but when wanting to finally apply this I saw
some other opportunity, namely, we already got prepare_value and it can already
quote, so instead of doing the quoting manually above we could add a $force_quote
(or something in that spirit) parameter and then just call it like:

prepare_value($value, $to_quote->{$key})