Plugins: Add logs to for plugin management actions (#90587)

* Plugins: Add logs to for plugin management actions

---------

Co-authored-by: Giuseppe Guerra <giuseppe.guerra@grafana.com>
This commit is contained in:
Hugo Kiyodi Oshiro 2024-07-18 17:19:36 +02:00 committed by GitHub
parent 08c611c68b
commit 5c966fd400
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 0 deletions

View File

@ -456,6 +456,8 @@ func (hs *HTTPServer) InstallPlugin(c *contextmodel.ReqContext) response.Respons
}
pluginID := web.Params(c.Req)[":pluginId"]
hs.log.Info("Plugin install/update requested", "pluginId", pluginID, "user", c.Login)
compatOpts := plugins.NewCompatOpts(hs.Cfg.BuildVersion, runtime.GOOS, runtime.GOARCH)
err := hs.pluginInstaller.Add(c.Req.Context(), pluginID, dto.Version, compatOpts)
if err != nil {
@ -486,6 +488,9 @@ func (hs *HTTPServer) InstallPlugin(c *contextmodel.ReqContext) response.Respons
func (hs *HTTPServer) UninstallPlugin(c *contextmodel.ReqContext) response.Response {
pluginID := web.Params(c.Req)[":pluginId"]
hs.log.Info("Plugin uninstall requested", "pluginId", pluginID, "user", c.Login)
plugin, exists := hs.pluginStore.Plugin(c.Req.Context(), pluginID)
if !exists {
return response.Error(http.StatusNotFound, "Plugin not installed", nil)

View File

@ -109,6 +109,8 @@ func Test_PluginsInstallAndUninstall(t *testing.T) {
hs.authnService = &authntest.FakeService{
ExpectedIdentity: expectedIdentity,
}
hs.log = log.NewNopLogger()
})
t.Run(testName("Install", tc), func(t *testing.T) {

View File

@ -107,6 +107,8 @@ func (m *PluginInstaller) install(ctx context.Context, pluginID, version string,
return nil, err
}
m.log.Info("Updating plugin", "pluginId", pluginID, "from", plugin.Info.Version, "to", pluginArchiveInfo.Version)
// if existing plugin version is the same as the target update version
if pluginArchiveInfo.Version == plugin.Info.Version {
return nil, plugins.DuplicateError{
@ -141,6 +143,7 @@ func (m *PluginInstaller) install(ctx context.Context, pluginID, version string,
if err != nil {
return nil, err
}
m.log.Info("Installing plugin", "pluginId", pluginID, "version", version)
}
extractedArchive, err := m.pluginStorage.Extract(ctx, pluginID, m.pluginStorageDirFunc, pluginArchive.File)