Provisioning: Add API endpoint to reload provisioning configs (#16579)
* Add api to reaload provisioning * Refactor and simplify the polling code * Add test for the provisioning service * Fix provider initialization and move some code to file reader * Simplify the code and move initialization * Remove unused code * Update comment * Add comment * Change error messages * Add DashboardProvisionerFactory type * Update imports * Use new assert lib * Use mutext for synchronizing the reloading * Fix typo Co-Authored-By: aocenas <mr.ocenas@gmail.com> * Add docs about the new api
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
func (server *HTTPServer) AdminProvisioningReloadDasboards(c *models.ReqContext) Response {
|
||||
err := server.ProvisioningService.ProvisionDashboards()
|
||||
if err != nil && err != context.Canceled {
|
||||
return Error(500, "", err)
|
||||
}
|
||||
return Success("Dashboards config reloaded")
|
||||
}
|
||||
|
||||
func (server *HTTPServer) AdminProvisioningReloadDatasources(c *models.ReqContext) Response {
|
||||
err := server.ProvisioningService.ProvisionDatasources()
|
||||
if err != nil {
|
||||
return Error(500, "", err)
|
||||
}
|
||||
return Success("Datasources config reloaded")
|
||||
}
|
||||
|
||||
func (server *HTTPServer) AdminProvisioningReloadNotifications(c *models.ReqContext) Response {
|
||||
err := server.ProvisioningService.ProvisionNotifications()
|
||||
if err != nil {
|
||||
return Error(500, "", err)
|
||||
}
|
||||
return Success("Notifications config reloaded")
|
||||
}
|
||||
@@ -387,6 +387,10 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
adminRoute.Post("/users/:id/logout", Wrap(hs.AdminLogoutUser))
|
||||
adminRoute.Get("/users/:id/auth-tokens", Wrap(hs.AdminGetUserAuthTokens))
|
||||
adminRoute.Post("/users/:id/revoke-auth-token", bind(m.RevokeAuthTokenCmd{}), Wrap(hs.AdminRevokeUserAuthToken))
|
||||
|
||||
adminRoute.Post("/provisioning/dashboards/reload", Wrap(hs.AdminProvisioningReloadDasboards))
|
||||
adminRoute.Post("/provisioning/datasources/reload", Wrap(hs.AdminProvisioningReloadDatasources))
|
||||
adminRoute.Post("/provisioning/notifications/reload", Wrap(hs.AdminProvisioningReloadNotifications))
|
||||
}, reqGrafanaAdmin)
|
||||
|
||||
// rendering
|
||||
|
||||
+12
-10
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/cache"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/hooks"
|
||||
"github.com/grafana/grafana/pkg/services/provisioning"
|
||||
"github.com/grafana/grafana/pkg/services/quota"
|
||||
"github.com/grafana/grafana/pkg/services/rendering"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -48,16 +49,17 @@ type HTTPServer struct {
|
||||
streamManager *live.StreamManager
|
||||
httpSrv *http.Server
|
||||
|
||||
RouteRegister routing.RouteRegister `inject:""`
|
||||
Bus bus.Bus `inject:""`
|
||||
RenderService rendering.Service `inject:""`
|
||||
Cfg *setting.Cfg `inject:""`
|
||||
HooksService *hooks.HooksService `inject:""`
|
||||
CacheService *cache.CacheService `inject:""`
|
||||
DatasourceCache datasources.CacheService `inject:""`
|
||||
AuthTokenService models.UserTokenService `inject:""`
|
||||
QuotaService *quota.QuotaService `inject:""`
|
||||
RemoteCacheService *remotecache.RemoteCache `inject:""`
|
||||
RouteRegister routing.RouteRegister `inject:""`
|
||||
Bus bus.Bus `inject:""`
|
||||
RenderService rendering.Service `inject:""`
|
||||
Cfg *setting.Cfg `inject:""`
|
||||
HooksService *hooks.HooksService `inject:""`
|
||||
CacheService *cache.CacheService `inject:""`
|
||||
DatasourceCache datasources.CacheService `inject:""`
|
||||
AuthTokenService models.UserTokenService `inject:""`
|
||||
QuotaService *quota.QuotaService `inject:""`
|
||||
RemoteCacheService *remotecache.RemoteCache `inject:""`
|
||||
ProvisioningService provisioning.ProvisioningService `inject:""`
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) Init() error {
|
||||
|
||||
Reference in New Issue
Block a user