Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded hclog dependencies as we move forward with events #1433

Merged
merged 3 commits into from Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion internal/auth/additional_verification_test.go
Expand Up @@ -88,7 +88,6 @@ func TestFetchActionSetForId(t *testing.T) {
req := require.New(t)
ctx := auth.NewVerifierContext(
context.Background(),
tc.Logger(),
iamRepoFn,
authTokenRepoFn,
serversRepoFn,
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/base/dev.go
Expand Up @@ -332,7 +332,7 @@ func (b *Server) createInitialOidcAuthMethod(ctx context.Context) (*oidc.AuthMet
if err != nil {
return nil, fmt.Errorf("error creating kms repository: %w", err)
}
kmsCache, err := kms.NewKms(kmsRepo, kms.WithLogger(b.Logger.Named("kms")))
kmsCache, err := kms.NewKms(kmsRepo)
if err != nil {
return nil, fmt.Errorf("error creating kms cache: %w", err)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/base/initial_resources.go
Expand Up @@ -23,7 +23,7 @@ func (b *Server) CreateInitialLoginRole(ctx context.Context) (*iam.Role, error)
if err != nil {
return nil, fmt.Errorf("error creating kms repository: %w", err)
}
kmsCache, err := kms.NewKms(kmsRepo, kms.WithLogger(b.Logger.Named("kms")))
kmsCache, err := kms.NewKms(kmsRepo)
if err != nil {
return nil, fmt.Errorf("error creating kms cache: %w", err)
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func (b *Server) CreateInitialPasswordAuthMethod(ctx context.Context) (*password
if err != nil {
return nil, nil, fmt.Errorf("error creating kms repository: %w", err)
}
kmsCache, err := kms.NewKms(kmsRepo, kms.WithLogger(b.Logger.Named("kms")))
kmsCache, err := kms.NewKms(kmsRepo)
if err != nil {
return nil, nil, fmt.Errorf("error creating kms cache: %w", err)
}
Expand Down Expand Up @@ -278,7 +278,7 @@ func (b *Server) CreateInitialScopes(ctx context.Context) (*iam.Scope, *iam.Scop
if err != nil {
return nil, nil, fmt.Errorf("error creating kms repository: %w", err)
}
kmsCache, err := kms.NewKms(kmsRepo, kms.WithLogger(b.Logger.Named("kms")))
kmsCache, err := kms.NewKms(kmsRepo)
if err != nil {
return nil, nil, fmt.Errorf("error creating kms cache: %w", err)
}
Expand Down Expand Up @@ -358,7 +358,7 @@ func (b *Server) CreateInitialHostResources(ctx context.Context) (*static.HostCa
if err != nil {
return nil, nil, nil, fmt.Errorf("error creating kms repository: %w", err)
}
kmsCache, err := kms.NewKms(kmsRepo, kms.WithLogger(b.Logger.Named("kms")))
kmsCache, err := kms.NewKms(kmsRepo)
if err != nil {
return nil, nil, nil, fmt.Errorf("error creating kms cache: %w", err)
}
Expand Down Expand Up @@ -468,7 +468,7 @@ func (b *Server) CreateInitialTarget(ctx context.Context) (target.Target, error)
if err != nil {
return nil, fmt.Errorf("error creating kms repository: %w", err)
}
kmsCache, err := kms.NewKms(kmsRepo, kms.WithLogger(b.Logger.Named("kms")))
kmsCache, err := kms.NewKms(kmsRepo)
if err != nil {
return nil, fmt.Errorf("error creating kms cache: %w", err)
}
Expand Down
17 changes: 6 additions & 11 deletions internal/cmd/base/listener.go
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net"
"net/http"
"os"
"strings"
"time"

Expand All @@ -14,7 +13,6 @@ import (
_ "crypto/sha512"

"github.com/hashicorp/boundary/internal/libs/alpnmux"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-secure-stdlib/listenerutil"
"github.com/hashicorp/go-secure-stdlib/reloadutil"
"github.com/mitchellh/cli"
Expand All @@ -39,7 +37,7 @@ type WorkerAuthInfo struct {
}

// Factory is the factory function to create a listener.
type ListenerFactory func(string, *listenerutil.ListenerConfig, hclog.Logger, cli.Ui) (string, net.Listener, error)
type ListenerFactory func(string, *listenerutil.ListenerConfig, cli.Ui) (string, net.Listener, error)

// BuiltinListeners is the list of built-in listener types.
var BuiltinListeners = map[string]ListenerFactory{
Expand All @@ -49,7 +47,7 @@ var BuiltinListeners = map[string]ListenerFactory{

// New creates a new listener of the given type with the given
// configuration. The type is looked up in the BuiltinListeners map.
func NewListener(l *listenerutil.ListenerConfig, logger hclog.Logger, ui cli.Ui) (*alpnmux.ALPNMux, map[string]string, reloadutil.ReloadFunc, error) {
func NewListener(l *listenerutil.ListenerConfig, ui cli.Ui) (*alpnmux.ALPNMux, map[string]string, reloadutil.ReloadFunc, error) {
f, ok := BuiltinListeners[l.Type]
if !ok {
return nil, nil, nil, fmt.Errorf("unknown listener type: %q", l.Type)
Expand All @@ -69,7 +67,7 @@ func NewListener(l *listenerutil.ListenerConfig, logger hclog.Logger, ui cli.Ui)
l.TLSDisable = true
}

finalAddr, ln, err := f(purpose, l, logger, ui)
finalAddr, ln, err := f(purpose, l, ui)
if err != nil {
return nil, nil, nil, err
}
Expand All @@ -83,10 +81,7 @@ func NewListener(l *listenerutil.ListenerConfig, logger hclog.Logger, ui cli.Ui)
"addr": finalAddr,
}

if _, ok := os.LookupEnv("BOUNDARY_LOG_CONNECTION_MUXING"); !ok {
logger = nil
}
alpnMux := alpnmux.New(ln, logger)
alpnMux := alpnmux.New(ln)

if l.TLSDisable {
return alpnMux, props, nil, nil
Expand Down Expand Up @@ -115,7 +110,7 @@ func NewListener(l *listenerutil.ListenerConfig, logger hclog.Logger, ui cli.Ui)
return alpnMux, props, reloadFunc, nil
}

func tcpListenerFactory(purpose string, l *listenerutil.ListenerConfig, logger hclog.Logger, ui cli.Ui) (string, net.Listener, error) {
func tcpListenerFactory(purpose string, l *listenerutil.ListenerConfig, ui cli.Ui) (string, net.Listener, error) {
if l.Address == "" {
switch purpose {
case "cluster":
Expand Down Expand Up @@ -180,7 +175,7 @@ func tcpListenerFactory(purpose string, l *listenerutil.ListenerConfig, logger h
return finalListenAddr, ln, nil
}

func unixListenerFactory(purpose string, l *listenerutil.ListenerConfig, logger hclog.Logger, ui cli.Ui) (string, net.Listener, error) {
func unixListenerFactory(purpose string, l *listenerutil.ListenerConfig, ui cli.Ui) (string, net.Listener, error) {
var uConfig *listenerutil.UnixSocketsConfig
if l.SocketMode != "" &&
l.SocketUser != "" &&
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/base/profiling_off.go
Expand Up @@ -2,7 +2,7 @@

package base

import "github.com/hashicorp/go-hclog"
import "context"

func StartMemProfiler(_ hclog.Logger) {
func StartMemProfiler(_ context.Context) {
}
13 changes: 6 additions & 7 deletions internal/cmd/base/profiling_on.go
Expand Up @@ -8,14 +8,13 @@ import (
"runtime"
"runtime/pprof"
"time"

"github.com/hashicorp/go-hclog"
)

func StartMemProfiler(logger hclog.Logger) {
func StartMemProfiler(ctx context.Context) {
const op = "base.StartMemProfiler"
profileDir := filepath.Join(os.TempDir(), "boundaryprof")
if err := os.MkdirAll(profileDir, 0o700); err != nil {
logger.Debug("could not create profile directory", "error", err)
event.WriteError(ctx, op, err,"could not create profile directory")
return
}

Expand All @@ -24,14 +23,14 @@ func StartMemProfiler(logger hclog.Logger) {
filename := filepath.Join(profileDir, time.Now().UTC().Format("20060102_150405")) + ".pprof"
f, err := os.Create(filename)
if err != nil {
logger.Debug("could not create memory profile", "error", err)
event.WriteError(ctx, op, err, event.WithInfo("could not create memory profile"))
}
runtime.GC()
if err := pprof.WriteHeapProfile(f); err != nil {
logger.Debug("could not write memory profile", "error", err)
event.WriteError(ctx, op, err, "could not write memory profile"))
}
f.Close()
logger.Debug("wrote memory profile", "filename", filename)
event.WriteSysEvent(ctx, op, "wrote memory profile", "filename", filename)
time.Sleep(5 * time.Minute)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/base/servers.go
Expand Up @@ -395,7 +395,7 @@ func (b *Server) SetupListeners(ui cli.Ui, config *configutil.SharedConfig, allo
}
}

lnMux, props, reloadFunc, err := NewListener(lnConfig, b.Logger, ui)
lnMux, props, reloadFunc, err := NewListener(lnConfig, ui)
if err != nil {
return fmt.Errorf("Error initializing listener of type %s: %w", lnConfig.Type, err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/commands/dev/dev.go
Expand Up @@ -499,7 +499,7 @@ func (c *Command) Run(args []string) int {
// here)
c.SetStatusGracePeriodDuration(0)

base.StartMemProfiler(c.Logger)
base.StartMemProfiler(ctx)

if c.flagRecoveryKey != "" {
c.Config.DevRecoveryKey = c.flagRecoveryKey
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/commands/server/server.go
Expand Up @@ -178,7 +178,7 @@ func (c *Command) Run(args []string) int {
// here)
c.SetStatusGracePeriodDuration(0)

base.StartMemProfiler(c.Logger)
base.StartMemProfiler(ctx)

if err := c.SetupKMSes(c.UI, c.Config); err != nil {
c.UI.Error(err.Error())
Expand Down
11 changes: 3 additions & 8 deletions internal/cmd/commands/server/worker_shutdown_reload_test.go
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/hashicorp/boundary/internal/cmd/config"
"github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/tests/helper"
"github.com/hashicorp/go-hclog"
"github.com/mitchellh/cli"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
Expand Down Expand Up @@ -86,10 +85,6 @@ listener "tcp" {
`

func TestServer_ShutdownWorker(t *testing.T) {
logger := hclog.New(&hclog.LoggerOptions{
Name: t.Name(),
Level: hclog.Trace,
})
require := require.New(t)
controllerKey, workerAuthKey, _ := config.DevKeyGeneration()

Expand Down Expand Up @@ -144,19 +139,19 @@ func TestServer_ShutdownWorker(t *testing.T) {
require.NotNil(tgt)

// Create test server, update default port on target
ts := helper.NewTestTcpServer(t, logger)
ts := helper.NewTestTcpServer(t)
require.NotNil(ts)
defer ts.Close()
tgt, err = tcl.Update(ctx, tgt.Item.Id, tgt.Item.Version, targets.WithTcpTargetDefaultPort(ts.Port()))
require.NoError(err)
require.NotNil(tgt)

// Authorize and connect
sess := helper.NewTestSession(ctx, t, logger, tcl, "ttcp_1234567890")
sess := helper.NewTestSession(ctx, t, tcl, "ttcp_1234567890")
sConn := sess.Connect(ctx, t)

// Run initial send/receive test, make sure things are working
logger.Debug("running initial send/recv test")
t.Log("running initial send/recv test")
sConn.TestSendRecvAll(t)

// Now, shut the worker down.
Expand Down