From b627b29c09c561ed961bcd432a0f15a6f34b3096 Mon Sep 17 00:00:00 2001 From: William Felipe Welter Date: Fri, 19 Jun 2020 17:44:08 -0300 Subject: [PATCH 1/2] Fix bug when labels include "\" character before closing quotes Fix bug when labels include "\" character before closing quotes Input example: vmware_vm_guest_disk_capacity{cluster_name="CLUSTER-ABC",dc_name="LAN-BRAZIL",environment="Datacenter-AWS",host_name="lan.example.com",instance="localhost:9273",job="vmware_exporter",partition="F:\\",vm_name="VMTEST001"} 21064335360 1592592551506 Error Output: Unexpected end char V --- src/parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parse.c b/src/parse.c index d6151e3..382b9f5 100644 --- a/src/parse.c +++ b/src/parse.c @@ -77,7 +77,7 @@ parse_labels(char *input, PrometheusParseCtx *ctx) value_start = input + i; - while ((input[i] != '"' || (input[i] == '"' && input[i-1] =='\\')) && input[i] != '\0') + while ((input[i] != '"' || (input[i] == '"' && input[i-1] =='\\' && input[i-2] !='\\')) && input[i] != '\0') { i++; } From 3215eff90665e9d2e72ee5841879182c524a6727 Mon Sep 17 00:00:00 2001 From: William Felipe Welter Date: Fri, 19 Jun 2020 20:14:11 -0300 Subject: [PATCH 2/2] Updating tests expected output to psql >= 10 version --- test/expected/normalized.out | 48 ++++++++++++++++++------------------ test/expected/raw.out | 8 +++--- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/test/expected/normalized.out b/test/expected/normalized.out index 4384ca3..2564802 100644 --- a/test/expected/normalized.out +++ b/test/expected/normalized.out @@ -23,36 +23,36 @@ SELECT create_prometheus_table('input'); (3 rows) \d input - View "public.input" - Column | Type | Modifiers ---------+--------------------------+----------- - sample | prom_sample | - time | timestamp with time zone | - name | text | - value | double precision | - labels | jsonb | + View "public.input" + Column | Type | Collation | Nullable | Default +--------+--------------------------+-----------+----------+--------- + sample | prom_sample | | | + time | timestamp with time zone | | | + name | text | | | + value | double precision | | | + labels | jsonb | | | Triggers: insert_trigger INSTEAD OF INSERT ON input FOR EACH ROW EXECUTE PROCEDURE prometheus.insert_view_normal('input_values', 'input_labels') \d input_values - Table "public.input_values" - Column | Type | Modifiers ------------+--------------------------+----------- - time | timestamp with time zone | - value | double precision | - labels_id | integer | + Table "public.input_values" + Column | Type | Collation | Nullable | Default +-----------+--------------------------+-----------+----------+--------- + time | timestamp with time zone | | | + value | double precision | | | + labels_id | integer | | | Indexes: "input_values_labels_id_idx" btree (labels_id, "time" DESC) Foreign-key constraints: "input_values_labels_id_fkey" FOREIGN KEY (labels_id) REFERENCES input_labels(id) \d input_labels - Table "public.input_labels" - Column | Type | Modifiers --------------+---------+----------------------------------------------------------- - id | integer | not null default nextval('input_labels_id_seq'::regclass) - metric_name | text | not null - labels | jsonb | + Table "public.input_labels" + Column | Type | Collation | Nullable | Default +-------------+---------+-----------+----------+------------------------------------------ + id | integer | | not null | nextval('input_labels_id_seq'::regclass) + metric_name | text | | not null | + labels | jsonb | | | Indexes: "input_labels_pkey" PRIMARY KEY, btree (id) "input_labels_metric_name_labels_key" UNIQUE CONSTRAINT, btree (metric_name, labels) @@ -62,10 +62,10 @@ Referenced by: TABLE "input_values" CONSTRAINT "input_values_labels_id_fkey" FOREIGN KEY (labels_id) REFERENCES input_labels(id) \d+ input_copy - Table "public.input_copy" - Column | Type | Modifiers | Storage | Stats target | Description ---------+-------------+-----------+---------+--------------+------------- - sample | prom_sample | not null | plain | | + Table "public.input_copy" + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+-------------+-----------+----------+---------+---------+--------------+------------- + sample | prom_sample | | not null | | plain | | Triggers: insert_trigger BEFORE INSERT ON input_copy FOR EACH ROW EXECUTE PROCEDURE prometheus.insert_view_normal('input_values', 'input_labels') diff --git a/test/expected/raw.out b/test/expected/raw.out index a116758..2635dfe 100644 --- a/test/expected/raw.out +++ b/test/expected/raw.out @@ -7,10 +7,10 @@ CREATE TABLE metrics (sample prom_sample); CREATE INDEX metrics_time_idx ON metrics (prom_time(sample)); CREATE INDEX metrics_labels_idx ON metrics USING GIN (prom_labels(sample)); \d metrics - Table "public.metrics" - Column | Type | Modifiers ---------+-------------+----------- - sample | prom_sample | + Table "public.metrics" + Column | Type | Collation | Nullable | Default +--------+-------------+-----------+----------+--------- + sample | prom_sample | | | Indexes: "metrics_labels_idx" gin (prom_labels(sample)) "metrics_time_idx" btree (prom_time(sample))