Chore: Remove plugincontext.ErrPluginNotFound (#74997)

This commit is contained in:
Andres Martinez Gotor
2023-09-25 12:10:47 +02:00
committed by GitHub
parent 1714fa598c
commit ece94b1e01
9 changed files with 18 additions and 32 deletions

View File

@ -19,7 +19,6 @@ import (
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util" "github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/web" "github.com/grafana/grafana/pkg/web"
@ -814,10 +813,7 @@ func (hs *HTTPServer) CheckDatasourceHealth(c *contextmodel.ReqContext) response
func (hs *HTTPServer) checkDatasourceHealth(c *contextmodel.ReqContext, ds *datasources.DataSource) response.Response { func (hs *HTTPServer) checkDatasourceHealth(c *contextmodel.ReqContext, ds *datasources.DataSource) response.Response {
pCtx, err := hs.pluginContextProvider.GetWithDataSource(c.Req.Context(), ds.Type, c.SignedInUser, ds) pCtx, err := hs.pluginContextProvider.GetWithDataSource(c.Req.Context(), ds.Type, c.SignedInUser, ds)
if err != nil { if err != nil {
if errors.Is(err, plugincontext.ErrPluginNotFound) { return response.ErrOrFallback(http.StatusInternalServerError, "Unable to get plugin context", err)
return response.Error(http.StatusNotFound, "Unable to find datasource plugin", nil)
}
return response.Error(http.StatusInternalServerError, "Unable to get plugin context", err)
} }
req := &backend.CheckHealthRequest{ req := &backend.CheckHealthRequest{
PluginContext: pCtx, PluginContext: pCtx,

View File

@ -14,7 +14,6 @@ import (
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
"github.com/grafana/grafana/pkg/web" "github.com/grafana/grafana/pkg/web"
) )
@ -25,9 +24,6 @@ func (hs *HTTPServer) handleQueryMetricsError(err error) *response.NormalRespons
if errors.Is(err, datasources.ErrDataSourceNotFound) { if errors.Is(err, datasources.ErrDataSourceNotFound) {
return response.Error(http.StatusNotFound, "Data source not found", err) return response.Error(http.StatusNotFound, "Data source not found", err)
} }
if errors.Is(err, plugincontext.ErrPluginNotFound) {
return response.Error(http.StatusNotFound, "Plugin not found", err)
}
var secretsPlugin datasources.ErrDatasourceSecretsPluginUserFriendly var secretsPlugin datasources.ErrDatasourceSecretsPluginUserFriendly
if errors.As(err, &secretsPlugin) { if errors.As(err, &secretsPlugin) {

View File

@ -11,10 +11,10 @@ import (
"github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/middleware/requestmeta" "github.com/grafana/grafana/pkg/middleware/requestmeta"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/httpresponsesender" "github.com/grafana/grafana/pkg/plugins/httpresponsesender"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
"github.com/grafana/grafana/pkg/util/proxyutil" "github.com/grafana/grafana/pkg/util/proxyutil"
"github.com/grafana/grafana/pkg/web" "github.com/grafana/grafana/pkg/web"
) )
@ -29,7 +29,7 @@ func (hs *HTTPServer) CallResource(c *contextmodel.ReqContext) {
func (hs *HTTPServer) callPluginResource(c *contextmodel.ReqContext, pluginID string) { func (hs *HTTPServer) callPluginResource(c *contextmodel.ReqContext, pluginID string) {
pCtx, err := hs.pluginContextProvider.Get(c.Req.Context(), pluginID, c.SignedInUser, c.OrgID) pCtx, err := hs.pluginContextProvider.Get(c.Req.Context(), pluginID, c.SignedInUser, c.OrgID)
if err != nil { if err != nil {
if errors.Is(err, plugincontext.ErrPluginNotFound) { if errors.Is(err, plugins.ErrPluginNotRegistered) {
c.JsonApiErr(404, "Plugin not found", nil) c.JsonApiErr(404, "Plugin not found", nil)
return return
} }
@ -54,7 +54,7 @@ func (hs *HTTPServer) callPluginResource(c *contextmodel.ReqContext, pluginID st
func (hs *HTTPServer) callPluginResourceWithDataSource(c *contextmodel.ReqContext, pluginID string, ds *datasources.DataSource) { func (hs *HTTPServer) callPluginResourceWithDataSource(c *contextmodel.ReqContext, pluginID string, ds *datasources.DataSource) {
pCtx, err := hs.pluginContextProvider.GetWithDataSource(c.Req.Context(), pluginID, c.SignedInUser, ds) pCtx, err := hs.pluginContextProvider.GetWithDataSource(c.Req.Context(), pluginID, c.SignedInUser, ds)
if err != nil { if err != nil {
if errors.Is(err, plugincontext.ErrPluginNotFound) { if errors.Is(err, plugins.ErrPluginNotRegistered) {
c.JsonApiErr(404, "Plugin not found", nil) c.JsonApiErr(404, "Plugin not found", nil)
return return
} }

View File

@ -26,7 +26,6 @@ import (
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginaccesscontrol" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginaccesscontrol"
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings"
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
@ -394,10 +393,7 @@ func (hs *HTTPServer) CheckHealth(c *contextmodel.ReqContext) response.Response
pluginID := web.Params(c.Req)[":pluginId"] pluginID := web.Params(c.Req)[":pluginId"]
pCtx, err := hs.pluginContextProvider.Get(c.Req.Context(), pluginID, c.SignedInUser, c.OrgID) pCtx, err := hs.pluginContextProvider.Get(c.Req.Context(), pluginID, c.SignedInUser, c.OrgID)
if err != nil { if err != nil {
if errors.Is(err, plugincontext.ErrPluginNotFound) { return response.ErrOrFallback(http.StatusInternalServerError, "Failed to get plugin settings", err)
return response.Error(http.StatusNotFound, "Plugin not found", nil)
}
return response.Error(http.StatusInternalServerError, "Failed to get plugin settings", err)
} }
resp, err := hs.pluginClient.CheckHealth(c.Req.Context(), &backend.CheckHealthRequest{ resp, err := hs.pluginClient.CheckHealth(c.Req.Context(), &backend.CheckHealthRequest{
PluginContext: pCtx, PluginContext: pCtx,

View File

@ -15,8 +15,8 @@ import (
"github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/expr/mathexp" "github.com/grafana/grafana/pkg/expr/mathexp"
"github.com/grafana/grafana/pkg/expr/ml" "github.com/grafana/grafana/pkg/expr/ml"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/httpresponsesender" "github.com/grafana/grafana/pkg/plugins/httpresponsesender"
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
) )
var ( var (
@ -64,7 +64,7 @@ func (m *MLNode) Execute(ctx context.Context, now time.Time, _ mathexp.Vars, s *
// get the plugin configuration that will be used by client (auth, host, etc) // get the plugin configuration that will be used by client (auth, host, etc)
pCtx, err := s.pCtxProvider.Get(ctx, mlPluginID, m.request.User, m.request.OrgId) pCtx, err := s.pCtxProvider.Get(ctx, mlPluginID, m.request.User, m.request.OrgId)
if err != nil { if err != nil {
if errors.Is(err, plugincontext.ErrPluginNotFound) { if errors.Is(err, plugins.ErrPluginNotRegistered) {
return result, errMLPluginDoesNotExist return result, errMLPluginDoesNotExist
} }
return result, fmt.Errorf("failed to get plugin settings: %w", err) return result, fmt.Errorf("failed to get plugin settings: %w", err)

View File

@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/expr/ml" "github.com/grafana/grafana/pkg/expr/ml"
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext" "github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/services/user"
) )
@ -139,7 +139,7 @@ func TestMLNodeExecute(t *testing.T) {
cfg: nil, cfg: nil,
dataService: nil, dataService: nil,
pCtxProvider: &fakePluginContextProvider{ pCtxProvider: &fakePluginContextProvider{
errorResult: plugincontext.ErrPluginNotFound, errorResult: plugins.ErrPluginNotRegistered,
}, },
features: nil, features: nil,
pluginsClient: nil, pluginsClient: nil,

View File

@ -7,11 +7,11 @@ import (
"github.com/centrifugal/centrifuge" "github.com/centrifugal/centrifuge"
"github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/auth/identity"
"github.com/grafana/grafana/pkg/services/live/model" "github.com/grafana/grafana/pkg/services/live/model"
"github.com/grafana/grafana/pkg/services/live/orgchannel" "github.com/grafana/grafana/pkg/services/live/orgchannel"
"github.com/grafana/grafana/pkg/services/live/runstream" "github.com/grafana/grafana/pkg/services/live/runstream"
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
) )
//go:generate mockgen -destination=plugin_mock.go -package=features github.com/grafana/grafana/pkg/services/live/features PluginContextGetter //go:generate mockgen -destination=plugin_mock.go -package=features github.com/grafana/grafana/pkg/services/live/features PluginContextGetter
@ -66,7 +66,7 @@ type PluginPathRunner struct {
func (r *PluginPathRunner) OnSubscribe(ctx context.Context, user identity.Requester, e model.SubscribeEvent) (model.SubscribeReply, backend.SubscribeStreamStatus, error) { func (r *PluginPathRunner) OnSubscribe(ctx context.Context, user identity.Requester, e model.SubscribeEvent) (model.SubscribeReply, backend.SubscribeStreamStatus, error) {
pCtx, err := r.pluginContextGetter.GetPluginContext(ctx, user, r.pluginID, r.datasourceUID, false) pCtx, err := r.pluginContextGetter.GetPluginContext(ctx, user, r.pluginID, r.datasourceUID, false)
if err != nil { if err != nil {
if errors.Is(err, plugincontext.ErrPluginNotFound) { if errors.Is(err, plugins.ErrPluginNotRegistered) {
logger.Error("Plugin context not found", "path", r.path) logger.Error("Plugin context not found", "path", r.path)
return model.SubscribeReply{}, 0, centrifuge.ErrorInternal return model.SubscribeReply{}, 0, centrifuge.ErrorInternal
} }
@ -110,7 +110,7 @@ func (r *PluginPathRunner) OnSubscribe(ctx context.Context, user identity.Reques
func (r *PluginPathRunner) OnPublish(ctx context.Context, user identity.Requester, e model.PublishEvent) (model.PublishReply, backend.PublishStreamStatus, error) { func (r *PluginPathRunner) OnPublish(ctx context.Context, user identity.Requester, e model.PublishEvent) (model.PublishReply, backend.PublishStreamStatus, error) {
pCtx, err := r.pluginContextGetter.GetPluginContext(ctx, user, r.pluginID, r.datasourceUID, false) pCtx, err := r.pluginContextGetter.GetPluginContext(ctx, user, r.pluginID, r.datasourceUID, false)
if err != nil { if err != nil {
if errors.Is(err, plugincontext.ErrPluginNotFound) { if errors.Is(err, plugins.ErrPluginNotRegistered) {
logger.Error("Plugin context not found", "path", r.path) logger.Error("Plugin context not found", "path", r.path)
return model.PublishReply{}, 0, centrifuge.ErrorInternal return model.PublishReply{}, 0, centrifuge.ErrorInternal
} }

View File

@ -11,8 +11,8 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/auth/identity" "github.com/grafana/grafana/pkg/services/auth/identity"
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
) )
var ( var (
@ -185,7 +185,7 @@ func (s *Manager) watchStream(ctx context.Context, cancelFn func(), sr streamReq
dsUID := sr.PluginContext.DataSourceInstanceSettings.UID dsUID := sr.PluginContext.DataSourceInstanceSettings.UID
pCtx, err := s.pluginContextGetter.GetPluginContext(ctx, sr.user, sr.PluginContext.PluginID, dsUID, false) pCtx, err := s.pluginContextGetter.GetPluginContext(ctx, sr.user, sr.PluginContext.PluginID, dsUID, false)
if err != nil { if err != nil {
if errors.Is(err, plugincontext.ErrPluginNotFound) { if errors.Is(err, plugins.ErrPluginNotRegistered) {
logger.Debug("Datasource not found, stop stream", "channel", sr.Channel, "path", sr.Path) logger.Debug("Datasource not found, stop stream", "channel", sr.Channel, "path", sr.Path)
return return
} }
@ -286,7 +286,7 @@ func (s *Manager) runStream(ctx context.Context, cancelFn func(), sr streamReque
} }
newPluginCtx, err := s.pluginContextGetter.GetPluginContext(ctx, sr.user, pluginCtx.PluginID, datasourceUID, false) newPluginCtx, err := s.pluginContextGetter.GetPluginContext(ctx, sr.user, pluginCtx.PluginID, datasourceUID, false)
if err != nil { if err != nil {
if errors.Is(err, plugincontext.ErrPluginNotFound) { if errors.Is(err, plugins.ErrPluginNotRegistered) {
logger.Info("No plugin context found, stopping stream", "path", sr.Path) logger.Info("No plugin context found, stopping stream", "path", sr.Path)
return return
} }
@ -410,7 +410,7 @@ func (s *Manager) SubmitStream(ctx context.Context, user identity.Requester, cha
} }
newPluginCtx, err := s.pluginContextGetter.GetPluginContext(ctx, user, pCtx.PluginID, datasourceUID, false) newPluginCtx, err := s.pluginContextGetter.GetPluginContext(ctx, user, pCtx.PluginID, datasourceUID, false)
if err != nil { if err != nil {
if errors.Is(err, plugincontext.ErrPluginNotFound) { if errors.Is(err, plugins.ErrPluginNotRegistered) {
return nil, errDatasourceNotFound return nil, errDatasourceNotFound
} }
return nil, err return nil, err

View File

@ -29,8 +29,6 @@ const (
pluginSettingsCachePrefix = "plugin-setting-" pluginSettingsCachePrefix = "plugin-setting-"
) )
var ErrPluginNotFound = errors.New("plugin not found")
func ProvideService(cfg *setting.Cfg, cacheService *localcache.CacheService, pluginStore pluginstore.Store, func ProvideService(cfg *setting.Cfg, cacheService *localcache.CacheService, pluginStore pluginstore.Store,
dataSourceService datasources.DataSourceService, pluginSettingsService pluginsettings.Service, dataSourceService datasources.DataSourceService, pluginSettingsService pluginsettings.Service,
licensing plugins.Licensing, pCfg *config.Cfg) *Provider { licensing plugins.Licensing, pCfg *config.Cfg) *Provider {
@ -62,7 +60,7 @@ type Provider struct {
func (p *Provider) Get(ctx context.Context, pluginID string, user identity.Requester, orgID int64) (backend.PluginContext, error) { func (p *Provider) Get(ctx context.Context, pluginID string, user identity.Requester, orgID int64) (backend.PluginContext, error) {
plugin, exists := p.pluginStore.Plugin(ctx, pluginID) plugin, exists := p.pluginStore.Plugin(ctx, pluginID)
if !exists { if !exists {
return backend.PluginContext{}, ErrPluginNotFound return backend.PluginContext{}, plugins.ErrPluginNotRegistered
} }
pCtx := backend.PluginContext{ pCtx := backend.PluginContext{
@ -97,7 +95,7 @@ func (p *Provider) Get(ctx context.Context, pluginID string, user identity.Reque
func (p *Provider) GetWithDataSource(ctx context.Context, pluginID string, user identity.Requester, ds *datasources.DataSource) (backend.PluginContext, error) { func (p *Provider) GetWithDataSource(ctx context.Context, pluginID string, user identity.Requester, ds *datasources.DataSource) (backend.PluginContext, error) {
plugin, exists := p.pluginStore.Plugin(ctx, pluginID) plugin, exists := p.pluginStore.Plugin(ctx, pluginID)
if !exists { if !exists {
return backend.PluginContext{}, ErrPluginNotFound return backend.PluginContext{}, plugins.ErrPluginNotRegistered
} }
pCtx := backend.PluginContext{ pCtx := backend.PluginContext{