mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Metrictank: fix bundled dashboard (#21209)
* update metrictank dashboard * Restored dashboard datasource variable, and improved error handling in the import api handler Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
parent
05d831df29
commit
104c2e3636
@ -244,7 +244,30 @@ func (hs *HTTPServer) PostDashboard(c *m.ReqContext, cmd m.SaveDashboardCommand)
|
|||||||
}
|
}
|
||||||
|
|
||||||
dashboard, err := dashboards.NewService().SaveDashboard(dashItem, allowUiUpdate)
|
dashboard, err := dashboards.NewService().SaveDashboard(dashItem, allowUiUpdate)
|
||||||
|
if err != nil {
|
||||||
|
return dashboardSaveErrorToApiResponse(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if hs.Cfg.EditorsCanAdmin && newDashboard {
|
||||||
|
inFolder := cmd.FolderId > 0
|
||||||
|
err := dashboards.MakeUserAdmin(hs.Bus, cmd.OrgId, cmd.UserId, dashboard.Id, !inFolder)
|
||||||
|
if err != nil {
|
||||||
|
hs.log.Error("Could not make user admin", "dashboard", dashboard.Title, "user", c.SignedInUser.UserId, "error", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.TimeRequest(metrics.MApiDashboardSave)
|
||||||
|
return JSON(200, util.DynMap{
|
||||||
|
"status": "success",
|
||||||
|
"slug": dashboard.Slug,
|
||||||
|
"version": dashboard.Version,
|
||||||
|
"id": dashboard.Id,
|
||||||
|
"uid": dashboard.Uid,
|
||||||
|
"url": dashboard.GetUrl(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func dashboardSaveErrorToApiResponse(err error) Response {
|
||||||
if err == m.ErrDashboardTitleEmpty ||
|
if err == m.ErrDashboardTitleEmpty ||
|
||||||
err == m.ErrDashboardWithSameNameAsFolder ||
|
err == m.ErrDashboardWithSameNameAsFolder ||
|
||||||
err == m.ErrDashboardFolderWithSameNameAsDashboard ||
|
err == m.ErrDashboardFolderWithSameNameAsDashboard ||
|
||||||
@ -267,13 +290,14 @@ func (hs *HTTPServer) PostDashboard(c *m.ReqContext, cmd m.SaveDashboardCommand)
|
|||||||
return Error(422, validationErr.Error(), nil)
|
return Error(422, validationErr.Error(), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
if err == m.ErrDashboardWithSameNameInFolderExists {
|
if err == m.ErrDashboardWithSameNameInFolderExists {
|
||||||
return JSON(412, util.DynMap{"status": "name-exists", "message": err.Error()})
|
return JSON(412, util.DynMap{"status": "name-exists", "message": err.Error()})
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == m.ErrDashboardVersionMismatch {
|
if err == m.ErrDashboardVersionMismatch {
|
||||||
return JSON(412, util.DynMap{"status": "version-mismatch", "message": err.Error()})
|
return JSON(412, util.DynMap{"status": "version-mismatch", "message": err.Error()})
|
||||||
}
|
}
|
||||||
|
|
||||||
if pluginErr, ok := err.(m.UpdatePluginDashboardError); ok {
|
if pluginErr, ok := err.(m.UpdatePluginDashboardError); ok {
|
||||||
message := "The dashboard belongs to plugin " + pluginErr.PluginId + "."
|
message := "The dashboard belongs to plugin " + pluginErr.PluginId + "."
|
||||||
// look up plugin name
|
// look up plugin name
|
||||||
@ -282,31 +306,14 @@ func (hs *HTTPServer) PostDashboard(c *m.ReqContext, cmd m.SaveDashboardCommand)
|
|||||||
}
|
}
|
||||||
return JSON(412, util.DynMap{"status": "plugin-dashboard", "message": message})
|
return JSON(412, util.DynMap{"status": "plugin-dashboard", "message": message})
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == m.ErrDashboardNotFound {
|
if err == m.ErrDashboardNotFound {
|
||||||
return JSON(404, util.DynMap{"status": "not-found", "message": err.Error()})
|
return JSON(404, util.DynMap{"status": "not-found", "message": err.Error()})
|
||||||
}
|
}
|
||||||
|
|
||||||
return Error(500, "Failed to save dashboard", err)
|
return Error(500, "Failed to save dashboard", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if hs.Cfg.EditorsCanAdmin && newDashboard {
|
|
||||||
inFolder := cmd.FolderId > 0
|
|
||||||
err := dashboards.MakeUserAdmin(hs.Bus, cmd.OrgId, cmd.UserId, dashboard.Id, !inFolder)
|
|
||||||
if err != nil {
|
|
||||||
hs.log.Error("Could not make user admin", "dashboard", dashboard.Title, "user", c.SignedInUser.UserId, "error", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c.TimeRequest(metrics.MApiDashboardSave)
|
|
||||||
return JSON(200, util.DynMap{
|
|
||||||
"status": "success",
|
|
||||||
"slug": dashboard.Slug,
|
|
||||||
"version": dashboard.Version,
|
|
||||||
"id": dashboard.Id,
|
|
||||||
"uid": dashboard.Uid,
|
|
||||||
"url": dashboard.GetUrl(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetHomeDashboard(c *m.ReqContext) Response {
|
func GetHomeDashboard(c *m.ReqContext) Response {
|
||||||
prefsQuery := m.GetPreferencesWithDefaultsQuery{User: c.SignedInUser}
|
prefsQuery := m.GetPreferencesWithDefaultsQuery{User: c.SignedInUser}
|
||||||
if err := bus.Dispatch(&prefsQuery); err != nil {
|
if err := bus.Dispatch(&prefsQuery); err != nil {
|
||||||
|
@ -179,7 +179,6 @@ func GetPluginMarkdown(c *m.ReqContext) Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ImportDashboard(c *m.ReqContext, apiCmd dtos.ImportDashboardCommand) Response {
|
func ImportDashboard(c *m.ReqContext, apiCmd dtos.ImportDashboardCommand) Response {
|
||||||
|
|
||||||
cmd := plugins.ImportDashboardCommand{
|
cmd := plugins.ImportDashboardCommand{
|
||||||
OrgId: c.OrgId,
|
OrgId: c.OrgId,
|
||||||
User: c.SignedInUser,
|
User: c.SignedInUser,
|
||||||
@ -192,7 +191,7 @@ func ImportDashboard(c *m.ReqContext, apiCmd dtos.ImportDashboardCommand) Respon
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := bus.Dispatch(&cmd); err != nil {
|
if err := bus.Dispatch(&cmd); err != nil {
|
||||||
return Error(500, "Failed to import dashboard", err)
|
return dashboardSaveErrorToApiResponse(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON(200, cmd.Result)
|
return JSON(200, cmd.Result)
|
||||||
|
@ -1,19 +1,12 @@
|
|||||||
{
|
{
|
||||||
"__inputs": [],
|
"__inputs": [
|
||||||
"__requires": [
|
|
||||||
{
|
{
|
||||||
"type": "grafana",
|
"name": "DS_NAME",
|
||||||
"id": "grafana",
|
"type": "datasource",
|
||||||
"name": "Grafana",
|
"pluginId": "graphite"
|
||||||
"version": "5.2.3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "panel",
|
|
||||||
"id": "graph",
|
|
||||||
"name": "Graph",
|
|
||||||
"version": "5.0.0"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
"annotations": {
|
"annotations": {
|
||||||
"list": [
|
"list": [
|
||||||
{
|
{
|
||||||
@ -31,11 +24,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"editable": true,
|
"editable": true,
|
||||||
"gnetId": 279,
|
|
||||||
"graphTooltip": 1,
|
"graphTooltip": 1,
|
||||||
"id": 21,
|
|
||||||
"iteration": 1547213827205,
|
|
||||||
"links": [],
|
|
||||||
"panels": [
|
"panels": [
|
||||||
{
|
{
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
@ -4788,6 +4777,5 @@
|
|||||||
},
|
},
|
||||||
"timezone": "utc",
|
"timezone": "utc",
|
||||||
"title": "Metrictank",
|
"title": "Metrictank",
|
||||||
"uid": "tQW3QShiz",
|
"uid": "tQW3QShiz"
|
||||||
"version": 5
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user