public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH manager v2] fix #3815: influxdb vmname should be string
@ 2022-01-27 12:52 Markus Frank
  2022-01-28  6:08 ` Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Frank @ 2022-01-27 12:52 UTC (permalink / raw)
  To: pve-devel

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:
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) = @_;
 
+    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}) {
+	    $value =~ s/\"/\\\"/g;
+	    $value = "\"$value\"";
+	}
 	if (!ref($value) && $value ne '') {
 	    # value is scalar
 
-- 
2.30.2





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pve-devel] [PATCH manager v2] fix #3815: influxdb vmname should be string
  2022-01-27 12:52 [pve-devel] [PATCH manager v2] fix #3815: influxdb vmname should be string Markus Frank
@ 2022-01-28  6:08 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2022-01-28  6:08 UTC (permalink / raw)
  To: Proxmox VE development discussion, Markus Frank

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})





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-28  6:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-27 12:52 [pve-devel] [PATCH manager v2] fix #3815: influxdb vmname should be string Markus Frank
2022-01-28  6:08 ` Thomas Lamprecht

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