Skip to content

Commit

Permalink
fix query instant
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Oct 11, 2024
1 parent 3d93356 commit 079e001
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 147 deletions.
2 changes: 1 addition & 1 deletion connector/internal/native_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
110 changes: 39 additions & 71 deletions connector/testdata/query/service_up/request.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
114 changes: 39 additions & 75 deletions connector/testdata/query/service_up_range/request.json
Original file line number Diff line number Diff line change
@@ -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": {}
}

0 comments on commit 079e001

Please sign in to comment.