Closed wuyb66 closed 4 years ago
Sorry, I'm not using influxdb-flux-datasource with InfluxDB 1.7.x.
Some logs for your reference. Log for grafana: ts=2020-06-01T06:57:14.814955Z lvl=debug msg=Request log_id=0N7ek1L0000 service=http method=POST host=xxx.xxx.107.9:9999 path=/api/v2/query query="org=05c107f454510000" proto=HTTP/1.1 status_code=200 response_size=5618 content_length=428 referrer= remote=172.17.0.3:46463 user_agent=influxdb-client-go took=7276.118ms body="{\"dialect\":{\"annotations\":[\"datatype\",\"group\",\"default\"],\"delimiter\":\",\",\"header\":true},\"query\":\"from(bucket: \\"meas2\\")\r\n |\u003e range(start: 2020-01-25T15:00:00Z, stop: 2020-01-27T15:59:59Z)\r\n |\u003e filter(fn: (r) =\u003e r[\\"_measurement\\"] == \\"MS_PROCESS_MEAS\\")\r\n |\u003e filter(fn: (r) =\u003e r[\\"_field\\"] == \\"CPUTIME\\")\r\n |\u003e group(columns: [ \\"_time\\" ])\r\n |\u003e sum()\r\n\r\n\",\"type\":\"flux\"}" Log for flux query: ts=2020-06-01T07:02:24.428030Z lvl=debug msg=Request log_id=0N7ek1L0000 service=http method=POST host=xxx.xxx.107.9:9999 path=/api/v2/query query="orgID=05c107f454510000" proto=HTTP/1.1 status_code=200 response_size=5614 content_length=1100 referrer=http://xxx.xxx.107.9:9999/orgs/05c107f454510000/data-explorer remote=10.141.12.79:52753 user_agent=Firefox took=7767.091ms body="{\"query\":\"from(bucket: \\"meas2\\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\\"_measurement\\"] == \\"MS_PROCESS_MEAS\\")\r\n |> filter(fn: (r) => r[\\"_field\\"] == \\"CPUTIME\\")\r\n |> group(columns: [\\"_time\\"])\r\n |> sum()\r\n\",\"extern\":{\"type\":\"File\",\"package\":null,\"imports\":null,\"body\":[{\"type\":\"OptionStatement\",\"assignment\":{\"type\":\"VariableAssignment\",\"id\":{\"type\":\"Identifier\",\"name\":\"v\"},\"init\":{\"type\":\"ObjectExpression\",\"properties\":[{\"type\":\"Property\",\"key\":{\"type\":\"Identifier\",\"name\":\"bucket\"},\"value\":{\"type\":\"StringLiteral\",\"value\":\"meas\"}},{\"type\":\"Property\",\"key\":{\"type\":\"Identifier\",\"name\":\"timeRangeStart\"},\"value\":{\"type\":\"DateTimeLiteral\",\"value\":\"2020-01-25T07:45:01.000Z\"}},{\"type\":\"Property\",\"key\":{\"type\":\"Identifier\",\"name\":\"timeRangeStop\"},\"value\":{\"type\":\"DateTimeLiteral\",\"value\":\"2020-01-28T08:45:01.000Z\"}},{\"type\":\"Property\",\"key\":{\"type\":\"Identifier\",\"name\":\"windowPeriod\"},\"value\":{\"type\":\"DurationLiteral\",\"values\":[{\"magnitude\":730000,\"unit\":\"ms\"}]}}]}}}]},\"dialect\":{\"annotations\":[\"group\",\"datatype\",\"default\"]}}"
It is also OK from CLI. cat cpu.flux from(bucket: "meas2") |> range(start: -140d, stop: -120d) |> filter(fn: (r) => r["_measurement"] == "MS_PROCESS_MEAS") |> filter(fn: (r) => r["_field"] == "CPUTIME") |> group(columns: ["_time"]) |> sum()
./influx query --file ./cpu.flux --org-id 05c107f454510000 Result: _result Table: keys: [_time] _time:time _value:float
2020-01-25T15:01:00.000000000Z 850.2599999999998
Table: keys: [_time]
_time:time _value:float
2020-01-25T15:06:00.000000000Z 851.5700000000005
Table: keys: [_time]
_time:time _value:float
2020-01-25T15:11:00.000000000Z 844.2600000000003
...
Table: keys: [_time]
_time:time _value:float
2020-01-27T15:31:00.000000000Z 826.2900000000004
Table: keys: [_time]
_time:time _value:float
2020-01-27T15:36:00.000000000Z 825.0600000000001
Table: keys: [_time]
_time:time _value:float
2020-01-27T15:41:00.000000000Z 807.7400000000011
Log: ts=2020-06-02T06:29:19.222443Z lvl=debug msg=Request log_id=0N7ek1L0000 service=http method=POST host=localhost:9999 path=/api/v2/query query="orgID=05c107f454510000" proto=HTTP/1.1 status_code=200 response_size=5618 content_length=1872 referrer= remote=[::1]:52992 user_agent=Go-http-client took=7756.535ms body="{\"type\":\"flux\",\"query\":\"\",\"spec\":{\"operations\":[{\"kind\":\"influxDBFrom\",\"id\":\"influxDBFrom0\",\"spec\":{\"bucket\":\"meas2\"}},{\"kind\":\"range\",\"id\":\"range1\",\"spec\":{\"start\":\"-3360h0m0s\",\"stop\":\"-2880h0m0s\",\"timeColumn\":\"_time\",\"startColumn\":\"_start\",\"stopColumn\":\"_stop\"}},{\"kind\":\"filter\",\"id\":\"filter2\",\"spec\":{\"fn\":{\"fn\":{\"type\":\"FunctionExpression\",\"block\":{\"type\":\"FunctionBlock\",\"parameters\":{\"type\":\"FunctionParameters\",\"list\":[{\"type\":\"FunctionParameter\",\"key\":{\"type\":\"Identifier\",\"name\":\"r\"}}],\"pipe\":null},\"body\":{\"type\":\"BinaryExpression\",\"operator\":\"==\",\"left\":{\"type\":\"MemberExpression\",\"object\":{\"type\":\"IdentifierExpression\",\"name\":\"r\"},\"property\":\"_measurement\"},\"right\":{\"type\":\"StringLiteral\",\"value\":\"MS_PROCESS_MEAS\"}}}}}}},{\"kind\":\"filter\",\"id\":\"filter3\",\"spec\":{\"fn\":{\"fn\":{\"type\":\"FunctionExpression\",\"block\":{\"type\":\"FunctionBlock\",\"parameters\":{\"type\":\"FunctionParameters\",\"list\":[{\"type\":\"FunctionParameter\",\"key\":{\"type\":\"Identifier\",\"name\":\"r\"}}],\"pipe\":null},\"body\":{\"type\":\"BinaryExpression\",\"operator\":\"==\",\"left\":{\"type\":\"MemberExpression\",\"object\":{\"type\":\"IdentifierExpression\",\"name\":\"r\"},\"property\":\"_field\"},\"right\":{\"type\":\"StringLiteral\",\"value\":\"CPUTIME\"}}}}}}},{\"kind\":\"group\",\"id\":\"group4\",\"spec\":{\"mode\":\"by\",\"columns\":[\"_time\"]}},{\"kind\":\"sum\",\"id\":\"sum5\",\"spec\":{\"columns\":[\"_value\"]}}],\"edges\":[{\"parent\":\"influxDBFrom0\",\"child\":\"range1\"},{\"parent\":\"range1\",\"child\":\"filter2\"},{\"parent\":\"filter2\",\"child\":\"filter3\"},{\"parent\":\"filter3\",\"child\":\"group4\"},{\"parent\":\"group4\",\"child\":\"sum5\"}],\"resources\":{\"priority\":\"high\",\"concurrency_quota\":0,\"memory_bytes_quota\":0},\"now\":\"2020-06-02T06:29:11.463039272Z\"},\"dialect\":{\"header\":true,\"delimiter\":\"\u0000\",\"commentPrefix\":\"#\",\"dateTimeFormat\":\"RFC3339\",\"annotations\":[\"datatype\",\"group\",\"default\"]},\"now\":\"0001-01-01T00:00:00Z\",\"PreferNoContent\":false,\"PreferNoContentWithError\":false}\n"
flux support was added to grafana 7.1 (released today :tada: ) -- I believe this issue is fixed, if not, please open an issue in https://github.com/grafana/grafana
The following query can get correct result from both grafana and flux query. from(bucket: "meas2") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r["_measurement"] == "MS_PROCESS_MEAS") |> filter(fn: (r) => r["_field"] == "CPUTIME")
"Metric request error" returned when adding group() clause and the correct result can be returned using flux query. from(bucket: "meas2") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r["_measurement"] == "MS_PROCESS_MEAS") |> filter(fn: (r) => r["_field"] == "CPUTIME") |> group(columns: [ "_time" ]) |> sum()
Influxdb: influxdb_2.0.0-beta.10_linux_amd64 Grafana: docker grafana/grafana:7.0.0