Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undocumented dashboards/import API Call #44383

Closed
safaci2000 opened this issue Jan 24, 2022 · 8 comments
Closed

Undocumented dashboards/import API Call #44383

safaci2000 opened this issue Jan 24, 2022 · 8 comments
Labels
area/backend/api help wanted migrate/status-icebox Temporary label that can be deleted after 2022 Nov type/docs

Comments

@safaci2000
Copy link

I'm not sure if this qualifies as a bug or feature request but...

The API used by the frontend to import a dashboard is /api/dashboards/import which seems to be the only one that supports importing library panels. The documented API for doing so /api/dashboard/db/ does not support library panels.

It would be nice if we could get either the dashboard/db to support the library panels OR document /import as a valid endpoint to use.

Either approach is fine as long as it's documented accordingly.

@safaci2000 safaci2000 changed the title Undocumented API Call Undocumented dashboards/import API Call Jan 24, 2022
@papagian
Copy link
Contributor

Hi, regarding the missing documentation we plan to change the way we document the API. Therefore it's hard to prioritise it unless we get some help.
In case somebody would like to pick it up, I enclose an example request.

example request for importing dashboard with library panels
curl 'http://localhost:3000/api/dashboards/import' \
  -H 'content-type: application/json' \
  -H 'Cookie: grafana_session=<cookie>' \
  --data-raw '{
	"dashboard": {
		"annotations": {
			"list": [
				{
					"builtIn": 1,
					"datasource": "-- Grafana --",
					"enable": true,
					"hide": true,
					"iconColor": "rgba(0, 211, 255, 1)",
					"name": "Annotations & Alerts",
					"target": {
						"limit": 100,
						"matchAny": false,
						"tags": [],
						"type": "dashboard"
					},
					"type": "dashboard"
				}
			]
		},
		"editable": true,
		"fiscalYearStartMonth": 0,
		"graphTooltip": 0,
		"id": null,
		"links": [],
		"liveNow": false,
		"panels": [
			{
				"aliasColors": {},
				"bars": false,
				"dashLength": 10,
				"dashes": false,
				"datasource": {},
				"description": "",
				"fill": 1,
				"fillGradient": 0,
				"gridPos": {
					"h": 9,
					"w": 12,
					"x": 0,
					"y": 0
				},
				"hiddenSeries": false,
				"id": 2,
				"legend": {
					"avg": false,
					"current": false,
					"max": false,
					"min": false,
					"show": true,
					"total": false,
					"values": false
				},
				"libraryPanel": {
					"description": "",
					"meta": {
						"connectedDashboards": 1,
						"created": "2021-12-21T10:59:45+02:00",
						"createdBy": {
							"avatarUrl": "/avatar/21232f297a57a5a743894a0e4a801fc3",
							"id": 1,
							"name": "admin"
						},
						"folderName": "General",
						"folderUid": "",
						"updated": "2022-01-26T11:08:59+02:00",
						"updatedBy": {
							"avatarUrl": "/avatar/21232f297a57a5a743894a0e4a801fc3",
							"id": 1,
							"name": "admin"
						}
					},
					"name": "#28301",
					"type": "graph",
					"uid": "Dpjyu0o7k",
					"version": 2
				},
				"lines": true,
				"linewidth": 1,
				"nullPointMode": "null",
				"options": {
					"alertThreshold": true
				},
				"percentage": false,
				"pluginVersion": "8.4.0-pre",
				"pointradius": 2,
				"points": false,
				"renderer": "flot",
				"seriesOverrides": [],
				"spaceLength": 10,
				"stack": false,
				"steppedLine": false,
				"targets": [
					{
						"alias": "",
						"refId": "A",
						"scenarioId": "csv_metric_values",
						"stringInput": "1,20,90,30,5,0"
					}
				],
				"thresholds": [],
				"timeRegions": [],
				"title": "#28301",
				"tooltip": {
					"shared": true,
					"sort": 0,
					"value_type": "individual"
				},
				"type": "graph",
				"xaxis": {
					"mode": "time",
					"show": true,
					"values": []
				},
				"yaxes": [
					{
						"format": "short",
						"logBase": 1,
						"show": true
					},
					{
						"format": "short",
						"logBase": 1,
						"show": true
					}
				],
				"yaxis": {
					"align": false
				}
			}
		],
		"schemaVersion": 34,
		"style": "dark",
		"tags": [],
		"templating": {
			"list": []
		},
		"time": {
			"from": "now-6h",
			"to": "now"
		},
		"timepicker": {},
		"timezone": "",
		"title": "#44383 clone",
		"uid": "7-u-btxnb",
		"version": 1,
		"weekStart": ""
	},
	"overwrite": true,
	"inputs": [],
	"folderId": 0
}'

