From be22e12d567ed4cb12bf052088b76479686761fc Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 15 Nov 2023 13:23:32 +0100 Subject: [PATCH] services/server: use structured log for plugin ID These logs were already using structured logs, so include "id" as a field, which also prevents the id being quoted (and escaped when printing); time="2023-11-15T11:30:23.745574884Z" level=info msg="loading plugin \"io.containerd.internal.v1.shutdown\"..." runtime=io.containerd.runc.v2 type=io.containerd.internal.v1 time="2023-11-15T11:30:23.745612425Z" level=info msg="loading plugin \"io.containerd.ttrpc.v1.pause\"..." runtime=io.containerd.runc.v2 type=io.containerd.ttrpc.v1 time="2023-11-15T11:30:23.745620884Z" level=info msg="loading plugin \"io.containerd.event.v1.publisher\"..." runtime=io.containerd.runc.v2 type=io.containerd.event.v1 time="2023-11-15T11:30:23.745625925Z" level=info msg="loading plugin \"io.containerd.ttrpc.v1.task\"..." runtime=io.containerd.runc.v2 type=io.containerd.ttrpc.v1 Also updated some changed `WithError().WithField()` calls, to prevent some overhead. Signed-off-by: Sebastiaan van Stijn --- services/server/server.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/services/server/server.go b/services/server/server.go index fb6a3bbb0..c2258b4cd 100644 --- a/services/server/server.go +++ b/services/server/server.go @@ -247,7 +247,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) { for _, p := range loaded { id := p.URI() - log.G(ctx).WithField("type", p.Type).Infof("loading plugin %q...", id) + log.G(ctx).WithFields(log.Fields{"id": id, "type": p.Type}).Info("loading plugin") var mustSucceed int32 initContext := plugin.NewContext( @@ -281,9 +281,9 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) { instance, err := result.Instance() if err != nil { if plugin.IsSkipPlugin(err) { - log.G(ctx).WithError(err).WithField("type", p.Type).Infof("skip loading plugin %q...", id) + log.G(ctx).WithFields(log.Fields{"error": err, "id": id, "type": p.Type}).Info("skip loading plugin") } else { - log.G(ctx).WithError(err).Warnf("failed to load plugin %s", id) + log.G(ctx).WithFields(log.Fields{"error": err, "id": id, "type": p.Type}).Warn("failed to load plugin") } if _, ok := required[id]; ok { return nil, fmt.Errorf("load required plugin %s: %w", id, err) @@ -432,8 +432,7 @@ func (s *Server) Stop() { p := s.plugins[i] instance, err := p.Instance() if err != nil { - log.L.WithError(err).WithField("id", p.Registration.URI()). - Error("could not get plugin instance") + log.L.WithFields(log.Fields{"error": err, "id": p.Registration.URI()}).Error("could not get plugin instance") continue } closer, ok := instance.(io.Closer) @@ -441,8 +440,7 @@ func (s *Server) Stop() { continue } if err := closer.Close(); err != nil { - log.L.WithError(err).WithField("id", p.Registration.URI()). - Error("failed to close plugin") + log.L.WithFields(log.Fields{"error": err, "id": p.Registration.URI()}).Error("failed to close plugin") } } } @@ -523,7 +521,7 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]plugin.Regist if pp.Platform != "" { p, err = platforms.Parse(pp.Platform) if err != nil { - log.G(ctx).WithError(err).WithField("plugin", name).Warn("skipping proxy platform with bad platform") + log.G(ctx).WithFields(log.Fields{"error": err, "plugin": name}).Warn("skipping proxy platform with bad platform") } } else { p = platforms.DefaultSpec()