Skip to content

Query Not returning - Timestamp format errors?? #15

@Fujio-Turner

Description

@Fujio-Turner

Couchbase stores JSON and that JSON can be in a timeseries friendly format.
There is a _timeseries() function that if you put in the above data in you can do cool time series queries.

So I copied two docs for the time series function example

here: https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/timeseries.html

and adding them as two separate documents keys as foo1 and foo2

WITH docs AS (
  [
    {
      "region": "UK",
      "ts_data": [18.5, 18.5, 18.5, 18.5, 20, 20, 20, 20, 20, 20, 20, 20, 20,
                  20, 20, 20, 20, 20, 20, 20, 20, 16.5, 16.5, 16.5, 16.5, 16.5,
                  16.5, 16.5, 16.5, 16.5, 16.5],
      "ts_end": 1375228800000,
      "ts_start": 1372636800000,
      "ts_interval": 86400000
    },
    {
      "region": "UK",
      "ts_data": [19.5, 19.5, 19.5, 19.5, 19.5, 19.5, 19.5, 19.5, 19.5, 19.5,
                  17, 15.5, 15.5, 15.5, 15.5, 15.5, 15.5, 15.5, 15.5, 15.5,
                  15.5, 15.5, 15.5, 15.5, 15.5, 15.5, 15.5, 14, 14, 14, 14],
      "ts_end": 1377907200000,
      "ts_start": 1375315200000,
      "ts_interval": 86400000
    }
  ]
)

Now let do a grafana query on this data to show cool graphs.

here is the query for it.

SELECT t._t AS `time`, t._v0 AS `value`
FROM water AS d
USE KEYS(["foo1", "foo2"])
UNNEST _timeseries(d, {"ts_ranges": [1367513998000, 1380815997000]}) AS t
WHERE d.region = 'UK'
  AND time_range(t._t)
ORDER BY t._t ASC

but it never returns.
so I tailed the logs
tail /usr/local/var/log/grafana/grafana.log

and here are the logs of the above HTTP POST query

