Merge pull request #9368 from thaJeztah/shim_logs
services/server, runtime/v2/shim: use structured log for plugin ID
This commit is contained in:
commit
5664c9a61a
@ -189,13 +189,13 @@ func Run(ctx context.Context, manager Manager, opts ...BinaryOpts) {
|
|||||||
|
|
||||||
ctx = log.WithLogger(ctx, log.G(ctx).WithField("runtime", manager.Name()))
|
ctx = log.WithLogger(ctx, log.G(ctx).WithField("runtime", manager.Name()))
|
||||||
|
|
||||||
if err := run(ctx, manager, "", config); err != nil {
|
if err := run(ctx, manager, config); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%s: %s", manager.Name(), err)
|
fmt.Fprintf(os.Stderr, "%s: %s", manager.Name(), err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(ctx context.Context, manager Manager, name string, config Config) error {
|
func run(ctx context.Context, manager Manager, config Config) error {
|
||||||
parseFlags()
|
parseFlags()
|
||||||
if versionFlag {
|
if versionFlag {
|
||||||
fmt.Printf("%s:\n", filepath.Base(os.Args[0]))
|
fmt.Printf("%s:\n", filepath.Base(os.Args[0]))
|
||||||
@ -318,8 +318,8 @@ func run(ctx context.Context, manager Manager, name string, config Config) error
|
|||||||
)
|
)
|
||||||
|
|
||||||
for _, p := range registry.Graph(func(*plugin.Registration) bool { return false }) {
|
for _, p := range registry.Graph(func(*plugin.Registration) bool { return false }) {
|
||||||
id := p.URI()
|
pID := p.URI()
|
||||||
log.G(ctx).WithField("type", p.Type).Infof("loading plugin %q...", id)
|
log.G(ctx).WithFields(log.Fields{"id": pID, "type": p.Type}).Info("loading plugin")
|
||||||
|
|
||||||
initContext := plugin.NewContext(
|
initContext := plugin.NewContext(
|
||||||
ctx,
|
ctx,
|
||||||
@ -353,14 +353,14 @@ func run(ctx context.Context, manager Manager, name string, config Config) error
|
|||||||
instance, err := result.Instance()
|
instance, err := result.Instance()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if plugin.IsSkipPlugin(err) {
|
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{"id": pID, "type": p.Type, "error": err}).Info("skip loading plugin")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to load plugin %s: %w", id, err)
|
return fmt.Errorf("failed to load plugin %s: %w", pID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if src, ok := instance.(TTRPCService); ok {
|
if src, ok := instance.(TTRPCService); ok {
|
||||||
log.G(ctx).WithField("id", id).Debug("registering ttrpc service")
|
log.G(ctx).WithField("id", pID).Debug("registering ttrpc service")
|
||||||
ttrpcServices = append(ttrpcServices, src)
|
ttrpcServices = append(ttrpcServices, src)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ func TestResolveImports(t *testing.T) {
|
|||||||
tempDir := t.TempDir()
|
tempDir := t.TempDir()
|
||||||
|
|
||||||
for _, filename := range []string{"config_1.toml", "config_2.toml", "test.toml"} {
|
for _, filename := range []string{"config_1.toml", "config_2.toml", "test.toml"} {
|
||||||
err := os.WriteFile(filepath.Join(tempDir, filename), []byte(""), 0600)
|
err := os.WriteFile(filepath.Join(tempDir, filename), []byte(""), 0o600)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ root = "/var/lib/containerd"
|
|||||||
tempDir := t.TempDir()
|
tempDir := t.TempDir()
|
||||||
|
|
||||||
path := filepath.Join(tempDir, "config.toml")
|
path := filepath.Join(tempDir, "config.toml")
|
||||||
err := os.WriteFile(path, []byte(data), 0600)
|
err := os.WriteFile(path, []byte(data), 0o600)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var out Config
|
var out Config
|
||||||
@ -147,10 +147,10 @@ disabled_plugins = ["io.containerd.v1.xyz"]
|
|||||||
|
|
||||||
tempDir := t.TempDir()
|
tempDir := t.TempDir()
|
||||||
|
|
||||||
err := os.WriteFile(filepath.Join(tempDir, "data1.toml"), []byte(data1), 0600)
|
err := os.WriteFile(filepath.Join(tempDir, "data1.toml"), []byte(data1), 0o600)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
err = os.WriteFile(filepath.Join(tempDir, "data2.toml"), []byte(data2), 0600)
|
err = os.WriteFile(filepath.Join(tempDir, "data2.toml"), []byte(data2), 0o600)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var out Config
|
var out Config
|
||||||
@ -175,10 +175,10 @@ imports = ["data1.toml", "data2.toml"]
|
|||||||
`
|
`
|
||||||
tempDir := t.TempDir()
|
tempDir := t.TempDir()
|
||||||
|
|
||||||
err := os.WriteFile(filepath.Join(tempDir, "data1.toml"), []byte(data1), 0600)
|
err := os.WriteFile(filepath.Join(tempDir, "data1.toml"), []byte(data1), 0o600)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
err = os.WriteFile(filepath.Join(tempDir, "data2.toml"), []byte(data2), 0600)
|
err = os.WriteFile(filepath.Join(tempDir, "data2.toml"), []byte(data2), 0o600)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var out Config
|
var out Config
|
||||||
@ -207,7 +207,7 @@ version = 2
|
|||||||
tempDir := t.TempDir()
|
tempDir := t.TempDir()
|
||||||
|
|
||||||
path := filepath.Join(tempDir, "config.toml")
|
path := filepath.Join(tempDir, "config.toml")
|
||||||
err := os.WriteFile(path, []byte(data), 0600)
|
err := os.WriteFile(path, []byte(data), 0o600)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var out Config
|
var out Config
|
||||||
@ -230,7 +230,7 @@ func TestDecodePluginInV1Config(t *testing.T) {
|
|||||||
`
|
`
|
||||||
|
|
||||||
path := filepath.Join(t.TempDir(), "config.toml")
|
path := filepath.Join(t.TempDir(), "config.toml")
|
||||||
err := os.WriteFile(path, []byte(data), 0600)
|
err := os.WriteFile(path, []byte(data), 0o600)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var out Config
|
var out Config
|
||||||
|
@ -81,16 +81,16 @@ func CreateTopLevelDirectories(config *srvconfig.Config) error {
|
|||||||
return errors.New("root and state must be different paths")
|
return errors.New("root and state must be different paths")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := sys.MkdirAllWithACL(config.Root, 0711); err != nil {
|
if err := sys.MkdirAllWithACL(config.Root, 0o711); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := sys.MkdirAllWithACL(config.State, 0711); err != nil {
|
if err := sys.MkdirAllWithACL(config.State, 0o711); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.TempDir != "" {
|
if config.TempDir != "" {
|
||||||
if err := sys.MkdirAllWithACL(config.TempDir, 0711); err != nil {
|
if err := sys.MkdirAllWithACL(config.TempDir, 0o711); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -247,7 +247,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
|
|||||||
|
|
||||||
for _, p := range loaded {
|
for _, p := range loaded {
|
||||||
id := p.URI()
|
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
|
var mustSucceed int32
|
||||||
|
|
||||||
initContext := plugin.NewContext(
|
initContext := plugin.NewContext(
|
||||||
@ -281,9 +281,9 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
|
|||||||
instance, err := result.Instance()
|
instance, err := result.Instance()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if plugin.IsSkipPlugin(err) {
|
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 {
|
} 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 {
|
if _, ok := required[id]; ok {
|
||||||
return nil, fmt.Errorf("load required plugin %s: %w", id, err)
|
return nil, fmt.Errorf("load required plugin %s: %w", id, err)
|
||||||
@ -341,12 +341,12 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
|
|||||||
// recordConfigDeprecations attempts to record use of any deprecated config field. Failures are logged and ignored.
|
// recordConfigDeprecations attempts to record use of any deprecated config field. Failures are logged and ignored.
|
||||||
func recordConfigDeprecations(ctx context.Context, config *srvconfig.Config, set *plugin.Set) {
|
func recordConfigDeprecations(ctx context.Context, config *srvconfig.Config, set *plugin.Set) {
|
||||||
// record any detected deprecations without blocking server startup
|
// record any detected deprecations without blocking server startup
|
||||||
plugin := set.Get(plugins.WarningPlugin, plugins.DeprecationsPlugin)
|
p := set.Get(plugins.WarningPlugin, plugins.DeprecationsPlugin)
|
||||||
if plugin == nil {
|
if p == nil {
|
||||||
log.G(ctx).Warn("failed to find warning service to record deprecations")
|
log.G(ctx).Warn("failed to find warning service to record deprecations")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
instance, err := plugin.Instance()
|
instance, err := p.Instance()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations")
|
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations")
|
||||||
return
|
return
|
||||||
@ -432,8 +432,7 @@ func (s *Server) Stop() {
|
|||||||
p := s.plugins[i]
|
p := s.plugins[i]
|
||||||
instance, err := p.Instance()
|
instance, err := p.Instance()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.L.WithError(err).WithField("id", p.Registration.URI()).
|
log.L.WithFields(log.Fields{"error": err, "id": p.Registration.URI()}).Error("could not get plugin instance")
|
||||||
Error("could not get plugin instance")
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
closer, ok := instance.(io.Closer)
|
closer, ok := instance.(io.Closer)
|
||||||
@ -441,8 +440,7 @@ func (s *Server) Stop() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := closer.Close(); err != nil {
|
if err := closer.Close(); err != nil {
|
||||||
log.L.WithError(err).WithField("id", p.Registration.URI()).
|
log.L.WithFields(log.Fields{"error": err, "id": p.Registration.URI()}).Error("failed to close plugin")
|
||||||
Error("failed to close plugin")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -523,7 +521,7 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]plugin.Regist
|
|||||||
if pp.Platform != "" {
|
if pp.Platform != "" {
|
||||||
p, err = platforms.Parse(pp.Platform)
|
p, err = platforms.Parse(pp.Platform)
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
p = platforms.DefaultSpec()
|
p = platforms.DefaultSpec()
|
||||||
|
Loading…
Reference in New Issue
Block a user