Plugins: Introduce plugin package specific logger (#62204)

* refactor

* implement with infra log for now

* undo moving

* update package name

* update name

* fix tests

* update pretty signature

* update naming

* simplify

* fix typo

* delete comment

* fix import

* retrigger
This commit is contained in:
Will Browne
2023-02-28 16:10:27 +01:00
committed by GitHub
parent ab8de1a0e3
commit ec82719372
38 changed files with 259 additions and 140 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"path/filepath"
"github.com/grafana/grafana/pkg/infra/fs"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/util"
)
@@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -75,7 +75,7 @@ func TestFinder_getAbsPluginJSONPaths(t *testing.T) {
})
finder := &Finder{
log: log.New(),
log: log.NewTestLogger(),
}
paths, err := finder.getAbsPluginJSONPaths("test")
@@ -93,7 +93,7 @@ func TestFinder_getAbsPluginJSONPaths(t *testing.T) {
})
finder := &Finder{
log: log.New(),
log: log.NewTestLogger(),
}
paths, err := finder.getAbsPluginJSONPaths("test")
@@ -111,7 +111,7 @@ func TestFinder_getAbsPluginJSONPaths(t *testing.T) {
})
finder := &Finder{
log: log.New(),
log: log.NewTestLogger(),
}
paths, err := finder.getAbsPluginJSONPaths("test")
@@ -9,9 +9,9 @@ import (
"github.com/grafana/grafana-aws-sdk/pkg/awsds"
"github.com/grafana/grafana-azure-sdk-go/azsettings"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/config"
"github.com/grafana/grafana/pkg/plugins/log"
)
type Initializer struct {
@@ -7,10 +7,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/backendplugin"
"github.com/grafana/grafana/pkg/plugins/config"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
)
@@ -37,7 +37,7 @@ func TestInitializer_Initialize(t *testing.T) {
i := &Initializer{
cfg: &config.Cfg{},
log: log.NewNopLogger(),
log: log.NewTestLogger(),
backendProvider: &fakeBackendProvider{
plugin: p,
},
@@ -67,7 +67,7 @@ func TestInitializer_Initialize(t *testing.T) {
i := &Initializer{
cfg: &config.Cfg{},
log: log.NewNopLogger(),
log: log.NewTestLogger(),
backendProvider: &fakeBackendProvider{
plugin: p,
},
@@ -97,7 +97,7 @@ func TestInitializer_Initialize(t *testing.T) {
i := &Initializer{
cfg: &config.Cfg{},
log: log.NewNopLogger(),
log: log.NewTestLogger(),
backendProvider: &fakeBackendProvider{
plugin: p,
},
@@ -120,7 +120,7 @@ func TestInitializer_Initialize(t *testing.T) {
i := &Initializer{
cfg: &config.Cfg{},
log: log.NewNopLogger(),
log: log.NewTestLogger(),
backendProvider: &fakeBackendProvider{
plugin: p,
},
@@ -158,7 +158,7 @@ func TestInitializer_envVars(t *testing.T) {
},
},
license: licensing,
log: log.NewNopLogger(),
log: log.NewTestLogger(),
backendProvider: &fakeBackendProvider{
plugin: p,
},
+2 -3
View File
@@ -12,12 +12,11 @@ import (
"strings"
"github.com/grafana/grafana/pkg/infra/fs"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/infra/slugify"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/config"
"github.com/grafana/grafana/pkg/plugins/logger"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/plugins/manager/loader/assetpath"
"github.com/grafana/grafana/pkg/plugins/manager/loader/finder"
"github.com/grafana/grafana/pkg/plugins/manager/loader/initializer"
@@ -57,7 +56,7 @@ func ProvideService(cfg *config.Cfg, license plugins.Licensing, authorizer plugi
pluginRegistry registry.Service, backendProvider plugins.BackendFactoryProvider,
roleRegistry plugins.RoleRegistry, pluginsCDNService *pluginscdn.Service, assetPath *assetpath.Service) *Loader {
return New(cfg, license, authorizer, pluginRegistry, backendProvider, process.NewManager(pluginRegistry),
storage.FileSystem(logger.NewLogger("loader.fs"), cfg.PluginsPath), roleRegistry, pluginsCDNService, assetPath)
storage.FileSystem(log.NewPrettyLogger("loader.fs"), cfg.PluginsPath), roleRegistry, pluginsCDNService, assetPath)
}
func New(cfg *config.Cfg, license plugins.Licensing, authorizer plugins.PluginLoaderAuthorizer,
+2 -2
View File
@@ -15,9 +15,9 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/infra/log/logtest"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/config"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
"github.com/grafana/grafana/pkg/plugins/manager/loader/initializer"
"github.com/grafana/grafana/pkg/plugins/manager/signature"
@@ -570,7 +570,7 @@ func TestLoader_setDefaultNavURL(t *testing.T) {
},
}},
}
logger := &logtest.Fake{}
logger := log.NewTestLogger()
pluginWithDashboard.SetLogger(logger)
t.Run("Default nav URL is not set if dashboard UID field not is set", func(t *testing.T) {