grafana / grafana

The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
https://grafana.com
GNU Affero General Public License v3.0
65.35k stars 12.19k forks source link

Invalid dashboard UID in the request error on custom home dashboard #54574

Open piotrp opened 2 years ago

piotrp commented 2 years ago

What happened:

I set custom home dashboard using default_home_dashboard_path, now when entering Grafana I see an error in UI: "Invalid dashboard UID in the request" obraz

What you expected to happen:

No error

How to reproduce it (as minimally and precisely as possible):

docker-compose.yml

version: '3.8'
services:
  grafana:
    image: grafana/grafana:9.1.2
    volumes:
      - ./Home.json:/tmp/Home.json
    ports:
      - "3000:3000"
    environment:
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/tmp/Home.json

Home.json - empty dashboard from the same Grafana version, with Annotations & Alerts removed for simplicity (the same happens when I leave it)

{
  "annotations": {
    "list": []
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": 1,
  "links": [],
  "liveNow": false,
  "panels": [],
  "schemaVersion": 37,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "Custom Home",
  "uid": "JqqE7eWVk",
  "version": 2,
  "weekStart": ""
}

Environment:

threechord82 commented 2 years ago

Same error here. If I pass the board already as a variable I get the error message. If I import the board manually I get no message. Since we deploy Grafana automatically it would be good if the board could be set automatically.

yangkb09 commented 2 years ago

Hi @piotrp! Are you using the absolute path when setting your custom home dashboard using default_home_dashboard_path? And do you have any organization dashboard preferences for the home dashboard set already?

piotrp commented 2 years ago

I'm using absolute path:

[dashboards]
default_home_dashboard_path = /var/lib/grafana/home.json

There are no such preferences set. You can verify all of this by checking out reproduction steps above, which use official Docker image.

yangkb09 commented 2 years ago

Hi @piotrp, I was able to reproduce what you're seeing - thanks for the well written reproduction!

The problem is that the dashboard must exist before you can configure it as the home dashboard; Grafana does not automatically create that dashboard.

You can either configure Grafana to provision the dashboard from that same json file, or create the dashboard in the UI. The documentation for provisioning dashboards from files can be found here.

This wasn't clear from the documentation, so I've re-labeled this as a docs issue. Thanks!

piotrp commented 2 years ago

Then isn't this also a design issue of this functionality? If this dashboard must be already existing, then configuration should only point to dashboard's UID, not file path. Or in other words, default_home_dashboard_path should be deprecated and a new default_home_dashboard_uid should be introduced, because current method of setting default home dashboard makes little sense.

ggear commented 2 years ago

I agree, and given this is the first time I have seen this issue with version 9.1.2 I would consider it a regression.

leodking commented 1 year ago

I have the same issue. From my tests this issue happens when I spin up a Grafana server on version 9.1.0. Whereas 9.0.9 and earlier is fine.

Error is: "Invalid dashboard UID in the request"

jacksongoode commented 1 year ago

Is there a resolution to this? We provision the custom home page with GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH.

jphx commented 1 year ago

I fixed this in our setup just yesterday. According to my investigation, the error message is coming from a failed annotations query, the "built-in" query that is normally done for all dashboards. But it can be disabled for a dashboard.

Our home dashboard json had this section near the top:

      "annotations": {
        "list": [
          {
            "builtIn": 1,
            "datasource": {
              "type": "grafana",
              "uid": "-- Grafana --"
            },
            "enable": true,
            "hide": true,
            "iconColor": "rgba(0, 211, 255, 1)",
            "name": "Annotations & Alerts",
            "target": {
              "limit": 100,
              "matchAny": false,
              "tags": [],
              "type": "dashboard"
            },
            "type": "dashboard"
          }
        ]
      },

All I did was to change enable to false and the built-in query is suppressed. The error message no longer appears.

Thrinadh-Kumpatla commented 1 year ago
        "annotations": {
          "list": [
            {
              "builtIn": 1,
              "datasource": {
                "type": "datasource",
                "uid": "grafana"
              },
              "enable": true,
              "hide": true,
              "iconColor": "rgba(0, 211, 255, 1)",
              "limit": 100,
              "name": "Annotations & Alerts",
              "showIn": 0,
              "target": {
                "limit": 100,
                "matchAny": false,
                "tags": [],
                "type": "dashboard"
              },
              "type": "dashboard"

I removed the line "showIn": 0, and I'm not seeing error anymore

activedecay commented 1 year ago

The problem is that the dashboard must exist before you can configure it as the home dashboard; Grafana does not automatically create that dashboard.

To which dashboard are you referring? The error message now says "Invalid dashboard UID in annotation request" which changed every so slightly from the original description.

The workaround steps are the same; just add "enable": false to the dashboard JSON and the error goes away.

It seems like changing the Home dashboard during creation of the default/empty/clean Grafana image is not supported. Is there a clean way to change the landing page (home dashboard) from a clean installation of the docker image? My Grafana version is 9.4.3 (Edit: The goal would be to create a new grafana docker instance and configure the home dashboard using some dashboard JSON as input. I guess you'd have to POST a dashboard API hit to create a dashboard? And from there configured it somehow?)

darks00ul commented 1 year ago

EDIT 1: I didn't verify if this behavior also happen with a dashboard exported from General Folder... If I probe this I will update this post to clarify this..

Hi everyone, I was having this same issue and I find out that this happened to me under the following circumstances:

environment:
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/tmp/home.json

But i didn't configure the provisioning needed in order to recreate the folder name from my older Grafana instance from where I exported the dashboard "home.json"

So I fix this as soon I configured the provisioning information, using a volume pointing to /etc/grafana/provisioning with the dashboard provisioning information like this:

apiVersion: 1

providers:
- name: Prometheus
  orgId: 1
  folder: 'myfolder'
  folderUid: 'myfolder'
  type: file
  options:
    path: /var/lib/grafana/dashboards

Hope this helps

andoks commented 1 year ago

If I am reading dashboard.go:561 and the call-tree of that function right, Grafana should not need the same dashboard definition to be provisioned as a dashboard in addition to be specified using the default_home_dashboard_path configuration parameter, as it reads the file specified, and returns it.

After doing some spelunking - assuming I am in the right place at all in the code - it should be possible to add a config for UID similarly as how it is done for user preferences (dashboard.go:537 and preferences.go:35)

I however found that setting home_page in the "users" setting instead (from settings.go:1700) covers my use-case, as I can just set the relative path to the desired dashboard here, and everything works as I need it to.

raffaeler commented 1 month ago

A possible cause for this error is when the dashboard path contains a folder starting with a dot character (.).