@safaci2000
Copy link
Author

If Grafana is re-working how the imports are being done that's fine. I understand that this isn't a big priority though I did want to point out the discrepancy.

I am trying to understand the recommended REST API to use though. Is it fair to say that /api/dashboards/import is likely the recommended end approach to use to import dashboards over /api/dashboard/db/ ?

I'd like to at least confirm I'm going down the right path as the documentation on said endpoint is missing.

@papagian
Copy link
Contributor

papagian commented Feb 7, 2022

If Grafana is re-working how the imports are being done that's fine. I understand that this isn't a big priority though I did want to point out the discrepancy.

sorry, I think my comment got misinterpreted. I was replying to OR document /import as a valid endpoint to use part that we work on formally specifying the HTTP API therefore updating these docs is not our priority.
I'm not aware of any planned changes to the imports.

Also what issues do you have with the /api/dashboard/db endpoint with the library panels? the following request seems to work for me:

Post dashboard with library panels example request
curl http://localhost:3000/api/dashboards/db/ \
-H 'Cookie: grafana_session=c15b304f14823291f1b54b8a7ab48822' \
-d '
{
	"dashboard": {
		"annotations": {
			"list": [
				{
					"builtIn": 1,
					"datasource": "-- Grafana --",
					"enable": true,
					"hide": true,
					"iconColor": "rgba(0, 211, 255, 1)",
					"name": "Annotations & Alerts",
					"target": {
						"limit": 100,
						"matchAny": false,
						"tags": [],
						"type": "dashboard"
					},
					"type": "dashboard"
				}
			]
		},
		"editable": true,
		"fiscalYearStartMonth": 0,
		"graphTooltip": 0,
		"links": [],
		"liveNow": false,
		"panels": [
			{
				"aliasColors": {},
				"bars": false,
				"dashLength": 10,
				"dashes": false,
				"datasource": {},
				"description": "",
				"fill": 1,
				"fillGradient": 0,
				"gridPos": {
					"h": 9,
					"w": 12,
					"x": 0,
					"y": 0
				},
				"hiddenSeries": false,
				"id": 2,
				"legend": {
					"avg": false,
					"current": false,
					"max": false,
					"min": false,
					"show": true,
					"total": false,
					"values": false
				},
				"libraryPanel": {
					"meta": {
						"connectedDashboards": 2,
						"created": "2021-12-21T10:59:45+02:00",
						"createdBy": {
							"avatarUrl": "/avatar/21232f297a57a5a743894a0e4a801fc3",
							"id": 1,
							"name": "admin"
						},
						"folderName": "General",
						"folderUid": "",
						"updated": "2022-01-26T11:08:59+02:00",
						"updatedBy": {
							"avatarUrl": "/avatar/21232f297a57a5a743894a0e4a801fc3",
							"id": 1,
							"name": "admin"
						}
					},
					"name": "#28301",
					"uid": "Dpjyu0o7k",
					"version": 2
				},
				"lines": true,
				"linewidth": 1,
				"nullPointMode": "null",
				"options": {
					"alertThreshold": true
				},
				"percentage": false,
				"pluginVersion": "8.5.0-pre",
				"pointradius": 2,
				"points": false,
				"renderer": "flot",
				"seriesOverrides": [],
				"spaceLength": 10,
				"stack": false,
				"steppedLine": false,
				"targets": [
					{
						"alias": "",
						"refId": "A",
						"scenarioId": "csv_metric_values",
						"stringInput": "1,20,90,30,5,0"
					}
				],
				"thresholds": [],
				"timeRegions": [],
				"title": "#28301",
				"tooltip": {
					"shared": true,
					"sort": 0,
					"value_type": "individual"
				},
				"type": "graph",
				"xaxis": {
					"mode": "time",
					"show": true,
					"values": []
				},
				"yaxes": [
					{
						"format": "short",
						"logBase": 1,
						"show": true
					},
					{
						"format": "short",
						"logBase": 1,
						"show": true
					}
				],
				"yaxis": {
					"align": false
				}
			}
		],
		"schemaVersion": 35,
		"style": "dark",
		"tags": [],
		"templating": {
			"list": []
		},
		"time": {
			"from": "now-6h",
			"to": "now"
		},
		"timepicker": {},
		"timezone": "",
		"title": "#44383 post dashboard",
		"version": 0,
		"weekStart": "",
		"id": null,
		"uid": "",
		"hideControls": false
	},
	"message": "",
	"overwrite": false,
	"folderId": 0
}'
{"id":1575,"slug":"44383-post-dashboard","status":"success","uid":"-YGI1ca7z","url":"/d/-YGI1ca7z/44383-post-dashboard","version":1}

