Couchbase-Ecosystem / grafana-plugin

Grafana Couchbase datasource plugin
MIT License
12 stars 3 forks source link

500 error when querying #6

Closed jeffdgr8 closed 3 months ago

jeffdgr8 commented 9 months ago

When querying a Couchbase datasource using the plugin, I consistently get 500 errors for all valid queries (invalid queries give other errors). Using the travel-sample bucket and this query:

SELECT r.date as time, r.content FROM `travel-sample`.inventory.hotel ht UNNEST ht.reviews r LIMIT 10;

I get this error response:

{
  "request": {
    "url": "api/ds/query?ds_type=couchbase-datasource&requestId=explore_nO3",
    "method": "POST",
    "data": {
      "queries": [
        {
          "refId": "A",
          "datasource": {
            "type": "couchbase-datasource",
            "uid": "P520070B0D602FCEC"
          },
          "query": "SELECT r.date as time, r.content FROM `travel-sample`.inventory.hotel ht UNNEST ht.reviews r LIMIT 10;",
          "analytics": false,
          "datasourceId": 1,
          "intervalMs": 10000,
          "maxDataPoints": 1834
        }
      ],
      "from": "1704379750156",
      "to": "1704401350156"
    },
    "hideFromInspector": false
  },
  "response": {
    "message": "An error occurred within the plugin",
    "messageId": "plugin.downstreamError",
    "statusCode": 500,
    "traceID": ""
  }
}

These are the Docker logs:

grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.278700165Z level=info msg="QueryData called" request="&{PluginContext:{OrgID:1 PluginID:couchbase-datasource User:0xc00027f200 AppInstanceSettings:<nil> DataSourceInstanceSettings:0xc0002cc8f0} Headers:map[http_X-Datasource-Uid:P520070B0D602FCEC http_X-Grafana-Org-Id:1 http_X-Panel-Id:undefined] Queries:[{RefID:A QueryType: MaxDataPoints:1834 Interval:10s TimeRange:{From:2024-01-04 14:40:21.271 +0000 UTC To:2024-01-04 20:40:21.271 +0000 UTC} 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 80 53 50 48 48 55 48 66 48 68 54 48 50 70 67 69 67 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 48 48 48 44 34 109 97 120 68 97 116 97 80 111 105 110 116 115 34 58 49 56 51 52 44 34 113 117 101 114 121 34 58 34 83 69 76 69 67 84 32 114 46 100 97 116 101 32 97 115 32 116 105 109 101 44 32 114 46 99 111 110 116 101 110 116 32 70 82 79 77 32 96 116 114 97 118 101 108 45 115 97 109 112 108 101 96 46 105 110 118 101 110 116 111 114 121 46 104 111 116 101 108 32 104 116 32 85 78 78 69 83 84 32 104 116 46 114 101 118 105 101 119 115 32 114 32 76 73 77 73 84 32 49 48 59 34 44 34 114 101 102 73 100 34 58 34 65 34 125]}]}"
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.278728374Z level=info msg="Processing query" EXTRA_VALUE_AT_END="TYPE: " refId=A
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.278739263Z level=info msg="Transforming query"
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.278780364Z level=info msg="Unmarshalled json" query_string="SELECT r.date as time, r.content FROM `travel-sample`.inventory.hotel ht UNNEST ht.reviews r LIMIT 10;"
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.278786743Z level=info msg="Querying couchbase" query_string="SELECT r.date as time, r.content FROM `travel-sample`.inventory.hotel ht UNNEST ht.reviews r LIMIT 10;"
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.302483244Z level=info msg="Query ok"
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.302526914Z level=error msg="Panic occured: interface conversion: interface {} is nil, not map[string]interface {}"
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.306679763Z level=error msg="plugin process exited" plugin=/var/lib/grafana/plugins/couchbase-datasource/dist/gpx_couchbase_linux_amd64 id=85 error="exit status 2"
grafana  | logger=context userId=1 orgId=1 uname=admin t=2024-01-04T20:40:21.306745712Z level=error msg="Internal server error" error="[plugin.downstreamError] client: failed to query data: Failed to query data: rpc error: code = Unavailable desc = error reading from server: EOF" remote_addr=172.17.0.1 traceID=
grafana  | logger=context userId=1 orgId=1 uname=admin t=2024-01-04T20:40:21.306785532Z level=error msg="Request Completed" method=POST path=/api/ds/query status=500 remote_addr=172.17.0.1 time_ms=31 duration=31.074951ms size=116 referer="http://localhost:3000/explore?orgId=1&schemaVersion=1" handler=/api/ds/query
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:22.062647163Z level=info msg=Profiler enabled=false

This is with the latest version of Grafana, v10.2.3.

jeffdgr8 commented 9 months ago

Modifying the code to log the stack trace to the logger, I see it's failing on this line:

d := row["data"].(map[string]interface{})
jeffdgr8 commented 9 months ago

Looking into this more, it seems it does this when you don't include either str_time_range or time_range in the query, so it doesn't get modified to have a data key in the query results. I need to better understand the code to understand what the proper way to handle this should be, but an appropriate error message at a minimum should be expected.

chedim commented 3 months ago

HI @jeffdgr8 , yes, using str_time_range or time_range in the query is required for the Grafana plugin because all queries are expected to have a time filter.