Add hclog adapter and gating to eventer (#1915)

This contains to related things:

1. An adapter allowing an hclog interface to take in information and send them to the eventer
2. A gate on the eventer, which is the analogue to the behavior prior to eventing where we'd ensure logs were not printed prior to the startup information. Without this, plugin logs using the hclog adapter will start showing up too early.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2022-03-16 17:25:34 -04:00
1 parent 7eb29261b2
commit e596daf34d
17 files changed
+879 -53

No files matched your search

+38 -25
View File
@@ -7,6 +7,7 @@ import (
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/config"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/observability/event"
host_plugin_assets "github.com/hashicorp/boundary/plugins/host"
kms_plugin_assets "github.com/hashicorp/boundary/plugins/kms"
external_host_plugins "github.com/hashicorp/boundary/sdk/plugins/host"
@@ -138,13 +139,49 @@ func (c *MigrateCommand) Run(args []string) (retCode int) {
}()
}
dialect := "postgres"
c.srv = base.NewServer(&base.Command{UI: c.UI})
if err := c.srv.SetupLogging(c.flagLogLevel, c.flagLogFormat, c.Config.LogLevel, c.Config.LogFormat); err != nil {
c.UI.Error(err.Error())
return base.CommandCliError
}
var serverName string
switch {
case c.Config.Controller == nil:
serverName = "boundary-database-migrate"
default:
if _, err := c.Config.Controller.InitNameIfEmpty(); err != nil {
c.UI.Error(err.Error())
return base.CommandCliError
}
serverName = c.Config.Controller.Name + "/boundary-database-migrate"
}
if err := c.srv.SetupEventing(
c.srv.Logger,
c.srv.StderrLock,
serverName,
base.WithEventerConfig(c.Config.Eventing)); err != nil {
c.UI.Error(err.Error())
return base.CommandCliError
}
pluginLogger, err := event.NewHclogLogger(c.Context, c.srv.Eventer)
if err != nil {
c.UI.Error(fmt.Sprintf("Error creating host catalog plugin logger: %v", err))
return base.CommandCliError
}
_, awsCleanup, err := external_host_plugins.CreateHostPlugin(
c.Context,
"aws",
external_host_plugins.WithPluginOptions(
pluginutil.WithPluginExecutionDirectory(c.Config.Plugins.ExecutionDir),
pluginutil.WithPluginsFilesystem(host_plugin_assets.HostPluginPrefix, host_plugin_assets.FileSystem()),
))
),
external_host_plugins.WithLogger(pluginLogger.Named("aws")),
)
if err != nil {
c.UI.Error(fmt.Errorf("Error creating dynamic host plugin: %w", err).Error())
c.UI.Warn(base.WrapAtLength(
@@ -176,30 +213,6 @@ plugins {
return base.CommandCliError
}
dialect := "postgres"
c.srv = base.NewServer(&base.Command{UI: c.UI})
if err := c.srv.SetupLogging(c.flagLogLevel, c.flagLogFormat, c.Config.LogLevel, c.Config.LogFormat); err != nil {
c.UI.Error(err.Error())
return base.CommandCliError
}
var serverName string
switch {
case c.Config.Controller == nil:
serverName = "boundary-database-migrate"
default:
if _, err := c.Config.Controller.InitNameIfEmpty(); err != nil {
c.UI.Error(err.Error())
return base.CommandCliError
}
serverName = c.Config.Controller.Name + "/boundary-database-migrate"
}
if err := c.srv.SetupEventing(c.srv.Logger, c.srv.StderrLock, serverName, base.WithEventerConfig(c.Config.Eventing)); err != nil {
c.UI.Error(err.Error())
return base.CommandCliError
}
// If mlockall(2) isn't supported, show a warning. We disable this in dev
// because it is quite scary to see when first using Boundary. We also disable
// this if the user has explicitly disabled mlock in configuration.