I am trying to understand the recommended REST API to use though. Is it fair to say that /api/dashboards/import is likely the recommended end approach to use to import dashboards over /api/dashboard/db/ ?

I'd like to at least confirm I'm going down the right path as the documentation on said endpoint is missing.

I don't think that there is a recommended endpoint to use. The import one was designed to work together with the export one and supports also importing dashboards from other grafana instances by permitting to the user to select among the compatible datasources existing in the destination instance. Other than that the two endpoints should not differ a lot so it's up to the caller to pick the one that best suit to their needs.

@papagian papagian added the needs more info Issue needs more information, like query results, dashboard or panel json, grafana version etc label Feb 7, 2022
@safaci2000
Copy link
Author

@papagian I believe this ticket has more context: #44003. It's my understanding that the dashboard/db does not support importing third party panels. Last comment was:

We don't support importing using the dashboard post api so we'll close this issue and PR. We can always revisit this if more feedback is received from the community. Thank you 🙏

This was initialed from a user opening up a ticket in the dashboard management tool I wrote for grafana. My understanding from the user feedback is that:

  1. UI supports importing 3rd party panels.
  2. The /import endpoint does as well.
  3. the /dashboard/db does not.

My concern was using the /import over /dashboard/db was related to the fact that it seems like an undocumented API.

My request / questions:

A. Can you confirm that the 3 assertions above are correct?
B. If yes, I was looking for guidance for the how to support 3rd party panels? aka. suggestion to use /import, or wait for release X.X that will support it, etc.

@efekete
Copy link

efekete commented Feb 7, 2022

@papagian
yes, as the @safaci2000 explained, the problem appears when you are trying to export panels from one Grafana instance, and import it to another. If the Grafana does not already have the library panels, there will be missing link and error: "library panels not found". If those panels exist, everything would work as expected.

Here would be the fix/feature for /dashboard/db API to actually import those panels.

@papagian
Copy link
Contributor

If you want to share dashboards among different grafana instances then the endpoint to use is the /import one. This endpoint tries to create all the library panels that do not already exist in the new instance. If a library panel with the same UID already exists in the new instance then it will ignore it. This was implemented as part of this work. For more details please check the implementation there.

@papagian papagian removed the needs more info Issue needs more information, like query results, dashboard or panel json, grafana version etc label Feb 11, 2022
@efekete
Copy link

efekete commented Feb 12, 2022

Exactly, and that is how we came to this issue and request to document that /import API.

@chri2547
Copy link
Collaborator

Closing this issue because it's over a year old, in an unresourced area, and not likely to be worked on in the next year.

@chri2547 chri2547 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/backend/api help wanted migrate/status-icebox Temporary label that can be deleted after 2022 Nov type/docs
Projects
None yet
Development

No branches or pull requests

6 participants