Grafana flux query fail error

As per this issue:

  • What Grafana version and what operating system are you using?
    Grafana v10.0.1 & Ubuntu 22.04.2 LTS

  • What are you trying to achieve?
    Resolve errors shown in the grafana-server log file after dashboard refreshes.

  • How are you trying to achieve it?
    Errors are caused every time a page refreshes (not auto-refresh, but actual F5 style refresh).

  • What happened?
    Server error messages saying:

Jun 23 14:28:46 HOSTNAME grafana[41728]: logger=tsdb.influx_flux t=2023-06-23T14:28:46.584983091+01:00 level=warn msg=“Flux query failed” err=“Post "https://HOSTNAME.HERE:8086/api/v2/query?org=ORG_HERE\”: context canceled" query=“from(bucket: "BUCKET_NAME")\r\n |> range(start: -3s, stop: 2023-06-23T13:28:46.7Z)\r\n |> filter(fn: (r) => r["Metric"] == "Alarm_info")\r\n |> last()”

  • What did you expect to happen?
    No error message.

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    The dashboard displays correctly, no errors on the UI.

  • Did you follow any online instructions? If so, what is the URL?

Hi @olliecampbell

Can you paste your full query here and also a screenshot of it working in Influx Data Explorer?

@grant2 It seems panels with an influx query that ends in ‘last()’ seem to cause this error, but only when the webpage has been left dormant on a tab for a while I think.

If I view a single panel that uses this last() function, and refresh the page, I don’t get an error.
If I open a dashboard with multiple panels, some of which use the last() function, I don’t get an error. I can also refresh this page as many times as I like and there is no error.

If I switch to another tab for a while, as soon as I go back to the dashboard tab, I see this error in the logs.