From 079e001a1aa5c7e9518ac6f69819ca37dd3548d5 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Fri, 11 Oct 2024 15:07:09 +0700 Subject: [PATCH] fix query instant --- connector/internal/native_query.go | 2 +- .../testdata/query/service_up/request.json | 110 ++++++----------- .../query/service_up_range/request.json | 114 ++++++------------ 3 files changed, 79 insertions(+), 147 deletions(-) diff --git a/connector/internal/native_query.go b/connector/internal/native_query.go index 1f948b8..b2b0b05 100644 --- a/connector/internal/native_query.go +++ b/connector/internal/native_query.go @@ -110,7 +110,7 @@ func (nqe *NativeQueryExecutor) execute(ctx context.Context, params *NativeQuery } var rawResults []map[string]any - if _, ok := nqe.Arguments[metadata.ArgumentKeyTime]; ok { + if !utils.IsNil(params.Timestamp) { rawResults, err = nqe.queryInstant(ctx, queryString, params, *flat) } else { rawResults, err = nqe.queryRange(ctx, queryString, params, *flat) diff --git a/connector/testdata/query/service_up/request.json b/connector/testdata/query/service_up/request.json index 89df3c8..cba7c5b 100644 --- a/connector/testdata/query/service_up/request.json +++ b/connector/testdata/query/service_up/request.json @@ -1,84 +1,52 @@ { - "arguments": { - "instance": { - "type": "literal", - "value": "localhost:9090" - }, - "job": { - "type": "literal", - "value": "node" - }, - "time": { - "type": "literal", - "value": "2024-10-10T00:00:00Z" - }, - "timeout": { - "type": "literal", - "value": "1m" - }, - "where": { - "type": "literal", - "value": { - "job": { "_neq": "node" } - } - } - }, "collection": "service_up", - "collection_relationships": {}, "query": { "fields": { - "__value": { - "column": "__value", + "job": { "type": "column", "column": "job", "fields": null }, + "instance": { "type": "column", "column": "instance", "fields": null }, + "timestamp": { "type": "column", "column": "timestamp", "fields": null }, + "value": { "type": "column", "column": "value", "fields": null }, + "values": { + "type": "column", + "column": "values", "fields": { + "type": "array", "fields": { + "type": "object", "fields": { - "instance": { - "column": "instance", - "type": "column" - }, - "job": { - "column": "job", - "type": "column" - }, - "labels": { - "column": "labels", - "type": "column" - }, "timestamp": { + "type": "column", "column": "timestamp", - "type": "column" - }, - "value": { - "column": "value", - "type": "column" + "fields": null }, - "values": { - "column": "values", - "fields": { - "fields": { - "fields": { - "timestamp": { - "column": "timestamp", - "type": "column" - }, - "value": { - "column": "value", - "type": "column" - } - }, - "type": "object" - }, - "type": "array" - }, - "type": "column" - } - }, - "type": "object" - }, - "type": "array" - }, - "type": "column" + "value": { "type": "column", "column": "value", "fields": null } + } + } + } } + }, + "predicate": { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { "type": "column", "name": "timestamp", "path": [] }, + "operator": "_eq", + "value": { "type": "scalar", "value": "2024-10-11" } + }, + { + "type": "binary_comparison_operator", + "column": { "type": "column", "name": "job", "path": [] }, + "operator": "_nregex", + "value": { "type": "scalar", "value": "node" } + } + ] } - } + }, + "arguments": { + "instance": { "type": "literal", "value": "node-exporter:9100" }, + "job": { "type": "literal", "value": "node" }, + "step": { "type": "literal", "value": "1m" } + }, + "collection_relationships": {} } diff --git a/connector/testdata/query/service_up_range/request.json b/connector/testdata/query/service_up_range/request.json index e61cab7..4d20d2c 100644 --- a/connector/testdata/query/service_up_range/request.json +++ b/connector/testdata/query/service_up_range/request.json @@ -1,88 +1,52 @@ { - "arguments": { - "instance": { - "type": "literal", - "value": "localhost:9090" - }, - "job": { - "type": "literal", - "value": "node" - }, - "start": { - "type": "literal", - "value": "2024-09-20T00:00:00Z" - }, - "step": { - "type": "literal", - "value": "1h" - }, - "timeout": { - "type": "literal", - "value": "1m" - }, - "where": { - "type": "literal", - "value": { - "job": { "_neq": "node" } - } - } - }, "collection": "service_up", - "collection_relationships": {}, "query": { "fields": { - "__value": { - "column": "__value", + "job": { "type": "column", "column": "job", "fields": null }, + "instance": { "type": "column", "column": "instance", "fields": null }, + "timestamp": { "type": "column", "column": "timestamp", "fields": null }, + "value": { "type": "column", "column": "value", "fields": null }, + "values": { + "type": "column", + "column": "values", "fields": { + "type": "array", "fields": { + "type": "object", "fields": { - "instance": { - "column": "instance", - "type": "column" - }, - "job": { - "column": "job", - "type": "column" - }, - "labels": { - "column": "labels", - "type": "column" - }, "timestamp": { + "type": "column", "column": "timestamp", - "type": "column" - }, - "value": { - "column": "value", - "type": "column" + "fields": null }, - "values": { - "column": "values", - "fields": { - "fields": { - "fields": { - "timestamp": { - "column": "timestamp", - "type": "column" - }, - "value": { - "column": "value", - "type": "column" - } - }, - "type": "object" - }, - "type": "array" - }, - "type": "column" - } - }, - "type": "object" - }, - "type": "array" - }, - "type": "column" + "value": { "type": "column", "column": "value", "fields": null } + } + } + } } + }, + "predicate": { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { "type": "column", "name": "timestamp", "path": [] }, + "operator": "_gt", + "value": { "type": "scalar", "value": "2024-10-11" } + }, + { + "type": "binary_comparison_operator", + "column": { "type": "column", "name": "job", "path": [] }, + "operator": "_nregex", + "value": { "type": "scalar", "value": "node" } + } + ] } - } + }, + "arguments": { + "instance": { "type": "literal", "value": "node-exporter:9100" }, + "job": { "type": "literal", "value": "node" }, + "step": { "type": "literal", "value": "1d" } + }, + "collection_relationships": {} }