user@Fujio-MacBook-Air couchbase-datasource % tail  /usr/local/var/log/grafana/grafana.log
logger=plugin.couchbase-datasource t=2025-03-11T21:43:47.130702-05:00 level=info msg="Connected to couchbase cluster"
logger=plugin.couchbase-datasource t=2025-03-11T21:43:47.134927-05:00 level=info msg="QueryData called" request="&{PluginContext:{OrgID:1 PluginID:couchbase-datasource PluginVersion:1.0.0 User:0xc0000257c0 AppInstanceSettings:<nil> DataSourceInstanceSettings:0xc0001aaf00 GrafanaConfig:0xc00018e2a0 UserAgent:Grafana/11.5.1 (darwin; amd64)} Headers:map[http_X-Dashboard-Uid:defisffqd4d1ce http_X-Datasource-Uid:fefhdot1zzcaof http_X-Grafana-Id:eyJhbGciOiJFUzI1NiIsImtpZCI6ImlkLTIwMjUtMDMtZXMyNTYiLCJ0eXAiOiJqd3QifQ.eyJhdWQiOiJvcmc6MSIsImVtYWlsIjoiYWRtaW5AbG9jYWxob3N0IiwiZXhwIjoxNzQxNzQ3NzgyLCJpYXQiOjE3NDE3NDcxODIsImlkZW50aWZpZXIiOiJmZWZoM2F3NjhscnN3YSIsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMC8iLCJuYW1lIjoiYWRtaW4iLCJuYW1lc3BhY2UiOiJkZWZhdWx0Iiwic3ViIjoidXNlcjoxIiwidHlwZSI6InVzZXIiLCJ1c2VybmFtZSI6ImFkbWluIn0.f2_dm_g9mDglKQULJDcfZ2l4cMhzFBPpk2Ww5GqrzPdoxre4ECEYe7ULf2hUhKxItKFYWiuL2E9qbqPSdLZTXQ http_X-Grafana-Org-Id:1 http_X-Panel-Id:1 http_X-Panel-Plugin-Id:timeseries] Queries:[{RefID:A QueryType: MaxDataPoints:1074 Interval:3h0m0s TimeRange:{From:2013-05-02 11:59:58 -0500 CDT To:2013-10-03 10:59:57 -0500 CDT} JSON:[123 34 97 110 97 108 121 116 105 99 115 34 58 102 97 108 115 101 44 34 100 97 116 97 115 111 117 114 99 101 34 58 123 34 116 121 112 101 34 58 34 99 111 117 99 104 98 97 115 101 45 100 97 116 97 115 111 117 114 99 101 34 44 34 117 105 100 34 58 34 102 101 102 104 100 111 116 49 122 122 99 97 111 102 34 125 44 34 100 97 116 97 115 111 117 114 99 101 73 100 34 58 49 44 34 105 110 116 101 114 118 97 108 77 115 34 58 49 48 56 48 48 48 48 48 44 34 109 97 120 68 97 116 97 80 111 105 110 116 115 34 58 49 48 55 52 44 34 113 117 101 114 121 34 58 34 83 69 76 69 67 84 32 116 46 95 116 32 65 83 32 96 116 105 109 101 96 44 32 116 46 95 118 48 32 65 83 32 96 118 97 108 117 101 96 92 110 70 82 79 77 32 119 97 116 101 114 32 65 83 32 100 92 110 85 83 69 32 75 69 89 83 40 91 92 34 102 111 111 49 92 34 44 32 92 34 102 111 111 50 92 34 93 41 92 110 85 78 78 69 83 84 32 95 116 105 109 101 115 101 114 105 101 115 40 100 44 32 123 92 34 116 115 95 114 97 110 103 101 115 92 34 58 32 91 49 51 54 55 53 49 51 57 57 56 48 48 48 44 32 49 51 56 48 56 49 53 57 57 55 48 48 48 93 125 41 32 65 83 32 116 92 110 87 72 69 82 69 32 100 46 114 101 103 105 111 110 32 61 32 39 85 75 39 92 110 32 32 65 78 68 32 116 105 109 101 95 114 97 110 103 101 40 116 46 95 116 41 92 110 79 82 68 69 82 32 66 89 32 116 46 95 116 32 65 83 67 34 44 34 114 101 102 73 100 34 58 34 65 34 125]}]}"
logger=plugin.couchbase-datasource t=2025-03-11T21:43:47.135164-05:00 level=info msg="Processing query" EXTRA_VALUE_AT_END="TYPE: " refId=A
logger=plugin.couchbase-datasource t=2025-03-11T21:43:47.146254-05:00 level=info msg="Transforming query"
logger=plugin.couchbase-datasource t=2025-03-11T21:43:47.151191-05:00 level=info msg="Unmarshalled json" query_string="SELECT * FROM (SELECT t._t AS `time`, t._v0 AS `value`\nFROM water AS d\nUSE KEYS([\"foo1\", \"foo2\"])\nUNNEST _timeseries(d, {\"ts_ranges\": [1367513998000, 1380815997000]}) AS t\nWHERE d.region = 'UK'\n  AND TO_NUMBER(t._t) > STR_TO_MILLIS('2013-05-02T11:59:58-05:00') AND TO_NUMBER(t._t) <= STR_TO_MILLIS('2013-10-03T10:59:57-05:00')\nORDER BY t._t ASC) AS data ORDER by TO_NUMBER(data.t._t) ASC"
logger=plugin.couchbase-datasource t=2025-03-11T21:43:47.151446-05:00 level=info msg="Querying couchbase" query_string="SELECT * FROM (SELECT t._t AS `time`, t._v0 AS `value`\nFROM water AS d\nUSE KEYS([\"foo1\", \"foo2\"])\nUNNEST _timeseries(d, {\"ts_ranges\": [1367513998000, 1380815997000]}) AS t\nWHERE d.region = 'UK'\n  AND TO_NUMBER(t._t) > STR_TO_MILLIS('2013-05-02T11:59:58-05:00') AND TO_NUMBER(t._t) <= STR_TO_MILLIS('2013-10-03T10:59:57-05:00')\nORDER BY t._t ASC) AS data ORDER by TO_NUMBER(data.t._t) ASC"
logger=plugin.couchbase-datasource t=2025-03-11T21:43:48.623558-05:00 level=info msg="Query ok"
logger=plugin.couchbase-datasource t=2025-03-11T21:43:48.654112-05:00 level=error msg="Panic occured: interface conversion: interface {} is float64, not string"
logger=plugin.couchbase-datasource t=2025-03-11T21:43:48.888814-05:00 level=error msg="plugin process exited" plugin=/usr/local/var/lib/grafana/plugins/couchbase-datasource/dist/gpx_couchbase_darwin_amd64 id=94249 error="exit status 2"
logger=context userId=1 orgId=1 uname=admin t=2025-03-11T21:43:48.93444-05:00 level=error msg="Request Completed" method=POST path=/api/ds/query status=500 remote_addr=127.0.0.1 time_ms=2381 duration=2.381848791s size=103 referer="http://localhost:3000/d/defisffqd4d1ce/new-dashboard?editPanel=1&from=2013-05-02T16%3A59%3A58.000Z&inspect=1&inspectTab=query&orgId=1&tab=queries&timezone=browser&to=2013-10-03T15%3A59%3A57.000Z" handler=/api/ds/query status_source=downstream errorReason=InternalError errorMessageID=plugin.downstreamError error="client: failed to query data: Failed to query data: rpc error: code = Unavailable desc = error reading from server: EOF"

Why Is This Happening?

Numeric Timestamps: Your t._t field is a numeric timestamp (e.g., Unix milliseconds), which is common for time series data and typically supported by Grafana for plotting.

Plugin Expectation: The Couchbase Grafana plugin appears to expect the time field to be a string (e.g., an ISO8601 format like "2013-05-02T11:59:58-05:00"), leading to the interface conversion panic when it encounters a float64.

This mismatch suggests either a plugin bug or a misconfiguration in how it handles numeric timestamps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions