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
@@ -8,9 +8,9 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"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/log"
"github.com/grafana/grafana/pkg/plugins/repo"
"github.com/grafana/grafana/pkg/plugins/storage"
)
+2 -3
View File
@@ -4,10 +4,9 @@ import (
"context"
"fmt"
"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/logger"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/plugins/manager/loader"
"github.com/grafana/grafana/pkg/plugins/manager/registry"
"github.com/grafana/grafana/pkg/plugins/repo"
@@ -26,7 +25,7 @@ type PluginInstaller struct {
func ProvideInstaller(cfg *config.Cfg, pluginRegistry registry.Service, pluginLoader loader.Service,
pluginRepo repo.Service) *PluginInstaller {
return New(pluginRegistry, pluginLoader, pluginRepo, storage.FileSystem(logger.NewLogger("installer.fs"), cfg.PluginsPath))
return New(pluginRegistry, pluginLoader, pluginRepo, storage.FileSystem(log.NewPrettyLogger("installer.fs"), cfg.PluginsPath))
}
func New(pluginRegistry registry.Service, pluginLoader loader.Service, pluginRepo repo.Service,
+4 -3
View File
@@ -6,12 +6,13 @@ import (
"fmt"
"testing"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
"github.com/grafana/grafana/pkg/plugins/repo"
"github.com/grafana/grafana/pkg/plugins/storage"
"github.com/stretchr/testify/require"
)
const testPluginID = "test-plugin"
@@ -207,7 +208,7 @@ func createPlugin(t *testing.T, pluginID string, class plugins.Class, managed, b
Backend: backend,
},
}
p.SetLogger(log.NewNopLogger())
p.SetLogger(log.NewTestLogger())
p.RegisterClient(&fakes.FakePluginClient{
ID: pluginID,
Managed: managed,
+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) {
+1 -1
View File
@@ -6,9 +6,9 @@ import (
"sync"
"time"
"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/log"
"github.com/grafana/grafana/pkg/plugins/manager/registry"
)
+4 -3
View File
@@ -5,10 +5,11 @@ import (
"sync"
"testing"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/backendplugin"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/plugins/log"
)
func TestProcessManager_Start(t *testing.T) {
@@ -270,7 +271,7 @@ func createPlugin(t *testing.T, bp backendplugin.Plugin, cbs ...func(p *plugins.
},
}
p.SetLogger(log.NewNopLogger())
p.SetLogger(log.NewTestLogger())
p.RegisterClient(bp)
for _, cb := range cbs {
+1 -1
View File
@@ -23,8 +23,8 @@ import (
// nolint:staticcheck
"golang.org/x/crypto/openpgp/clearsign"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/setting"
)
@@ -6,8 +6,8 @@ import (
"strings"
"testing"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/setting"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -151,7 +151,7 @@ func TestCalculate(t *testing.T) {
})
setting.AppUrl = tc.appURL
sig, err := Calculate(log.NewNopLogger(), &plugins.Plugin{
sig, err := Calculate(log.NewTestLogger(), &plugins.Plugin{
JSONData: plugins.JSONData{
ID: "test-datasource",
Info: plugins.Info{
@@ -173,7 +173,7 @@ func TestCalculate(t *testing.T) {
})
runningWindows = true
sig, err := Calculate(log.NewNopLogger(), &plugins.Plugin{
sig, err := Calculate(log.NewTestLogger(), &plugins.Plugin{
JSONData: plugins.JSONData{
ID: "test-renderer",
Type: plugins.Renderer,
+1 -1
View File
@@ -1,8 +1,8 @@
package signature
import (
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/log"
)
type Validator struct {