Live: stream resubmit on ds change, fix old ds settings in RunStream (#34130)
This commit is contained in:
+17
-8
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana/pkg/api/datasource"
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
@@ -15,6 +14,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins/adapters"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
)
|
||||
|
||||
var datasourcesLogger = log.New("datasources")
|
||||
@@ -83,7 +84,7 @@ func GetDataSourceById(c *models.ReqContext) response.Response {
|
||||
return response.JSON(200, &dtos)
|
||||
}
|
||||
|
||||
func DeleteDataSourceById(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) DeleteDataSourceById(c *models.ReqContext) response.Response {
|
||||
id := c.ParamsInt64(":id")
|
||||
|
||||
if id <= 0 {
|
||||
@@ -109,6 +110,8 @@ func DeleteDataSourceById(c *models.ReqContext) response.Response {
|
||||
return response.Error(500, "Failed to delete datasource", err)
|
||||
}
|
||||
|
||||
hs.Live.HandleDatasourceDelete(c.OrgId, ds.Uid)
|
||||
|
||||
return response.Success("Data source deleted")
|
||||
}
|
||||
|
||||
@@ -128,7 +131,7 @@ func GetDataSourceByUID(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
// DELETE /api/datasources/uid/:uid
|
||||
func DeleteDataSourceByUID(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) DeleteDataSourceByUID(c *models.ReqContext) response.Response {
|
||||
uid := c.Params(":uid")
|
||||
|
||||
if uid == "" {
|
||||
@@ -154,10 +157,12 @@ func DeleteDataSourceByUID(c *models.ReqContext) response.Response {
|
||||
return response.Error(500, "Failed to delete datasource", err)
|
||||
}
|
||||
|
||||
hs.Live.HandleDatasourceDelete(c.OrgId, ds.Uid)
|
||||
|
||||
return response.Success("Data source deleted")
|
||||
}
|
||||
|
||||
func DeleteDataSourceByName(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) DeleteDataSourceByName(c *models.ReqContext) response.Response {
|
||||
name := c.Params(":name")
|
||||
|
||||
if name == "" {
|
||||
@@ -182,6 +187,8 @@ func DeleteDataSourceByName(c *models.ReqContext) response.Response {
|
||||
return response.Error(500, "Failed to delete datasource", err)
|
||||
}
|
||||
|
||||
hs.Live.HandleDatasourceDelete(c.OrgId, getCmd.Result.Uid)
|
||||
|
||||
return response.JSON(200, util.DynMap{
|
||||
"message": "Data source deleted",
|
||||
"id": getCmd.Result.Id,
|
||||
@@ -224,7 +231,7 @@ func AddDataSource(c *models.ReqContext, cmd models.AddDataSourceCommand) respon
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateDataSource(c *models.ReqContext, cmd models.UpdateDataSourceCommand) response.Response {
|
||||
func (hs *HTTPServer) UpdateDataSource(c *models.ReqContext, cmd models.UpdateDataSourceCommand) response.Response {
|
||||
datasourcesLogger.Debug("Received command to update data source", "url", cmd.Url)
|
||||
cmd.OrgId = c.OrgId
|
||||
cmd.Id = c.ParamsInt64(":id")
|
||||
@@ -254,16 +261,18 @@ func UpdateDataSource(c *models.ReqContext, cmd models.UpdateDataSourceCommand)
|
||||
if errors.Is(err, models.ErrDataSourceNotFound) {
|
||||
return response.Error(404, "Data source not found", nil)
|
||||
}
|
||||
return response.Error(500, "Failed to query datasources", err)
|
||||
return response.Error(500, "Failed to query datasource", err)
|
||||
}
|
||||
|
||||
dtos := convertModelToDtos(query.Result)
|
||||
datasourceDTO := convertModelToDtos(query.Result)
|
||||
|
||||
hs.Live.HandleDatasourceUpdate(c.OrgId, datasourceDTO.UID)
|
||||
|
||||
return response.JSON(200, util.DynMap{
|
||||
"message": "Datasource updated",
|
||||
"id": cmd.Id,
|
||||
"name": cmd.Name,
|
||||
"datasource": dtos,
|
||||
"datasource": datasourceDTO,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user