An error occurred within the plugin - Amazon Athena plugin

Hello everyone.
I’m trying to call Grafana HTTP POST API using POSTMAN:
http://ip:port/api/ds/query
because i want to perform a query on a datasource imported in Grafana through the Amazon Athena plugin.
In the header I have specified Authorization, Content-Type and Accept options as said in the documentation, whereas in the body I have:
{
“queries”: [
{
“refId”: “A”,
“datasource”: {
“uid”: “mydatasourceuid”
},
“rawSql”: “SELECT 1”,
“format”: “table”
}
],
“from”: “now-5m”,
“to”: “now”
}

But in the response i always get:
{
“message”: “An error occurred within the plugin”,
“messageId”: “plugin.downstreamError”,
“statusCode”: 500,
“traceID”: “”
}

Now, what is going wrong? I managed to call correctly other APIs (even the related http://ip:port/api/datasources/name/nameofthedatasourceingrafana), so I don’t think I’m doing something wrong in the request.
In fact, if I intentionally insert a wrong uid in the body:
“datasource”: {
“uid”: “wrongdatasourceid”
},
I get the response:
{
“message”: “Data source not found”,
“traceID”: “”
}

I have also done a query from the grafana GUI on a new dashboard connected to the same datasource that I’m passing in the request body and it worked.
Does anyone know how I can solve?
Thank you in advance!

still not solved.
UP

anyone can help? I am not figuring out how to solve

I’m sorry to hear that you’re experiencing difficulties.

Grafana can provide valuable information about certain issues through its own debug logs. These logs can help troubleshoot and identify the root cause of problems (especially if they are related to anything that can be configured via Grafana config file).

To enable debug logging edit the configuration file grafana.ini:

[log]
# Either "console", "file", "syslog". Default is console and file
# Use space to separate multiple modes, e.g. "console file"
mode = console file

# Either "debug", "info", "warn", "error", "critical", default is "info"
level = debug

Then restart grafana for the setting to go into effect.

Replicate the problem and check Grafana logs. However, before posting the debug logs on the community forum, it is important to sanitize any private details such as passwords, tokens, IPs, names, … By including properly formatted debug logs (with sanitized information) and details about your installations (e.g. exact Grafana version, how it was installed, OS details, …), you greatly enhance the chances of receiving accurate assistance and solutions.

I think something is not working properly with Amazon Athena plugin:

According to the first part of the error (not shown in figure), the problem seems to be related to a runtime panic caused by an invalid memory address or nil pointer dereference. Essentially, I think that the Go code of Grafana tries to access a memory location that hasn’t been initialized or is pointing to an invalid value.

Correct. But prove it/provide more details (you never mentioned your Grafana/plugin version - maybe you have old Grafana and issue is fixed in newer version - who knows when you didn’t provide details)/debug (not only error) logs in copy&paste format (how any dev can copy text from the image), pls.

Grafana version: “version”: “11.2.0” (obtained by contacting /api/health endpoint)
Amazon Athena: 3.0.0 (latest version, since I updated few days ago)

I cannot add the whole logs since too long:

logger=plugin.grafana-athena-datasource t=2025-02-03T14:40:15.303187537Z level=error msg="panic triggered" error="runtime error: invalid memory address or nil pointer dereference" stack="goroutine 36 [running]:\nruntime/debug.Stack()\n\t/usr/local/go/src/runtime/debug/stack.go:26 +0x5e\ngithub.com/grafana/grafana-plugin-sdk-go/backend.handlePanic({0x1404320, 0x2572c20})\n\t/go/pkg/mod/github.com/grafana/grafana-plugin-sdk-go@v0.261.0/backend/serve.go:137 +0x25\ngithub.com/grafana/grafana-plugin-sdk-go/backend.defaultGRPCMiddlewares.WithRecoveryHandler.func4.1({0xc0006e6388?, 0xc000616308?}, {0x1404320?, 0x2572c20?})\n\t/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware/v2@v2.2.0/interceptors/recovery/options.go:36 +0x27\ngithub.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/recovery.recoverFrom({0x1941760?, 0xc0005d2900?}, {0x1404320?, 0x2572c20?}, 0x43b029?)\n\t/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware/v2@v2.2.0/interceptors/recovery/interceptors.go:54 +0xea\ngithub.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/recovery.UnaryServerInterceptor.func1.1()\n\t/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware/v2@v2.2.0/interceptors/recovery/interceptors.go:30 +0x67\npanic({0x1404320?, 0x2572c20?})\n\t/usr/local/go/src/runtime/panic.go:785 +0x132\ngithub.com/grafana/grafana-aws-
...
logger=context userId=3 orgId=1 uname=XYZ t=2025-02-03T14:40:15.304093882Z level=error msg=InternalError error="[plugin.downstreamError] client: failed to query data: Failed to query data: rpc error: code = Unknown desc = panic triggered: runtime error: invalid memory address or nil pointer dereference" remote_addr=IPADDRESS traceID=
logger=context userId=3 orgId=1 uname=XYZ t=2025-02-03T14:40:15.304827916Z level=error msg="Request Completed" method=POST path=/api/ds/query status=500 remote_addr=IPADDRESS time_ms=39 duration=39.801424ms size=116 referer= handler=/api/ds/query status_source=downstream

Great. Finally, useful details. Try upgrade to the latest stable version.

Did you configure everything properly, so “save&test” in the datasource configuration is green?

By clicking on “Save & test” everything seems to be alright:


I’m also able to query data from Grafana GUI.

So, should I try to update Grafana to 11.5.1?

So why you need to use postman? It looks like you are not issuing the same request from the Postman as from the UI - is it really a problem of Grafana?

I’m using Postman for testing purpose, because I want to perform an API call from a python script.
I don’t know what could be wrong, I am calling the endpoint http://ip:port/api/ds/query, with a POST request with Authorization set to “Bearer myapikey”, Content-Type set to “application/json” and Accept set to “application/json” in the headers.
In the body I have:

{
  "queries": [
        {
            "refId": "A",
            "datasource": {
                "uid": "uidofmydatasource"
            },
            "rawSql": "SELECT 1",
            "format": "table"
        }
    ]
}

And I still get 500 Internal Server Error:

{
    "message": "An error occurred within the plugin",
    "messageId": "plugin.downstreamError",
    "statusCode": 500,
    "traceID": ""
}

The request should be formatted well, since by changing deliberately the datasource uid to a wrong one, I get a 404 error:

{
    "message": "Data source not found",
    "traceID": ""
}

Documentation: (Data source HTTP API | Grafana documentation)

It works in UI, so use the browser console - check request from the UI and mimic that in your Postman/python. Grafana was never intended for this use case - “REST API proxy” for script access.
You have python, so use boto3 and you can do what IAM permissions allow you. Why do you need such a complicated life, when you must have Grafana in the middle?

1 Like

By changing the body to the one of the request made on the browser it worked.
There were several fields that were missing in my postman request body.
Thank you all!
Hope this post may help someone in the future!