From ef38d3a01e10bf618dcda0ad952e37312274e35f Mon Sep 17 00:00:00 2001 From: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com> Date: Mon, 16 Sep 2024 10:31:33 -0600 Subject: [PATCH] feat: switch to zerolog (#8) * feat: switch to zerolog Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com> * core version, startblock Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com> --------- Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com> --- cmd/cli/cmd/root.go | 49 ++++++++---- cmd/root.go | 55 ++++++++----- cmd/serve.go | 9 +-- go.mod | 29 ++++--- go.sum | 80 ++++++++++++------- internal/httpserve/config/config.go | 3 - .../httpserve/config/configproviderrefresh.go | 6 +- internal/httpserve/handlers/handlers.go | 4 - internal/httpserve/handlers/organizations.go | 14 ++-- internal/httpserve/server/server.go | 35 ++++---- internal/httpserve/serveropts/hooks.go | 15 ++++ internal/httpserve/serveropts/option.go | 21 ++--- 12 files changed, 191 insertions(+), 129 deletions(-) create mode 100644 internal/httpserve/serveropts/hooks.go diff --git a/cmd/cli/cmd/root.go b/cmd/cli/cmd/root.go index fa8b497..783a193 100644 --- a/cmd/cli/cmd/root.go +++ b/cmd/cli/cmd/root.go @@ -3,9 +3,12 @@ package cmd import ( "errors" + "fmt" "os" "path/filepath" + "runtime/debug" "strings" + "time" "github.com/knadh/koanf/parsers/yaml" "github.com/knadh/koanf/providers/env" @@ -13,8 +16,9 @@ import ( "github.com/knadh/koanf/providers/posflag" "github.com/knadh/koanf/v2" "github.com/mitchellh/go-homedir" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" "github.com/spf13/cobra" - "go.uber.org/zap" ) const ( @@ -24,7 +28,6 @@ const ( var ( cfgFile string OutputFormat string - Logger *zap.SugaredLogger Config *koanf.Koanf ) @@ -78,24 +81,40 @@ func initConfig() { setupLogging() } -// setupLogging configures the logger based on the command flags +// setupLogging sets up the logging defaults for the application func setupLogging() { - cfg := zap.NewProductionConfig() - if Config.Bool("pretty") { - cfg = zap.NewDevelopmentConfig() - } + // setup logging with time and app name + log.Logger = zerolog.New(os.Stderr). + With().Timestamp(). + Logger(). + With().Str("app", appName). + Logger() + + // set the log level + zerolog.SetGlobalLevel(zerolog.InfoLevel) + // set the log level to debug if the debug flag is set and add additional information if Config.Bool("debug") { - cfg.Level = zap.NewAtomicLevelAt(zap.DebugLevel) - } else { - cfg.Level = zap.NewAtomicLevelAt(zap.InfoLevel) - } + zerolog.SetGlobalLevel(zerolog.DebugLevel) - l, err := cfg.Build() - cobra.CheckErr(err) + buildInfo, _ := debug.ReadBuildInfo() - Logger = l.Sugar().With("app", appName) - defer Logger.Sync() //nolint:errcheck + log.Logger = log.Logger.With(). + Caller(). + Int("pid", os.Getpid()). + Str("go_version", buildInfo.GoVersion).Logger() + } + + // pretty logging for development + if Config.Bool("pretty") { + log.Logger = log.Output(zerolog.ConsoleWriter{ + Out: os.Stderr, + TimeFormat: time.RFC3339, + FormatCaller: func(i interface{}) string { + return filepath.Base(fmt.Sprintf("%s", i)) + }, + }) + } } // initConfiguration loads the configuration from the command flags of the given cobra command diff --git a/cmd/root.go b/cmd/root.go index abaff43..ae3e095 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,19 +1,23 @@ package cmd import ( - "log" + "fmt" + "os" + "path/filepath" + "runtime/debug" + "time" "github.com/knadh/koanf/providers/posflag" "github.com/knadh/koanf/v2" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" "github.com/spf13/cobra" - "go.uber.org/zap" ) const appName = "openlane-cloud" var ( - logger *zap.SugaredLogger - k *koanf.Koanf + k *koanf.Koanf ) // rootCmd represents the base command when called without any subcommands @@ -46,7 +50,7 @@ func init() { func initConfig() { // Load config from flags, including defaults if err := initCmdFlags(rootCmd); err != nil { - log.Fatalf("error loading config: %v", err) + log.Fatal().Err(err).Msg("error loading config") } setupLogging() @@ -56,23 +60,38 @@ func initCmdFlags(cmd *cobra.Command) error { return k.Load(posflag.Provider(cmd.Flags(), k.Delim(), k), nil) } +// setupLogging sets up the logging defaults for the application func setupLogging() { - cfg := zap.NewProductionConfig() + // setup logging with time and app name + log.Logger = zerolog.New(os.Stderr). + With().Timestamp(). + Logger(). + With().Str("app", appName). + Logger() + + // set the log level + zerolog.SetGlobalLevel(zerolog.InfoLevel) + + // set the log level to debug if the debug flag is set and add additional information if k.Bool("pretty") { - cfg = zap.NewDevelopmentConfig() - } + zerolog.SetGlobalLevel(zerolog.DebugLevel) - if k.Bool("debug") { - cfg.Level = zap.NewAtomicLevelAt(zap.DebugLevel) - } else { - cfg.Level = zap.NewAtomicLevelAt(zap.InfoLevel) - } + buildInfo, _ := debug.ReadBuildInfo() - l, err := cfg.Build() - if err != nil { - panic(err) + log.Logger = log.Logger.With(). + Caller(). + Int("pid", os.Getpid()). + Str("go_version", buildInfo.GoVersion).Logger() } - logger = l.Sugar().With("app", appName) - defer logger.Sync() //nolint:errcheck + // pretty logging for development + if k.Bool("pretty") { + log.Logger = log.Output(zerolog.ConsoleWriter{ + Out: os.Stderr, + TimeFormat: time.RFC3339, + FormatCaller: func(i interface{}) string { + return filepath.Base(fmt.Sprintf("%s", i)) + }, + }) + } } diff --git a/cmd/serve.go b/cmd/serve.go index b62c0e1..89dc921 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -3,9 +3,9 @@ package cmd import ( "context" + "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/theopenlane/beacon/otelx" - "go.uber.org/zap" "github.com/theopenlane/openlane-cloud/internal/httpserve/config" "github.com/theopenlane/openlane-cloud/internal/httpserve/server" @@ -30,7 +30,6 @@ func serve(ctx context.Context) error { serverOpts := []serveropts.ServerOption{} serverOpts = append(serverOpts, serveropts.WithConfigProvider(&config.ConfigProviderWithRefresh{}), - serveropts.WithLogger(logger), serveropts.WithOpenlaneClient(), serveropts.WithHTTPS(), serveropts.WithMiddleware(), @@ -40,13 +39,13 @@ func serve(ctx context.Context) error { so := serveropts.NewServerOptions(serverOpts, k.String("config")) if err := otelx.NewTracer(so.Config.Settings.Tracer, appName); err != nil { - logger.Fatalw("failed to initialize tracer", "error", err) + log.Fatal().Err(err).Msg("failed to initialize tracer") } - srv := server.NewServer(so.Config, so.Config.Logger) + srv := server.NewServer(so.Config) if err := srv.StartEchoServer(ctx); err != nil { - logger.Error("failed to run server", zap.Error(err)) + log.Error().Err(err).Msg("failed to run server") } return nil diff --git a/go.mod b/go.mod index fde692c..6b582c0 100644 --- a/go.mod +++ b/go.mod @@ -18,28 +18,29 @@ require ( github.com/mcuadros/go-defaults v1.2.0 github.com/mitchellh/go-homedir v1.1.0 github.com/prometheus/client_golang v1.20.3 + github.com/rs/zerolog v1.33.0 github.com/schollz/progressbar/v3 v3.15.0 github.com/spf13/cobra v1.8.1 github.com/stoewer/go-strcase v1.3.0 github.com/stretchr/testify v1.9.0 github.com/theopenlane/beacon v0.1.0 - github.com/theopenlane/core v0.1.9 + github.com/theopenlane/core v0.1.10 github.com/theopenlane/echo-prometheus v0.1.0 - github.com/theopenlane/echox v0.1.0 - github.com/theopenlane/echozap v0.1.0 + github.com/theopenlane/echox v0.2.0 github.com/theopenlane/httpsling v0.2.0 - github.com/theopenlane/iam v0.1.6 - github.com/theopenlane/utils v0.1.5 - go.uber.org/zap v1.27.0 + github.com/theopenlane/iam v0.2.0 + github.com/theopenlane/utils v0.2.0 golang.org/x/crypto v0.27.0 golang.org/x/text v0.18.0 ) require ( ariga.io/atlas v0.27.0 // indirect + entgo.io/contrib v0.6.0 // indirect entgo.io/ent v0.14.1 // indirect - github.com/Yamashou/gqlgenc v0.24.0 // indirect + github.com/Yamashou/gqlgenc v0.25.0 // indirect github.com/agext/levenshtein v1.2.3 // indirect + github.com/agnivade/levenshtein v1.1.1 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -80,6 +81,8 @@ require ( github.com/lestrrat-go/jwx/v2 v2.1.1 // indirect github.com/lestrrat-go/option v1.0.1 // indirect github.com/mailru/easyjson v0.7.7 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect github.com/mitchellh/copystructure v1.2.0 // indirect @@ -100,7 +103,7 @@ require ( github.com/segmentio/asm v1.2.0 // indirect github.com/sosodev/duration v1.3.1 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/theopenlane/entx v0.1.7 // indirect + github.com/theopenlane/entx v0.2.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect github.com/vektah/gqlparser/v2 v2.5.16 // indirect @@ -109,16 +112,16 @@ require ( github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect github.com/x448/float16 v0.8.4 // indirect github.com/zclconf/go-cty v1.15.0 // indirect - go.opentelemetry.io/otel v1.29.0 // indirect + go.opentelemetry.io/otel v1.30.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.29.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0 // indirect go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.29.0 // indirect - go.opentelemetry.io/otel/metric v1.29.0 // indirect + go.opentelemetry.io/otel/metric v1.30.0 // indirect go.opentelemetry.io/otel/sdk v1.29.0 // indirect - go.opentelemetry.io/otel/trace v1.29.0 // indirect + go.opentelemetry.io/otel/trace v1.30.0 // indirect go.opentelemetry.io/proto/otlp v1.3.1 // indirect - go.uber.org/multierr v1.11.0 // indirect + golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect golang.org/x/mod v0.21.0 // indirect golang.org/x/net v0.29.0 // indirect golang.org/x/oauth2 v0.23.0 // indirect @@ -129,7 +132,7 @@ require ( golang.org/x/tools v0.25.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect - google.golang.org/grpc v1.66.0 // indirect + google.golang.org/grpc v1.66.1 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index f236e55..599dd10 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,19 @@ ariga.io/atlas v0.27.0 h1:UHUQMTRx2Vz8/acJxEfcC/zL2wY739/vkZzt7L8HL8I= ariga.io/atlas v0.27.0/go.mod h1:KPLc7Zj+nzoXfWshrcY1RwlOh94dsATQEy4UPrF2RkM= +entgo.io/contrib v0.6.0 h1:xfo4TbJE7sJZWx7BV7YrpSz7IPFvS8MzL3fnfzZjKvQ= +entgo.io/contrib v0.6.0/go.mod h1:3qWIseJ/9Wx2Hu5zVh15FDzv7d/UvKNcYKdViywWCQg= entgo.io/ent v0.14.1 h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s= entgo.io/ent v0.14.1/go.mod h1:MH6XLG0KXpkcDQhKiHfANZSzR55TJyPL5IGNpI8wpco= github.com/99designs/gqlgen v0.17.50 h1:c0CggpVl4Eh9jDU8QVB/PRqwDBrJzd2RQYZCO7e+ZRs= github.com/99designs/gqlgen v0.17.50/go.mod h1:77/+pVe6zlTsz++oUg2m8VLgzdUPHxjoAG3BxI5y8Rc= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= -github.com/Yamashou/gqlgenc v0.24.0 h1:Aeufjb2zF0XxkeSTAVQ+DfiHL+ney/M2ovShZozBmHw= -github.com/Yamashou/gqlgenc v0.24.0/go.mod h1:3QQD8ZoeEyVXuzqcMDsl8OfCCCTk+ulaxkvFFQDupIA= +github.com/Yamashou/gqlgenc v0.25.0 h1:wb4CKKpnklmK9R+RQ68yoSdhqlK+MPflYT/hsMOE1+I= +github.com/Yamashou/gqlgenc v0.25.0/go.mod h1:KheDl3KZUFmnGCLHCHPQ6hodwWbggc889vwwaf0VqH8= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8= +github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 h1:uvdUDbHQHO85qeSydJtItA4T55Pw6BtAejd0APRJOCE= github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= github.com/alicebob/miniredis/v2 v2.33.0 h1:uvTF0EDeu9RLnUEG27Db5I68ESoIxTiXbNUiji6lZrA= @@ -18,6 +22,8 @@ github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNg github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= +github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= +github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -43,6 +49,7 @@ github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObk github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -52,6 +59,8 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnN github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g= +github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= @@ -81,6 +90,7 @@ github.com/go-webauthn/x v0.1.14 h1:1wrB8jzXAofojJPAaRxnZhRgagvLGnLjhCAwg3kTpT0= github.com/go-webauthn/x v0.1.14/go.mod h1:UuVvFZ8/NbOnkDz3y1NaxtUN87pmtpC1PQ+/5BBQRdc= github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -96,8 +106,12 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA= github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo= +github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= +github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys= github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/hcl/v2 v2.22.0 h1:hkZ3nCtqeJsDhPRFz5EA9iwcG1hNWGePOTw6oyul12M= github.com/hashicorp/hcl/v2 v2.22.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= @@ -149,11 +163,16 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0 github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= -github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/mattn/go-sqlite3 v1.14.23 h1:gbShiuAP1W5j9UOksQ06aiiqPMxYecovVGwmTxWtuw0= +github.com/mattn/go-sqlite3 v1.14.23/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mcuadros/go-defaults v1.2.0 h1:FODb8WSf0uGaY8elWJAkoLL0Ri6AlZ1bFlenk56oZtc= github.com/mcuadros/go-defaults v1.2.0/go.mod h1:WEZtHEVIGYVDqkKSWBdWKUVdRyKlMfulPaGDWIVeCWY= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= @@ -198,6 +217,9 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= +github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/schollz/progressbar/v3 v3.15.0 h1:cNZmcNiVyea6oofBTg80ZhVXxf3wG/JoAhqCCwopkQo= github.com/schollz/progressbar/v3 v3.15.0/go.mod h1:ncBdc++eweU0dQoeZJ3loXoAc+bjaallHRIm8pVVeQM= @@ -216,6 +238,8 @@ github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8w github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -225,22 +249,20 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/theopenlane/beacon v0.1.0 h1:cyGx18rbaJTZT8pRcqMMvg+kN6uh86X4OoDahQp6VnE= github.com/theopenlane/beacon v0.1.0/go.mod h1:gOJAanQzfmDF3FIyv7Lwx16bKI7YPkJx1iRT4SdcBW4= -github.com/theopenlane/core v0.1.9 h1:1D34xKoqKMqrRoiPjNru/CHpsOvKB9fiLLJFfpmOVos= -github.com/theopenlane/core v0.1.9/go.mod h1:z5sNm0rEmP3dASfbLxFnEZWviur0vdtVLqs1TNSK+bs= +github.com/theopenlane/core v0.1.10 h1:Y/Bd27g0C3OFt/sB8Wxucq1AGr9W6JPWR5+zmFDnS/I= +github.com/theopenlane/core v0.1.10/go.mod h1:pFQbbCPMgnLoNrOu8ab/nENSBqppb2qMFf9wnQHbGDU= github.com/theopenlane/echo-prometheus v0.1.0 h1:1zMejBVHe5w4zLHS+k5FV9S/46QBiwO6ggTSKi6r/7E= github.com/theopenlane/echo-prometheus v0.1.0/go.mod h1:Eiiv1ZLXKMsteQ3T+H1tFfSSZuXSvQfZp95qr5hmGkA= -github.com/theopenlane/echox v0.1.0 h1:y4Z2shaODCLwXHsHBrY/EkH/2sIuo49xdIfxx7h+Zvg= -github.com/theopenlane/echox v0.1.0/go.mod h1:RaynhPvY9qbLOVlcO7Js1NqZ66+CP9hVBa0c7ehNYA4= -github.com/theopenlane/echozap v0.1.0 h1:qoD1tEGQoTMPrzleOymk6auLHJcQmzPLprCEvoXNKDE= -github.com/theopenlane/echozap v0.1.0/go.mod h1:E3Fkzb6QvEsx9KxxpUv9dpxUvKjxAEUZSEtkYeCXLok= -github.com/theopenlane/entx v0.1.7 h1:H1123YtVR2nFjqDY0SlJsjQrX8aDn5DEWFNuU/M8lNA= -github.com/theopenlane/entx v0.1.7/go.mod h1:h978z5xgldvaL/dIX7E2zQZ3rJ6cFDKnuVpi9wKRSGc= +github.com/theopenlane/echox v0.2.0 h1:s9DJJrsLOSPsXVfgmQxgXmSVtxzztBnSmcVX4ax7tIM= +github.com/theopenlane/echox v0.2.0/go.mod h1:nfxwQpwvqYYI/pFHJKDs3/HLvjYKEGCih4XDgLSma64= +github.com/theopenlane/entx v0.2.0 h1:ymsaHXlG43visg84QH6ULmNNHKdYBYUY7jDumVImtEw= +github.com/theopenlane/entx v0.2.0/go.mod h1:eW5p++QXhTc8qv5/cbeeRTxKSVWkJ0jxmijZd4RpZxQ= github.com/theopenlane/httpsling v0.2.0 h1:5k/PoFA5jjak9dnijATFvTVTvgUSMFdEZeyctyv1cWU= github.com/theopenlane/httpsling v0.2.0/go.mod h1:Ta/8bjv4JhKT0Xk1hD2Iott9BKLCqXvscmjolSB/bBY= -github.com/theopenlane/iam v0.1.6 h1:ps6xLXHpnGy687uLPRZiD7034DRVqaWEfJLCJVMx95o= -github.com/theopenlane/iam v0.1.6/go.mod h1:mOtYjuqUD7SX4EkwXFAYwf8+mwPDsRvTsLhAngqVIxM= -github.com/theopenlane/utils v0.1.5 h1:4DRieQmsBF87n4lPjEkTt6s4iVRQaCGYlk2+C05lt3o= -github.com/theopenlane/utils v0.1.5/go.mod h1:LWJzG9FfklsLlqWx/VdmfBMuNk700cWqHAwQL0299FM= +github.com/theopenlane/iam v0.2.0 h1:TGFk4ToN6XVKQXJvyA2cNiVQfWmDnpDD9oV2B2qJndk= +github.com/theopenlane/iam v0.2.0/go.mod h1:8nPT57sPCoOzf5QeSbfEonDkZBTQpwIYnN8L8ibJbW8= +github.com/theopenlane/utils v0.2.0 h1:+O5pBWA9cvlCjdwHDaJKwnSMAVRUh1Jgkzl4nYU3h7E= +github.com/theopenlane/utils v0.2.0/go.mod h1:GdjAWxjiMavAMgRNqC6y5v4LUdCcCJlfuHHYU6LrrUw= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= @@ -263,8 +285,8 @@ github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= -go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= -go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= +go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts= +go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 h1:dIIDULZJpgdiHz5tXrTgKIMLkus6jEFa7x5SOKcyR7E= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0/go.mod h1:jlRVBe7+Z1wyxFSUs48L6OBQZ5JwH2Hg/Vbl+t9rAgI= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.29.0 h1:nSiV3s7wiCam610XcLbYOmMfJxB9gO4uK3Xgv5gmTgg= @@ -273,22 +295,20 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0 h1:JAv0J go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0/go.mod h1:QNKLmUEAq2QUbPQUfvw4fmv0bgbK7UlOSFCnXyfvSNc= go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.29.0 h1:X3ZjNp36/WlkSYx0ul2jw4PtbNEDDeLskw3VPsrpYM0= go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.29.0/go.mod h1:2uL/xnOXh0CHOBFCWXz5u1A4GXLiW+0IQIzVbeOEQ0U= -go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc= -go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8= +go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4QIZs7+w= +go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ= go.opentelemetry.io/otel/sdk v1.29.0 h1:vkqKjk7gwhS8VaWb0POZKmIEDimRCMsopNYnriHyryo= go.opentelemetry.io/otel/sdk v1.29.0/go.mod h1:pM8Dx5WKnvxLCb+8lG1PRNIDxu9g9b9g59Qr7hfAAok= -go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4= -go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ= +go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc= +go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o= go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= -go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= -go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk= +golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= @@ -299,7 +319,9 @@ golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM= @@ -315,14 +337,16 @@ google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 h1: google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:qpvKtACPCQhAdu3PyQgV4l3LMXZEtft7y8QcarRsp9I= google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ= google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= -google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c= -google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= +google.golang.org/grpc v1.66.1 h1:hO5qAXR19+/Z44hmvIM4dQFMSYX9XcWsByfoxutBpAM= +google.golang.org/grpc v1.66.1/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/httpserve/config/config.go b/internal/httpserve/config/config.go index b4f1dac..6cb405b 100644 --- a/internal/httpserve/config/config.go +++ b/internal/httpserve/config/config.go @@ -6,7 +6,6 @@ import ( "time" echo "github.com/theopenlane/echox" - "go.uber.org/zap" "golang.org/x/crypto/acme" "golang.org/x/crypto/acme/autocert" @@ -35,8 +34,6 @@ var ( type Config struct { // add all the configuration settings for the openlane server Settings config.Config - // Logger contains the logger used by echo functions - Logger *zap.SugaredLogger // Routes contains the handler functions Routes []http.Handler // DefaultMiddleware to enable on the echo server used on all requests diff --git a/internal/httpserve/config/configproviderrefresh.go b/internal/httpserve/config/configproviderrefresh.go index 32a65b2..946ed71 100644 --- a/internal/httpserve/config/configproviderrefresh.go +++ b/internal/httpserve/config/configproviderrefresh.go @@ -3,6 +3,8 @@ package config import ( "sync" "time" + + "github.com/rs/zerolog/log" ) // ConfigProviderWithRefresh shows a config provider with automatic refresh; it contains fields and methods to manage the configuration, @@ -65,11 +67,11 @@ func (s *ConfigProviderWithRefresh) refreshConfig() { newConfig, err := s.configProvider.GetConfig() if err != nil { - s.config.Logger.Error("failed to load new server configuration") + log.Error().Err(err).Msg("failed to load new server configuration") continue } - s.config.Logger.Info("loaded new server configuration") + log.Info().Msg("loaded new server configuration") s.Lock() s.config = newConfig diff --git a/internal/httpserve/handlers/handlers.go b/internal/httpserve/handlers/handlers.go index 7161989..f848165 100644 --- a/internal/httpserve/handlers/handlers.go +++ b/internal/httpserve/handlers/handlers.go @@ -1,8 +1,6 @@ package handlers import ( - "go.uber.org/zap" - "github.com/theopenlane/core/pkg/openlaneclient" ) @@ -10,8 +8,6 @@ import ( type Handler struct { // IsTest is a flag to determine if the application is running in test mode and will mock external calls IsTest bool - // Logger provides the zap logger to do logging things from the handlers - Logger *zap.SugaredLogger // ReadyChecks is a set of checkFuncs to determine if the application is "ready" upon startup ReadyChecks Checks // OpenlaneClient is the client to interact with the openlane API diff --git a/internal/httpserve/handlers/organizations.go b/internal/httpserve/handlers/organizations.go index 8b8b0de..c9ba002 100644 --- a/internal/httpserve/handlers/organizations.go +++ b/internal/httpserve/handlers/organizations.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/getkin/kin-openapi/openapi3" + "github.com/rs/zerolog/log" "github.com/theopenlane/core/pkg/openlaneclient" echo "github.com/theopenlane/echox" "github.com/theopenlane/utils/rout" @@ -29,12 +30,11 @@ func (h *Handler) OrganizationHandler(ctx echo.Context) error { return h.InvalidInput(ctx, err) } - h.Logger.Debugw("creating organization", - "name", in.Name, - "environments", in.Environments, - "buckets", in.Buckets, - "relationships", in.Relationships, - ) + log.Debug().Str("name", in.Name). + Strs("environments", in.Environments). + Strs("buckets", in.Buckets). + Strs("relationships", in.Relationships). + Msg("creating organization") // create root organization rootOrgName := in.Name @@ -145,7 +145,7 @@ func (h *Handler) createChildOrganizations(ctx context.Context, namePrefix, pare var orgs []openlaneclient.CreateOrganization_CreateOrganization_Organization for _, childName := range childNames { - h.Logger.Debugw("creating child organization", "childName", childName) + log.Debug().Str("childName", childName).Msg("creating child organization") orgName := childName diff --git a/internal/httpserve/server/server.go b/internal/httpserve/server/server.go index 36c31a8..01fc1f8 100644 --- a/internal/httpserve/server/server.go +++ b/internal/httpserve/server/server.go @@ -3,10 +3,9 @@ package server import ( "context" - echo "github.com/theopenlane/echox" - "go.uber.org/zap" - + "github.com/rs/zerolog/log" echodebug "github.com/theopenlane/core/pkg/middleware/debug" + echo "github.com/theopenlane/echox" "github.com/theopenlane/openlane-cloud/internal/httpserve/config" "github.com/theopenlane/openlane-cloud/internal/httpserve/route" @@ -15,8 +14,6 @@ import ( type Server struct { // config contains the base server settings config config.Config - // logger contains the zap logger - logger *zap.SugaredLogger // handlers contains additional handlers to register with the echo server handlers []handler } @@ -46,10 +43,9 @@ func (s *Server) AddHandler(r handler) { } // NewServer returns a new Server configuration -func NewServer(c config.Config, l *zap.SugaredLogger) *Server { +func NewServer(c config.Config) *Server { return &Server{ config: c, - logger: l, } } @@ -71,7 +67,7 @@ func (s *Server) StartEchoServer(ctx context.Context) error { srv.Echo.Debug = s.config.Settings.Server.Debug if srv.Echo.Debug { - srv.Echo.Use(echodebug.BodyDump(s.logger)) + srv.Echo.Use(echodebug.BodyDump()) } for _, m := range s.config.DefaultMiddleware { @@ -93,28 +89,31 @@ func (s *Server) StartEchoServer(ctx context.Context) error { // Print routes on startup routes := srv.Echo.Router().Routes() for _, r := range routes { - s.logger.Infow("registered route", "route", r.Path(), "method", r.Method()) + log.Info().Str("route", r.Path()).Str("method", r.Method()).Msg("registered route") } // if TLS is enabled, start new echo server with TLS if s.config.Settings.Server.TLS.Enabled { - s.logger.Infow("starting in https mode") + log.Info().Msg("starting in https mode") return sc.StartTLS(srv.Echo, s.config.Settings.Server.TLS.CertFile, s.config.Settings.Server.TLS.CertKey) } - s.logger.Infow(startBlock) + log.Info().Msg(startBlock) // otherwise, start without TLS return sc.Start(srv.Echo) } var startBlock = ` -________________________________________________________________ - - / ------------__------__----__----__---/----__----__----__--------- - / ) / ) /___) / ) / / ) / ) /___) -________(___/___/___/_(___ _/___/_/___(___(_/___/_(___ _________ - +┌────────────────────────────────────────────────────────────────────────────────────────┐ +│ ******* ******* ******** **** ** ** ** **** ** ******** │ +│ **/////** /**////**/**///// /**/** /**/** **** /**/** /**/**///// │ +│ ** //**/** /**/** /**//** /**/** **//** /**//** /**/** │ +│ /** /**/******* /******* /** //** /**/** ** //** /** //** /**/******* │ +│ /** /**/**//// /**//// /** //**/**/** **********/** //**/**/**//// │ +│ //** ** /** /** /** //****/** /**//////**/** //****/** │ +│ //******* /** /********/** //***/********/** /**/** //***/******** │ +│ /////// // //////// // /// //////// // // // /// //////// │ +└────────────────────────────────────────────────────────────────────────────────────────┘ ` diff --git a/internal/httpserve/serveropts/hooks.go b/internal/httpserve/serveropts/hooks.go new file mode 100644 index 0000000..d61cfca --- /dev/null +++ b/internal/httpserve/serveropts/hooks.go @@ -0,0 +1,15 @@ +package serveropts + +import ( + "github.com/rs/zerolog" +) + +// LevelNameHook is a hook that sets the level name field to "info" if the level is not set. +type LevelNameHook struct{} + +// Run satisfies the zerolog.Hook interface. +func (h LevelNameHook) Run(e *zerolog.Event, l zerolog.Level, msg string) { + if l == zerolog.NoLevel { + e.Str(zerolog.LevelFieldName, zerolog.InfoLevel.String()) + } +} diff --git a/internal/httpserve/serveropts/option.go b/internal/httpserve/serveropts/option.go index 584242c..3d0e900 100644 --- a/internal/httpserve/serveropts/option.go +++ b/internal/httpserve/serveropts/option.go @@ -1,21 +1,20 @@ package serveropts import ( + "github.com/rs/zerolog/log" echoprometheus "github.com/theopenlane/echo-prometheus" echo "github.com/theopenlane/echox" "github.com/theopenlane/echox/middleware" - "github.com/theopenlane/echozap" - "go.uber.org/zap" "github.com/theopenlane/openlane-cloud/internal/httpserve/config" "github.com/theopenlane/core/pkg/middleware/cachecontrol" "github.com/theopenlane/core/pkg/middleware/cors" - "github.com/theopenlane/core/pkg/middleware/echocontext" "github.com/theopenlane/core/pkg/middleware/mime" "github.com/theopenlane/core/pkg/middleware/ratelimit" "github.com/theopenlane/core/pkg/middleware/redirect" "github.com/theopenlane/core/pkg/openlaneclient" + "github.com/theopenlane/echox/middleware/echocontext" ) type ServerOption interface { @@ -43,16 +42,6 @@ func WithConfigProvider(cfgProvider config.ConfigProvider) ServerOption { }) } -// WithLogger supplies the logger for the server -func WithLogger(l *zap.SugaredLogger) ServerOption { - return newApplyFunc(func(s *ServerOptions) { - // Add logger to main config - s.Config.Logger = l - // Add logger to the handlers config - s.Config.Handler.Logger = l - }) -} - // WithOpenlaneClient supplies the openlane client for the server func WithOpenlaneClient() ServerOption { return newApplyFunc(func(s *ServerOptions) { @@ -65,7 +54,7 @@ func WithOpenlaneClient() ServerOption { s.Config.Handler.OpenlaneClient, err = openlaneclient.NewWithDefaults( openlaneclient.WithCredentials(creds)) if err != nil { - s.Config.Logger.Fatalw("failed to create openlane client", "error", err) + log.Fatal().Err(err).Msg("failed to create openlane client") } }) } @@ -100,10 +89,10 @@ func WithMiddleware() ServerOption { middleware.RequestID(), // add request id middleware.Recover(), // recover server from any panic/fatal error gracefully middleware.LoggerWithConfig(middleware.LoggerConfig{ - Format: "remote_ip=${remote_ip}, method=${method}, uri=${uri}, status=${status}, session=${header:Set-Cookie}, host=${host}, referer=${referer}, user_agent=${user_agent}, route=${route}, path=${path}, auth=${header:Authorization}\n", + Output: log.Logger.Hook(LevelNameHook{}), + Format: "remote_ip=${remote_ip}, method=${method}, uri=${uri}, status=${status}, session=${header:Set-Cookie}, host=${host}, referer=${referer}, user_agent=${user_agent}, route=${route}, path=${path}", }), echoprometheus.MetricsMiddleware(), // add prometheus metrics - echozap.ZapLogger(s.Config.Logger.Desugar()), // add zap logger, middleware requires the "regular" zap logger echocontext.EchoContextToContextMiddleware(), // adds echo context to parent cors.New(s.Config.Settings.Server.CORS.AllowOrigins), // add cors middleware mime.NewWithConfig(mime.Config{DefaultContentType: echo.MIMEApplicationJSONCharsetUTF8}), // add mime middleware