Live: stream resubmit on ds change, fix old ds settings in RunStream (#34130)
This commit is contained in:
+4
-4
@@ -265,10 +265,10 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
apiRoute.Group("/datasources", func(datasourceRoute routing.RouteRegister) {
|
||||
datasourceRoute.Get("/", routing.Wrap(hs.GetDataSources))
|
||||
datasourceRoute.Post("/", quota("data_source"), bind(models.AddDataSourceCommand{}), routing.Wrap(AddDataSource))
|
||||
datasourceRoute.Put("/:id", bind(models.UpdateDataSourceCommand{}), routing.Wrap(UpdateDataSource))
|
||||
datasourceRoute.Delete("/:id", routing.Wrap(DeleteDataSourceById))
|
||||
datasourceRoute.Delete("/uid/:uid", routing.Wrap(DeleteDataSourceByUID))
|
||||
datasourceRoute.Delete("/name/:name", routing.Wrap(DeleteDataSourceByName))
|
||||
datasourceRoute.Put("/:id", bind(models.UpdateDataSourceCommand{}), routing.Wrap(hs.UpdateDataSource))
|
||||
datasourceRoute.Delete("/:id", routing.Wrap(hs.DeleteDataSourceById))
|
||||
datasourceRoute.Delete("/uid/:uid", routing.Wrap(hs.DeleteDataSourceByUID))
|
||||
datasourceRoute.Delete("/name/:name", routing.Wrap(hs.DeleteDataSourceByName))
|
||||
datasourceRoute.Get("/:id", routing.Wrap(GetDataSourceById))
|
||||
datasourceRoute.Get("/uid/:uid", routing.Wrap(GetDataSourceByUID))
|
||||
datasourceRoute.Get("/name/:name", routing.Wrap(GetDataSourceByName))
|
||||
|
||||
+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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,13 @@ func TestDataSourcesProxy_userLoggedIn(t *testing.T) {
|
||||
|
||||
loggedInUserScenario(t, "Should be able to save a data source when calling DELETE on non-existing",
|
||||
"/api/datasources/name/12345", func(sc *scenarioContext) {
|
||||
sc.handlerFunc = DeleteDataSourceByName
|
||||
// handler func being tested
|
||||
hs := &HTTPServer{
|
||||
Bus: bus.GetBus(),
|
||||
Cfg: setting.NewCfg(),
|
||||
PluginManager: &fakePluginManager{},
|
||||
}
|
||||
sc.handlerFunc = hs.DeleteDataSourceByName
|
||||
sc.fakeReqWithParams("DELETE", sc.url, map[string]string{}).exec()
|
||||
assert.Equal(t, 404, sc.resp.Code)
|
||||
})
|
||||
|
||||
+2
-2
@@ -313,7 +313,7 @@ func (hs *HTTPServer) GetPluginAssets(c *models.ReqContext) {
|
||||
func (hs *HTTPServer) CheckHealth(c *models.ReqContext) response.Response {
|
||||
pluginID := c.Params("pluginId")
|
||||
|
||||
pCtx, found, err := hs.PluginContextProvider.Get(pluginID, "", c.SignedInUser)
|
||||
pCtx, found, err := hs.PluginContextProvider.Get(pluginID, "", c.SignedInUser, false)
|
||||
if err != nil {
|
||||
return response.Error(500, "Failed to get plugin settings", err)
|
||||
}
|
||||
@@ -355,7 +355,7 @@ func (hs *HTTPServer) CheckHealth(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) CallResource(c *models.ReqContext) {
|
||||
pluginID := c.Params("pluginId")
|
||||
|
||||
pCtx, found, err := hs.PluginContextProvider.Get(pluginID, "", c.SignedInUser)
|
||||
pCtx, found, err := hs.PluginContextProvider.Get(pluginID, "", c.SignedInUser, false)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Failed to get plugin settings", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user