Vet/race fixes (#4421)

This addresses all found vet/race fixes in community edition.

---------

Co-authored-by: Damian Debkowski <damian.debkowski@hashicorp.com>
This commit is contained in:
Jeff MitchellandDamian Debkowski authored and GitHub committed 2024-02-21 16:32:26 -05:00
1 parent 4535af25aa
commit 014a5a7aae
46 files changed
+411 -176

No files matched your search

+88 -23
View File
@@ -7,9 +7,11 @@ import (
"fmt"
"os"
"strings"
"sync/atomic"
"github.com/hashicorp/boundary/internal/cmd/base/logging"
"github.com/hashicorp/go-hclog"
"google.golang.org/grpc/grpclog"
)
func ProcessLogLevelAndFormat(flagLogLevel, flagLogFormat, configLogLevel, configLogFormat string) (hclog.Level, logging.LogFormat, error) {
@@ -59,77 +61,140 @@ func ProcessLogLevelAndFormat(flagLogLevel, flagLogFormat, configLogLevel, confi
return level, logFormat, nil
}
type grpcLogFakerLogHolder struct {
logger hclog.Logger
}
var grpcLogFaker *GRPCLogFaker = &GRPCLogFaker{
loggingEnabled: new(atomic.Bool),
logger: new(atomic.Pointer[grpcLogFakerLogHolder]),
}
func init() {
grpclog.SetLoggerV2(grpcLogFaker)
}
type GRPCLogFaker struct {
Logger hclog.Logger
Log bool
logger *atomic.Pointer[grpcLogFakerLogHolder]
loggingEnabled *atomic.Bool
}
func (g *GRPCLogFaker) SetLogOnOff(on bool) {
g.loggingEnabled.Store(on)
}
func (g *GRPCLogFaker) SetLogger(logger hclog.Logger) {
g.logger.Store(&grpcLogFakerLogHolder{logger: logger})
}
func (g *GRPCLogFaker) Fatal(args ...any) {
g.Logger.Error(fmt.Sprint(args...))
if l := g.logger.Load(); l != nil {
l.logger.Error(fmt.Sprint(args...))
}
os.Exit(1)
}
func (g *GRPCLogFaker) Fatalf(format string, args ...any) {
g.Logger.Error(fmt.Sprintf(format, args...))
if l := g.logger.Load(); l != nil {
l.logger.Error(fmt.Sprintf(format, args...))
}
os.Exit(1)
}
func (g *GRPCLogFaker) Fatalln(args ...any) {
g.Logger.Error(fmt.Sprintln(args...))
if l := g.logger.Load(); l != nil {
l.logger.Error(fmt.Sprintln(args...))
}
os.Exit(1)
}
func (g *GRPCLogFaker) Info(args ...any) {
if g.Log && g.Logger.IsDebug() {
g.Logger.Debug(fmt.Sprint(args...))
if g.loggingEnabled.Load() {
if l := g.logger.Load(); l != nil {
if l.logger.IsDebug() {
l.logger.Debug(fmt.Sprint(args...))
}
}
}
}
func (g *GRPCLogFaker) Infof(format string, args ...any) {
if g.Log && g.Logger.IsDebug() {
g.Logger.Debug(fmt.Sprintf(format, args...))
if g.loggingEnabled.Load() {
if l := g.logger.Load(); l != nil {
if l.logger.IsDebug() {
l.logger.Debug(fmt.Sprintf(format, args...))
}
}
}
}
func (g *GRPCLogFaker) Infoln(args ...any) {
if g.Log && g.Logger.IsDebug() {
g.Logger.Debug(fmt.Sprintln(args...))
if g.loggingEnabled.Load() {
if l := g.logger.Load(); l != nil {
if l.logger.IsDebug() {
l.logger.Debug(fmt.Sprintln(args...))
}
}
}
}
func (g *GRPCLogFaker) Warning(args ...any) {
if g.Log && g.Logger.IsDebug() {
g.Logger.Debug(fmt.Sprint(args...))
if g.loggingEnabled.Load() {
if l := g.logger.Load(); l != nil {
if l.logger.IsDebug() {
l.logger.Debug(fmt.Sprint(args...))
}
}
}
}
func (g *GRPCLogFaker) Warningf(format string, args ...any) {
if g.Log && g.Logger.IsDebug() {
g.Logger.Debug(fmt.Sprintf(format, args...))
if g.loggingEnabled.Load() {
if l := g.logger.Load(); l != nil {
if l.logger.IsDebug() {
l.logger.Debug(fmt.Sprintf(format, args...))
}
}
}
}
func (g *GRPCLogFaker) Warningln(args ...any) {
if g.Log && g.Logger.IsDebug() {
g.Logger.Debug(fmt.Sprintln(args...))
if g.loggingEnabled.Load() {
if l := g.logger.Load(); l != nil {
if l.logger.IsDebug() {
l.logger.Debug(fmt.Sprintln(args...))
}
}
}
}
func (g *GRPCLogFaker) Error(args ...any) {
if g.Log && g.Logger.IsDebug() {
g.Logger.Debug(fmt.Sprint(args...))
if g.loggingEnabled.Load() {
if l := g.logger.Load(); l != nil {
if l.logger.IsDebug() {
l.logger.Debug(fmt.Sprint(args...))
}
}
}
}
func (g *GRPCLogFaker) Errorf(format string, args ...any) {
if g.Log && g.Logger.IsDebug() {
g.Logger.Debug(fmt.Sprintf(format, args...))
if g.loggingEnabled.Load() {
if l := g.logger.Load(); l != nil {
if l.logger.IsDebug() {
l.logger.Debug(fmt.Sprintf(format, args...))
}
}
}
}
func (g *GRPCLogFaker) Errorln(args ...any) {
if g.Log && g.Logger.IsDebug() {
g.Logger.Debug(fmt.Sprintln(args...))
if g.loggingEnabled.Load() {
if l := g.logger.Load(); l != nil {
if l.logger.IsDebug() {
l.logger.Debug(fmt.Sprintln(args...))
}
}
}
}
+2 -5
View File
@@ -50,7 +50,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"google.golang.org/grpc/grpclog"
)
const (
@@ -285,10 +284,8 @@ func (b *Server) SetupLogging(flagLogLevel, flagLogFormat, configLogLevel, confi
// create GRPC logger
namedGRPCLogFaker := b.Logger.Named("grpclogfaker")
grpclog.SetLoggerV2(&GRPCLogFaker{
Logger: namedGRPCLogFaker,
Log: os.Getenv("BOUNDARY_GRPC_LOGGING") != "",
})
grpcLogFaker.SetLogOnOff(os.Getenv("BOUNDARY_GRPC_LOGGING") != "")
grpcLogFaker.SetLogger(namedGRPCLogFaker)
b.Info["log level"] = logLevel.String()
b.InfoKeys = append(b.InfoKeys, "log level")