From 0b1a5de33f7fe6f79556f3061b207b94e3e1c720 Mon Sep 17 00:00:00 2001 From: Lukas Zapletal Date: Wed, 8 Jan 2025 13:02:50 +0100 Subject: [PATCH] refactor: introduce common logging --- .gitignore | 1 + Makefile | 2 +- cmd/image-builder-maintenance/db.go | 2 +- cmd/image-builder-maintenance/main.go | 31 ++- .../image-builder-migrate-db-tern.go | 59 ++++-- cmd/image-builder/logging.go | 107 ----------- cmd/image-builder/logging_test.go | 69 ------- cmd/image-builder/main.go | 148 +++++---------- go.mod | 28 ++- go.sum | 81 +++----- internal/clients/composer/client.go | 7 +- internal/clients/provisioning/client.go | 6 +- internal/clients/recommendations/client.go | 9 +- internal/common/allow.go | 2 +- internal/common/context.go | 51 ----- internal/common/echo_logrus.go | 178 ------------------ internal/common/runtime.go | 36 ---- internal/db/db_trace.go | 12 +- internal/logger/logger.go | 146 -------------- internal/logger/logger_test.go | 63 ------- internal/oauth2/lazy_token.go | 2 +- internal/oauth2/lazy_token_test.go | 36 ++-- internal/unleash/log-listener.go | 8 +- internal/v1/api.go | 1 - internal/v1/api.yaml | 2 - internal/v1/handler.go | 4 +- internal/v1/server_test.go | 15 +- 27 files changed, 227 insertions(+), 879 deletions(-) delete mode 100644 cmd/image-builder/logging.go delete mode 100644 cmd/image-builder/logging_test.go delete mode 100644 internal/common/context.go delete mode 100644 internal/common/echo_logrus.go delete mode 100644 internal/common/runtime.go delete mode 100644 internal/logger/logger.go delete mode 100644 internal/logger/logger_test.go diff --git a/.gitignore b/.gitignore index 2e8baba5f..98ea23fa5 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ __debug* coverage* /tools/bin vendor/ +/*.log diff --git a/Makefile b/Makefile index 8f1a20283..8ed6a33a9 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ ubi-container: ubi-maintenance-container-test: ubi-container # just check if the container would start # functional tests are in the target "db-tests" - podman run --rm --tty --entrypoint /app/image-builder-maintenance osbuild/image-builder 2>&1 | grep "Dry run, no state will be changed" + podman run --rm --tty --entrypoint /app/image-builder-maintenance osbuild/image-builder 2>&1 | tee ubi-maintenance-container-test.log | grep "dry run, no state will be changed" .PHONY: generate-openscap-blueprints generate-openscap-blueprints: diff --git a/cmd/image-builder-maintenance/db.go b/cmd/image-builder-maintenance/db.go index dc55f4b03..8555f3204 100644 --- a/cmd/image-builder-maintenance/db.go +++ b/cmd/image-builder-maintenance/db.go @@ -7,7 +7,7 @@ import ( "github.com/jackc/pgx/v5" - "github.com/sirupsen/logrus" + "github.com/osbuild/logging/pkg/logrus" ) const ( diff --git a/cmd/image-builder-maintenance/main.go b/cmd/image-builder-maintenance/main.go index dcc4ad3aa..7604ddac9 100644 --- a/cmd/image-builder-maintenance/main.go +++ b/cmd/image-builder-maintenance/main.go @@ -3,12 +3,13 @@ package main import ( "context" "fmt" + "log/slog" "os" "os/signal" "syscall" "time" - "github.com/sirupsen/logrus" + "github.com/osbuild/logging/pkg/sinit" ) func main() { @@ -35,8 +36,6 @@ func main() { ctx, cancelTimeout := context.WithTimeout(ctx, 2*time.Hour) defer cancelTimeout() - logrus.SetReportCaller(true) - conf := Config{ DryRun: true, EnableDBMaintenance: false, @@ -45,15 +44,30 @@ func main() { err := LoadConfigFromEnv(&conf) if err != nil { - logrus.Fatal(err) + panic(err) + } + + loggingConfig := sinit.LoggingConfig{ + StdoutConfig: sinit.StdoutConfig{ + Enabled: true, + Level: "debug", + Format: "text", + }, } + err = sinit.InitializeLogging(ctx, loggingConfig) + if err != nil { + panic(err) + } + + slog.InfoContext(ctx, "starting image-builder maintainance") + if conf.DryRun { - logrus.Info("Dry run, no state will be changed") + slog.InfoContext(ctx, "dry run, no state will be changed") } if !conf.EnableDBMaintenance { - logrus.Info("🦀🦀🦀 DB maintenance not enabled, skipping 🦀🦀🦀") + slog.InfoContext(ctx, "🦀🦀🦀 DB maintenance not enabled, skipping 🦀🦀🦀") return } dbURL := fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s", @@ -66,8 +80,9 @@ func main() { ) err = DBCleanup(ctx, dbURL, conf.DryRun, conf.ComposesRetentionMonths) if err != nil { - logrus.Fatalf("Error during DBCleanup: %v", err) + slog.ErrorContext(ctx, "error during DBCleanup", "err", err) + os.Exit(1) } - logrus.Info("🦀🦀🦀 dbqueue cleanup done 🦀🦀🦀") + slog.InfoContext(ctx, "🦀🦀🦀 dbqueue cleanup done 🦀🦀🦀") close(shutdownSignal) } diff --git a/cmd/image-builder-migrate-db-tern/image-builder-migrate-db-tern.go b/cmd/image-builder-migrate-db-tern/image-builder-migrate-db-tern.go index c5596e973..e82d1269a 100644 --- a/cmd/image-builder-migrate-db-tern/image-builder-migrate-db-tern.go +++ b/cmd/image-builder-migrate-db-tern/image-builder-migrate-db-tern.go @@ -3,14 +3,18 @@ package main import ( "bufio" "bytes" + "context" + "fmt" + "log/slog" + "os" "os/exec" "github.com/osbuild/image-builder/internal/config" - "github.com/osbuild/image-builder/internal/logger" - "github.com/sirupsen/logrus" + "github.com/osbuild/logging/pkg/sinit" ) func main() { + ctx := context.Background() conf := config.ImageBuilderConfig{ ListenAddress: "unused", LogLevel: "INFO", @@ -29,18 +33,51 @@ func main() { panic(err) } - err = logger.ConfigLogger(logrus.StandardLogger(), conf.LogLevel) + hostname, err := os.Hostname() if err != nil { - panic(err) + hostname = "image-builder-unknown" + } + + loggingConfig := sinit.LoggingConfig{ + StdoutConfig: sinit.StdoutConfig{ + Enabled: true, + Level: "warning", + Format: "text", + }, + SplunkConfig: sinit.SplunkConfig{ + Enabled: conf.SplunkHost != "" && conf.SplunkPort != "" && conf.SplunkToken != "", + Level: conf.LogLevel, + URL: fmt.Sprintf("https://%s:%s/services/collector/event", conf.SplunkHost, conf.SplunkPort), + Token: conf.SplunkToken, + Source: "image-builder", + Hostname: hostname, + }, + CloudWatchConfig: sinit.CloudWatchConfig{ + Enabled: conf.CwAccessKeyID != "" && conf.CwSecretAccessKey != "" && conf.CwRegion != "", + Level: conf.LogLevel, + AWSRegion: conf.CwRegion, + AWSSecret: conf.CwSecretAccessKey, + AWSKey: conf.CwAccessKeyID, + AWSLogGroup: conf.LogGroup, + AWSLogStream: hostname, + }, + SentryConfig: sinit.SentryConfig{ + Enabled: conf.GlitchTipDSN != "", + DSN: conf.GlitchTipDSN, + }, } - if conf.CwAccessKeyID != "" { - err = logger.AddCloudWatchHook(logrus.StandardLogger(), conf.CwAccessKeyID, conf.CwSecretAccessKey, conf.CwRegion, conf.LogGroup) - if err != nil { - panic(err) - } + err = sinit.InitializeLogging(ctx, loggingConfig) + if err != nil { + panic(err) } + slog.InfoContext(ctx, "starting image-builder migration", + "splunk", loggingConfig.SplunkConfig.Enabled, + "cloudwatch", loggingConfig.CloudWatchConfig.Enabled, + "sentry", loggingConfig.SentryConfig.Enabled, + ) + // #nosec G204 -- the executable in the config can be trusted cmd := exec.Command(conf.TernExecutable, "migrate", @@ -55,12 +92,12 @@ func main() { scanner := bufio.NewScanner(bytes.NewReader(out)) for scanner.Scan() { - logrus.Info(scanner.Text()) + slog.InfoContext(ctx, scanner.Text()) } if err != nil { panic(err) } - logrus.Info("DB migration successful") + slog.InfoContext(ctx, "DB migration successful") } diff --git a/cmd/image-builder/logging.go b/cmd/image-builder/logging.go deleted file mode 100644 index 067f175f7..000000000 --- a/cmd/image-builder/logging.go +++ /dev/null @@ -1,107 +0,0 @@ -package main - -import ( - "strings" - - "github.com/labstack/echo/v4" - "github.com/labstack/gommon/random" - "github.com/osbuild/image-builder/internal/common" - "github.com/sirupsen/logrus" -) - -// Use request id from the standard context and add it to the message as a field. -type ctxHook struct { -} - -func (h *ctxHook) Levels() []logrus.Level { - return []logrus.Level{ - logrus.DebugLevel, - logrus.InfoLevel, - logrus.WarnLevel, - logrus.ErrorLevel, - logrus.FatalLevel, - logrus.PanicLevel, - } -} - -func (h *ctxHook) Fire(e *logrus.Entry) error { - if e.Context == nil || e.Data == nil { - return nil - } - - e.Data["request_id"] = common.RequestId(e.Context) - e.Data["insights_id"] = common.InsightsRequestId(e.Context) - - rd := common.RequestData(e.Context) - for k, v := range rd { - e.Data[k] = v - } - - return nil -} - -// Extract/generate request id and store it in the standard context -func requestIdExtractMiddleware(next echo.HandlerFunc) echo.HandlerFunc { - return func(c echo.Context) error { - // extract or generate request and insights id - rid := c.Request().Header.Get("X-Rh-Edge-Request-Id") - if rid != "" { - rid = strings.TrimSuffix(rid, "\n") - } else { - rid = random.String(12) - } - - iid := c.Request().Header.Get("X-Rh-Insights-Request-Id") - if iid != "" { - iid = strings.TrimSuffix(iid, "\n") - } else { - iid = random.String(12) - } - - // create fields stored with every log statement - rd := logrus.Fields{ - "method": c.Request().Method, - "path": c.Path(), - } - for _, key := range c.ParamNames() { - // protect existing and the most important fields - if _, ok := rd[key]; !(ok || key == "msg" || key == "level") { - rd[key] = c.Param(key) - } - } - - // store it in a standard context - ctx := c.Request().Context() - ctx = common.WithRequestId(ctx, rid) - ctx = common.WithInsightsRequestId(ctx, iid) - ctx = common.WithRequestData(ctx, rd) - c.SetRequest(c.Request().WithContext(ctx)) - - // and set echo logger to be context logger - ctxLogger := logrus.StandardLogger() - newLogger := &common.EchoLogrusLogger{ - Logger: ctxLogger, - Ctx: ctx, - } - c.SetLogger(newLogger) - - if !SkipPath(c.Path()) { - newLogger.Debugf("Started request") - } - - return next(c) - } -} - -func SkipPath(path string) bool { - switch path { - case "/metrics": - return true - case "/status": - return true - case "/ready": - return true - } - - return false -} diff --git a/cmd/image-builder/logging_test.go b/cmd/image-builder/logging_test.go deleted file mode 100644 index abf2d1030..000000000 --- a/cmd/image-builder/logging_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package main - -import ( - "context" - "testing" - - "github.com/osbuild/image-builder/internal/common" - "github.com/sirupsen/logrus" - "github.com/stretchr/testify/require" -) - -func TestFire(t *testing.T) { - testHook := &ctxHook{} - - tests := []struct { - entry *logrus.Entry - exp_before map[string]string - exp_after map[string]string - }{ - // empty calls should not crash - {&logrus.Entry{}, - map[string]string{}, - map[string]string{}, - }, - {&logrus.Entry{Context: context.Background(), Data: make(logrus.Fields)}, - map[string]string{}, - map[string]string{}, - }, - - // Data should be added - {&logrus.Entry{ - Context: common.WithRequestId(context.Background(), "Test"), - Data: make(logrus.Fields)}, - map[string]string{}, - map[string]string{"request_id": "Test"}, - }, - - // valid DataCtx - {&logrus.Entry{ - Context: common.WithRequestData(context.Background(), - logrus.Fields{ - "method": "GET", - "path": "/"}), - Data: make(logrus.Fields)}, - map[string]string{}, - map[string]string{"method": "GET"}, - }, - - // invalid DataCtx - {&logrus.Entry{ - Context: common.WithRequestData(context.Background(), nil), - Data: make(logrus.Fields)}, - map[string]string{}, - map[string]string{}, - }, - } - - for _, test := range tests { - for k, v := range test.exp_before { - require.Equal(t, v, test.entry.Data[k]) - } - - require.Equal(t, testHook.Fire(test.entry), nil) - for k, v := range test.exp_after { - require.Equal(t, v, test.entry.Data[k]) - } - } - -} diff --git a/cmd/image-builder/main.go b/cmd/image-builder/main.go index dc49220cd..6f194089a 100644 --- a/cmd/image-builder/main.go +++ b/cmd/image-builder/main.go @@ -2,49 +2,31 @@ package main import ( "context" - "errors" "fmt" - "runtime/debug" - - "github.com/osbuild/image-builder/internal/oauth2" + "log/slog" + "os" "github.com/osbuild/image-builder/internal/clients/compliance" "github.com/osbuild/image-builder/internal/clients/composer" "github.com/osbuild/image-builder/internal/clients/content_sources" "github.com/osbuild/image-builder/internal/clients/provisioning" "github.com/osbuild/image-builder/internal/clients/recommendations" - "github.com/osbuild/image-builder/internal/common" "github.com/osbuild/image-builder/internal/config" "github.com/osbuild/image-builder/internal/db" "github.com/osbuild/image-builder/internal/distribution" - "github.com/osbuild/image-builder/internal/logger" + "github.com/osbuild/image-builder/internal/oauth2" "github.com/osbuild/image-builder/internal/unleash" v1 "github.com/osbuild/image-builder/internal/v1" - "github.com/getsentry/sentry-go" sentryecho "github.com/getsentry/sentry-go/echo" - sentrylogrus "github.com/getsentry/sentry-go/logrus" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "github.com/labstack/gommon/log" - slogger "github.com/osbuild/osbuild-composer/pkg/splunk_logger" - "github.com/sirupsen/logrus" + echoproxy "github.com/osbuild/logging/pkg/echo" + "github.com/osbuild/logging/pkg/sinit" + "github.com/osbuild/logging/pkg/strc" ) -// gitRev returns the gitHash of the current running binary -func gitRev() (string, error) { - info, ok := debug.ReadBuildInfo() - if !ok { - return "", errors.New("cannot read build info") - } - for _, bs := range info.Settings { - if bs.Key == "vcs.revision" { - return bs.Value, nil - } - } - return "", errors.New("vcs.revision not found in debug.ReadBuildInfo()") -} - func main() { conf := config.ImageBuilderConfig{ ListenAddress: "localhost:8086", @@ -64,56 +46,51 @@ func main() { panic(err) } - if conf.GlitchTipDSN != "" { - err = sentry.Init(sentry.ClientOptions{ - Dsn: conf.GlitchTipDSN, - }) - if err != nil { - panic(err) - } - } - - err = logger.ConfigLogger(logrus.StandardLogger(), conf.LogLevel) - if err != nil { - panic(err) - } - logrus.AddHook(&ctxHook{}) - - gitRev, err := gitRev() + hostname, err := os.Hostname() if err != nil { - logrus.Warn(err.Error()) - gitRev = "unknown" + hostname = "image-builder-unknown" } - logrus.Infof("Starting image-builder from Git Hash: %s", gitRev) - logrus.Infof("Changelog: https://github.com/osbuild/image-builder/commits/%s", gitRev) - - if conf.GlitchTipDSN == "" { - logrus.Warn("Sentry/Glitchtip was not initialized") - } else { - sentryhook := sentrylogrus.NewFromClient([]logrus.Level{logrus.PanicLevel, - logrus.FatalLevel, logrus.ErrorLevel}, - sentry.CurrentHub().Client()) - logrus.AddHook(sentryhook) - } - - if conf.CwAccessKeyID != "" { - err = logger.AddCloudWatchHook(logrus.StandardLogger(), conf.CwAccessKeyID, conf.CwSecretAccessKey, conf.CwRegion, conf.LogGroup) - if err != nil { - panic(err) - } + loggingConfig := sinit.LoggingConfig{ + StdoutConfig: sinit.StdoutConfig{ + Enabled: true, + Level: "warning", + Format: "text", + }, + SplunkConfig: sinit.SplunkConfig{ + Enabled: conf.SplunkHost != "" && conf.SplunkPort != "" && conf.SplunkToken != "", + Level: conf.LogLevel, + URL: fmt.Sprintf("https://%s:%s/services/collector/event", conf.SplunkHost, conf.SplunkPort), + Token: conf.SplunkToken, + Source: "image-builder", + Hostname: hostname, + }, + CloudWatchConfig: sinit.CloudWatchConfig{ + Enabled: conf.CwAccessKeyID != "" && conf.CwSecretAccessKey != "" && conf.CwRegion != "", + Level: conf.LogLevel, + AWSRegion: conf.CwRegion, + AWSSecret: conf.CwSecretAccessKey, + AWSKey: conf.CwAccessKeyID, + AWSLogGroup: conf.LogGroup, + AWSLogStream: hostname, + }, + SentryConfig: sinit.SentryConfig{ + Enabled: conf.GlitchTipDSN != "", + DSN: conf.GlitchTipDSN, + }, } - if conf.DeploymentChannel != "" { - logrus.AddHook(&slogger.EnvironmentHook{Channel: conf.DeploymentChannel}) + err = sinit.InitializeLogging(ctx, loggingConfig) + if err != nil { + panic(err) } + defer sinit.Flush() - if conf.SplunkHost != "" { - err = logger.AddSplunkHook(logrus.StandardLogger(), conf.SplunkHost, conf.SplunkPort, conf.SplunkToken) - if err != nil { - panic(err) - } - } + slog.Info("starting image-builder", + "splunk", loggingConfig.SplunkConfig.Enabled, + "cloudwatch", loggingConfig.CloudWatchConfig.Enabled, + "sentry", loggingConfig.SentryConfig.Enabled, + ) connStr := fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s", conf.PGUser, conf.PGPassword, conf.PGHost, conf.PGPort, conf.PGDatabase, conf.PGSSLMode) dbase, err := db.InitDBConnectionPool(ctx, connStr) @@ -189,34 +166,13 @@ func main() { echoServer := echo.New() echoServer.HideBanner = true - echoServer.Logger = common.Logger() - echoServer.Use(requestIdExtractMiddleware) - echoServer.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ - LogURI: true, - LogStatus: true, - LogLatency: true, - LogMethod: true, - LogValuesFunc: func(c echo.Context, values middleware.RequestLoggerValues) error { - fields := logrus.Fields{ - "uri": values.URI, - "method": values.Method, - "status": values.Status, - "latency_ms": values.Latency.Milliseconds(), - "request_id": common.RequestId(c.Request().Context()), - "insights_id": common.InsightsRequestId(c.Request().Context()), - } - if values.Error != nil { - fields["error"] = values.Error - } - logrus.WithContext(c.Request().Context()). - WithFields(fields).Infof("Processed request %s %s", values.Method, values.URI) - - return nil - }, - Skipper: func(c echo.Context) bool { - return SkipPath(c.Path()) - }, - })) + echoServer.Logger = echoproxy.NewProxyFor(slog.Default()) + echoServer.Use(echo.WrapMiddleware(strc.NewMiddlewareWithFilters( + slog.Default(), + strc.IgnorePathPrefix("/metrics"), + strc.IgnorePathPrefix("/status"), + strc.IgnorePathPrefix("/ready"), + ))) if conf.GlitchTipDSN != "" { echoServer.Use(sentryecho.New(sentryecho.Options{})) } @@ -256,7 +212,7 @@ func main() { panic(err) } - logrus.Infof("🚀 Starting image-builder built %s sha %s server on %v ...\n", common.BuildTime, common.BuildCommit, conf.ListenAddress) + log.Info("🚀 starting image-builder server", "listen", conf.ListenAddress) err = echoServer.Start(conf.ListenAddress) if err != nil { panic(err) diff --git a/go.mod b/go.mod index 034f01bda..4eac570a4 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,14 @@ module github.com/osbuild/image-builder -go 1.22 +go 1.22.1 -toolchain go1.22.0 +toolchain go1.23.4 require ( github.com/BurntSushi/toml v1.4.0 github.com/Unleash/unleash-client-go/v4 v4.1.4 - github.com/aws/aws-sdk-go v1.55.6 github.com/getkin/kin-openapi v0.128.0 - github.com/getsentry/sentry-go v0.31.1 github.com/getsentry/sentry-go/echo v0.31.1 - github.com/getsentry/sentry-go/logrus v0.31.1 github.com/google/uuid v1.6.0 github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438 github.com/jackc/pgx/v5 v5.7.2 @@ -20,23 +17,29 @@ require ( github.com/labstack/gommon v0.4.2 github.com/oapi-codegen/runtime v1.1.1 github.com/osbuild/community-gateway/oidc-authorizer v0.0.0-20240208125334-43c3aac2bb9c - github.com/osbuild/images v0.112.0 - github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20250102070339-8b0a1d1714f6 + github.com/osbuild/images v0.107.0 + github.com/osbuild/logging v0.0.2 github.com/prometheus/client_golang v1.20.5 github.com/redhatinsights/app-common-go v1.6.8 github.com/redhatinsights/identity v0.0.0-20220719174832-36a7b1cbeff1 - github.com/redhatinsights/platform-go-middlewares v1.0.0 - github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.10.0 ) require ( github.com/Masterminds/semver/v3 v3.1.1 // indirect github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect + github.com/aws/aws-sdk-go-v2 v1.32.7 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.17.48 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26 // indirect + github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.45.1 // indirect + github.com/aws/smithy-go v1.22.1 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/getsentry/sentry-go v0.31.1 // indirect github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/swag v0.23.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect @@ -45,20 +48,25 @@ require ( github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect - github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/klauspost/compress v1.17.9 // indirect + github.com/lzap/cloudwatchwriter2 v1.4.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/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/onsi/ginkgo v1.16.5 // indirect github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.55.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect + github.com/samber/lo v1.47.0 // indirect + github.com/samber/slog-common v0.18.0 // indirect + github.com/samber/slog-sentry/v2 v2.9.2 // indirect github.com/stretchr/objx v0.5.2 // indirect + github.com/systemd/slog-journal v0.1.0 // indirect github.com/twmb/murmur3 v1.1.8 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect diff --git a/go.sum b/go.sum index 0af881dbc..c12c1c2e0 100644 --- a/go.sum +++ b/go.sum @@ -7,9 +7,20 @@ github.com/Unleash/unleash-client-go/v4 v4.1.4 h1:c/Z90s4Q/VtAlpTsPR23qV7mgBZch0 github.com/Unleash/unleash-client-go/v4 v4.1.4/go.mod h1:k7LRAXyKeZ1DwqGaKn1KZo92e9JVlEPut4CAhutPJmU= github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ= github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= -github.com/aws/aws-sdk-go v1.49.13/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= -github.com/aws/aws-sdk-go v1.55.6 h1:cSg4pvZ3m8dgYcgqB97MrcdjUmZ1BeMYKUxMMB89IPk= -github.com/aws/aws-sdk-go v1.55.6/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= +github.com/aws/aws-sdk-go-v2 v1.32.7 h1:ky5o35oENWi0JYWUZkB7WYvVPP+bcRF5/Iq7JWSb5Rw= +github.com/aws/aws-sdk-go-v2 v1.32.7/go.mod h1:P5WJBrYqqbWVaOxgH0X/FYYD47/nooaPOZPlQdmiN2U= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 h1:lL7IfaFzngfx0ZwUGOZdsFFnQ5uLvR0hWqqhyE7Q9M8= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7/go.mod h1:QraP0UcVlQJsmHfioCrveWOC1nbiWUl3ej08h4mXWoc= +github.com/aws/aws-sdk-go-v2/credentials v1.17.48 h1:IYdLD1qTJ0zanRavulofmqut4afs45mOWEI+MzZtTfQ= +github.com/aws/aws-sdk-go-v2/credentials v1.17.48/go.mod h1:tOscxHN3CGmuX9idQ3+qbkzrjVIx32lqDSU1/0d/qXs= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26 h1:I/5wmGMffY4happ8NOCuIUEWGUvvFp5NSeQcXl9RHcI= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26/go.mod h1:FR8f4turZtNy6baO0KJ5FJUmXH/cSkI9fOngs0yl6mA= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26 h1:zXFLuEuMMUOvEARXFUVJdfqZ4bvvSgdGRq/ATcrQxzM= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26/go.mod h1:3o2Wpy0bogG1kyOPrgkXA8pgIfEEv0+m19O9D5+W8y8= +github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.45.1 h1:f6jhr4U8osQQrJrzKsWcbTZwK4xA0wUF52sN0zvLKUY= +github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.45.1/go.mod h1:u8Bi6DG9tLOVIS9MNqtE3vh9T6I/U/8RBpYvy/VyMjc= +github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro= +github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= @@ -31,9 +42,6 @@ github.com/getsentry/sentry-go v0.31.1 h1:ELVc0h7gwyhnXHDouXkhqTFSO5oslsRDk0++ey github.com/getsentry/sentry-go v0.31.1/go.mod h1:CYNcMMz73YigoHljQRG+qPF+eMq8gG72XcGN/p71BAY= github.com/getsentry/sentry-go/echo v0.31.1 h1:bGY2QrNq5PovERoQBwyfJtQixjptHC06gLiAlF0WUPc= github.com/getsentry/sentry-go/echo v0.31.1/go.mod h1:2gHa20EVxDNNTJY+Cq4Eqr8A0Z6UEULh4ImSsVMSRUg= -github.com/getsentry/sentry-go/logrus v0.31.1 h1:561777lxQWZl4qpte67Wp4zQB7V1oNVriZNN5hiOooI= -github.com/getsentry/sentry-go/logrus v0.31.1/go.mod h1:UHhxir22yymjeM8dBN0LM+7Z98+cYFEev8V3AV1+UYU= -github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= @@ -85,10 +93,6 @@ github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI= github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ= github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= -github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= -github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= -github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= -github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= @@ -106,6 +110,8 @@ github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaa github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= +github.com/lzap/cloudwatchwriter2 v1.4.1 h1:2CqzIl94h8z/nqOVYs9aNRe4f4idpy+yh+ffW95TVg4= +github.com/lzap/cloudwatchwriter2 v1.4.1/go.mod h1:/6POlaGi8jO8R12iSmXzcxDdOyR6puJPJWIsN0dW/k0= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -135,10 +141,10 @@ github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c= github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/osbuild/community-gateway/oidc-authorizer v0.0.0-20240208125334-43c3aac2bb9c h1:2xNCErdgiigmIJhWsiwTxevG9H1B1wdDXDMAaQWI/EA= github.com/osbuild/community-gateway/oidc-authorizer v0.0.0-20240208125334-43c3aac2bb9c/go.mod h1:CecYUdLQNeKEkEC0DOejBTaVxs8Xbr30tRtgOIpbuKo= -github.com/osbuild/images v0.112.0 h1:+pKwPniwYTRRgist6V+7DQfZEg7osddl1z4pASecq4M= -github.com/osbuild/images v0.112.0/go.mod h1:58tzp7jV50rjaH9gMpvmQdVati0c4TaC5Op7wmSD/tY= -github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20250102070339-8b0a1d1714f6 h1:TF34HV84ZNAkKWpqi//CXiYuWAkuXE2CE1ug92F5eoo= -github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20250102070339-8b0a1d1714f6/go.mod h1:zR1iu/hOuf+OQNJlk70tju9IqzzM4ycq0ectkFBm94U= +github.com/osbuild/images v0.107.0 h1:lSH4Wkizm+7ZSzo0xYGs4vNpjmV8JaYZg6GczK/dCfo= +github.com/osbuild/images v0.107.0/go.mod h1:4bNmMQOVadIKVC1q8zsLO8tdEQFH90zIp+MQBQUnCiE= +github.com/osbuild/logging v0.0.2 h1:usmHAWUbrXPGF95gIrJLaCVIIWkQvzRTikG9jhqEhvA= +github.com/osbuild/logging v0.0.2/go.mod h1:q/fLOvb36kGwJ69pBBUOjhzklxvZ8t+9JuZFclOep7M= github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s= github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= @@ -160,13 +166,14 @@ github.com/redhatinsights/app-common-go v1.6.8 h1:hyExMp6WHprlGkHKElQvSFF2ZPX8XT github.com/redhatinsights/app-common-go v1.6.8/go.mod h1:KW0BK+bnhp3kXU8BFwebQXqCqjdkcRewZsDlXCSNMyo= github.com/redhatinsights/identity v0.0.0-20220719174832-36a7b1cbeff1 h1:oCJ53EClFw5LdNWLKYmwGeqkUoYLV0Wy6ZaZlwjDYDY= github.com/redhatinsights/identity v0.0.0-20220719174832-36a7b1cbeff1/go.mod h1:B0Dwuuaghxyqo8ltmLZyLpKQFKU6r8cE2YRrO0bVdXM= -github.com/redhatinsights/platform-go-middlewares v1.0.0 h1:OxyiYt+VmNo+UucK/ey0b6UDFnpCni6JoGPeisGmmNI= -github.com/redhatinsights/platform-go-middlewares v1.0.0/go.mod h1:dRH6XOjiZDbw8STvk6NNC7mMwqhTaV7X+1tn1oXOs24= 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/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= -github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= +github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= +github.com/samber/slog-common v0.18.0 h1:zPeXHM+WhMl2zSx76Rg3EE0jwXdkut9s45K+pwhcO1c= +github.com/samber/slog-common v0.18.0/go.mod h1:6Krf+hemckfEiRDqy3J/sTpKTJQvmOoFLj9Riz3IkRU= +github.com/samber/slog-sentry/v2 v2.9.2 h1:JW3mQvza3YX+QN1EZ1ZL0ERGgS2uS/3RTZt5zp3hkfk= +github.com/samber/slog-sentry/v2 v2.9.2/go.mod h1:kPT5LvrwBwS0PqbsUcMzJHVeQrJLJd/xJMpYAzI409A= github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -178,6 +185,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/systemd/slog-journal v0.1.0 h1:/SdZsEp21ZzFWS3w6rcmiFCkaVKX3dt8W8mwcbNPdrM= +github.com/systemd/slog-journal v0.1.0/go.mod h1:RroeO1jghpRimGgddhGx+TS/CmRJdPjK9g2ZeYLr9P8= github.com/twmb/murmur3 v1.1.8 h1:8Yt9taO/WN3l08xErzjeschgZU2QSrwm1kclYq+0aRg= github.com/twmb/murmur3 v1.1.8/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= @@ -187,40 +196,25 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 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.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -228,37 +222,21 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg= @@ -266,8 +244,6 @@ golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -290,7 +266,6 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/internal/clients/composer/client.go b/internal/clients/composer/client.go index e28f976c1..d5223cb30 100644 --- a/internal/clients/composer/client.go +++ b/internal/clients/composer/client.go @@ -12,11 +12,9 @@ import ( "path/filepath" "strings" - "github.com/osbuild/image-builder/internal/common" - "github.com/osbuild/image-builder/internal/oauth2" - "github.com/google/uuid" - "github.com/sirupsen/logrus" + "github.com/osbuild/image-builder/internal/oauth2" + "github.com/osbuild/logging/pkg/logrus" ) type ComposerClient struct { @@ -83,7 +81,6 @@ func (cc *ComposerClient) request(method, url string, headers map[string]string, for k, v := range headers { req.Header.Add(k, v) } - req.Header.Add("X-External-Id", common.RequestId(req.Context())) token, err := cc.tokener.Token(req.Context()) if err != nil { diff --git a/internal/clients/provisioning/client.go b/internal/clients/provisioning/client.go index 32db15388..76e1c80c9 100644 --- a/internal/clients/provisioning/client.go +++ b/internal/clients/provisioning/client.go @@ -6,6 +6,7 @@ import ( "io" "net/http" + "github.com/osbuild/logging/pkg/strc" "github.com/redhatinsights/identity" ) @@ -37,7 +38,10 @@ func (pc *ProvisioningClient) request(method, url string, headers map[string]str req.Header.Add(k, v) } - return pc.client.Do(req) + // TODO context must be passed to the request method + req = req.WithContext(context.TODO()) + doer := strc.NewTracingDoer(pc.client) + return doer.Do(req) } func (pc *ProvisioningClient) GetUploadInfo(ctx context.Context, sourceID string) (*http.Response, error) { diff --git a/internal/clients/recommendations/client.go b/internal/clients/recommendations/client.go index 5c3b97d2b..fb521f9bd 100644 --- a/internal/clients/recommendations/client.go +++ b/internal/clients/recommendations/client.go @@ -2,6 +2,7 @@ package recommendations import ( "bytes" + "context" "crypto/tls" "crypto/x509" "encoding/json" @@ -14,7 +15,8 @@ import ( "strings" "github.com/osbuild/image-builder/internal/oauth2" - "github.com/sirupsen/logrus" + "github.com/osbuild/logging/pkg/logrus" + "github.com/osbuild/logging/pkg/strc" ) type RecommendationsClient struct { @@ -106,7 +108,10 @@ func (rc *RecommendationsClient) request(method, url string, headers map[string] } req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) - resp, err := rc.client.Do(req) + // TODO context must be passed to the request method + req = req.WithContext(context.TODO()) + doer := strc.NewTracingDoer(rc.client) + resp, err := doer.Do(req) if err != nil { return nil, err } diff --git a/internal/common/allow.go b/internal/common/allow.go index 01c79baf5..6628b7b93 100644 --- a/internal/common/allow.go +++ b/internal/common/allow.go @@ -8,7 +8,7 @@ import ( "path/filepath" "regexp" - "github.com/sirupsen/logrus" + "github.com/osbuild/logging/pkg/logrus" ) type AllowList map[string][]string diff --git a/internal/common/context.go b/internal/common/context.go deleted file mode 100644 index 130afc6f5..000000000 --- a/internal/common/context.go +++ /dev/null @@ -1,51 +0,0 @@ -package common - -import ( - "context" - - "github.com/sirupsen/logrus" -) - -type ctxKey int - -const ( - requestIdCtx ctxKey = iota - insightsRequestIdCtx ctxKey = iota - requestDataCtx ctxKey = iota -) - -func WithRequestId(ctx context.Context, requestId string) context.Context { - return context.WithValue(ctx, requestIdCtx, requestId) -} - -func RequestId(ctx context.Context) string { - rid := ctx.Value(requestIdCtx) - if rid == nil { - return "" - } - return rid.(string) -} - -func WithInsightsRequestId(ctx context.Context, insightsRequestId string) context.Context { - return context.WithValue(ctx, insightsRequestIdCtx, insightsRequestId) -} - -func InsightsRequestId(ctx context.Context) string { - iid := ctx.Value(insightsRequestIdCtx) - if iid == nil { - return "" - } - return iid.(string) -} - -func WithRequestData(ctx context.Context, data logrus.Fields) context.Context { - return context.WithValue(ctx, requestDataCtx, data) -} - -func RequestData(ctx context.Context) logrus.Fields { - rd := ctx.Value(requestDataCtx) - if rd == nil { - return logrus.Fields{} - } - return rd.(logrus.Fields) -} diff --git a/internal/common/echo_logrus.go b/internal/common/echo_logrus.go deleted file mode 100644 index a61b97c56..000000000 --- a/internal/common/echo_logrus.go +++ /dev/null @@ -1,178 +0,0 @@ -package common - -import ( - "context" - "encoding/json" - "io" - - "github.com/labstack/gommon/log" - "github.com/sirupsen/logrus" -) - -// EchoLogrusLogger extend logrus.Logger -type EchoLogrusLogger struct { - *logrus.Logger - Ctx context.Context -} - -var commonLogger = &EchoLogrusLogger{ - Logger: logrus.StandardLogger(), - Ctx: context.Background(), -} - -func Logger() *EchoLogrusLogger { - return commonLogger -} - -func toEchoLevel(level logrus.Level) log.Lvl { - switch level { - case logrus.DebugLevel: - return log.DEBUG - case logrus.InfoLevel: - return log.INFO - case logrus.WarnLevel: - return log.WARN - case logrus.ErrorLevel: - return log.ERROR - } - - return log.OFF -} - -func (l *EchoLogrusLogger) Output() io.Writer { - return l.Out -} - -func (l *EchoLogrusLogger) SetOutput(w io.Writer) { - // disable operations that would change behavior of global logrus logger. -} - -func (l *EchoLogrusLogger) Level() log.Lvl { - return toEchoLevel(l.Logger.Level) -} - -func (l *EchoLogrusLogger) SetLevel(v log.Lvl) { - // disable operations that would change behavior of global logrus logger. -} - -func (l *EchoLogrusLogger) SetHeader(h string) { -} - -func (l *EchoLogrusLogger) Prefix() string { - return "" -} - -func (l *EchoLogrusLogger) SetPrefix(p string) { -} - -func (l *EchoLogrusLogger) Print(i ...interface{}) { - l.Logger.WithContext(l.Ctx).Print(i...) -} - -func (l *EchoLogrusLogger) Printf(format string, args ...interface{}) { - l.Logger.WithContext(l.Ctx).Printf(format, args...) -} - -func (l *EchoLogrusLogger) Printj(j log.JSON) { - b, err := json.Marshal(j) - if err != nil { - panic(err) - } - l.Logger.WithContext(l.Ctx).Println(string(b)) -} - -func (l *EchoLogrusLogger) Debug(i ...interface{}) { - l.Logger.WithContext(l.Ctx).Debug(i...) -} - -func (l *EchoLogrusLogger) Debugf(format string, args ...interface{}) { - l.Logger.WithContext(l.Ctx).Debugf(format, args...) -} - -func (l *EchoLogrusLogger) Debugj(j log.JSON) { - b, err := json.Marshal(j) - if err != nil { - panic(err) - } - l.Logger.WithContext(l.Ctx).Debugln(string(b)) -} - -func (l *EchoLogrusLogger) Info(i ...interface{}) { - l.Logger.WithContext(l.Ctx).Info(i...) -} - -func (l *EchoLogrusLogger) Infof(format string, args ...interface{}) { - l.Logger.WithContext(l.Ctx).Infof(format, args...) -} - -func (l *EchoLogrusLogger) Infoj(j log.JSON) { - b, err := json.Marshal(j) - if err != nil { - panic(err) - } - l.Logger.WithContext(l.Ctx).Infoln(string(b)) -} - -func (l *EchoLogrusLogger) Warn(i ...interface{}) { - l.Logger.WithContext(l.Ctx).Warn(i...) -} - -func (l *EchoLogrusLogger) Warnf(format string, args ...interface{}) { - l.Logger.WithContext(l.Ctx).Warnf(format, args...) -} - -func (l *EchoLogrusLogger) Warnj(j log.JSON) { - b, err := json.Marshal(j) - if err != nil { - panic(err) - } - l.Logger.WithContext(l.Ctx).Warnln(string(b)) -} - -func (l *EchoLogrusLogger) Error(i ...interface{}) { - l.Logger.WithContext(l.Ctx).Error(i...) -} - -func (l *EchoLogrusLogger) Errorf(format string, args ...interface{}) { - l.Logger.WithContext(l.Ctx).Errorf(format, args...) -} - -func (l *EchoLogrusLogger) Errorj(j log.JSON) { - b, err := json.Marshal(j) - if err != nil { - panic(err) - } - l.Logger.WithContext(l.Ctx).Errorln(string(b)) -} - -func (l *EchoLogrusLogger) Fatal(i ...interface{}) { - l.Logger.WithContext(l.Ctx).Fatal(i...) -} - -func (l *EchoLogrusLogger) Fatalf(format string, args ...interface{}) { - l.Logger.WithContext(l.Ctx).Fatalf(format, args...) -} - -func (l *EchoLogrusLogger) Fatalj(j log.JSON) { - b, err := json.Marshal(j) - if err != nil { - panic(err) - } - l.Logger.WithContext(l.Ctx).Fatalln(string(b)) -} - -func (l *EchoLogrusLogger) Panic(i ...interface{}) { - l.Logger.WithContext(l.Ctx).Panic(i...) -} - -func (l *EchoLogrusLogger) Panicf(format string, args ...interface{}) { - l.Logger.WithContext(l.Ctx).Panicf(format, args...) -} - -func (l *EchoLogrusLogger) Panicj(j log.JSON) { - b, err := json.Marshal(j) - if err != nil { - panic(err) - } - l.Logger.WithContext(l.Ctx).Panicln(string(b)) -} diff --git a/internal/common/runtime.go b/internal/common/runtime.go deleted file mode 100644 index 1148b3c39..000000000 --- a/internal/common/runtime.go +++ /dev/null @@ -1,36 +0,0 @@ -package common - -import "runtime/debug" - -var ( - // Git SHA commit (first 4 characters) - BuildCommit string - - // Build date and time - BuildTime string - - // BuildGoVersion carries Go version the binary was built with - BuildGoVersion string -) - -func init() { - bi, ok := debug.ReadBuildInfo() - - if !ok { - BuildTime = "N/A" - BuildCommit = "HEAD" - } - - BuildGoVersion = bi.GoVersion - - for _, bs := range bi.Settings { - switch bs.Key { - case "vcs.revision": - if len(bs.Value) > 6 { - BuildCommit = bs.Value[0:6] - } - case "vcs.time": - BuildTime = bs.Value - } - } -} diff --git a/internal/db/db_trace.go b/internal/db/db_trace.go index ed4ebda75..f12e0df8f 100644 --- a/internal/db/db_trace.go +++ b/internal/db/db_trace.go @@ -4,16 +4,20 @@ import ( "context" "encoding/json" "fmt" + "log/slog" "github.com/jackc/pgx/v5" - "github.com/sirupsen/logrus" ) // Used for pgx logging with context information type dbTracer struct{} func (dt *dbTracer) TraceQueryStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryStartData) context.Context { - logrus.WithContext(ctx).Debug(formatSqlLog(data)) + if !slog.Default().Enabled(ctx, slog.LevelDebug) { + return ctx + } + + slog.DebugContext(ctx, formatSqlLog(data)) return ctx } @@ -22,10 +26,6 @@ func (dt *dbTracer) TraceQueryEnd(ctx context.Context, conn *pgx.Conn, data pgx. } func formatSqlLog(data pgx.TraceQueryStartData) string { - if logrus.GetLevel() > logrus.DebugLevel { - return "" - } - d := make([]interface{}, len(data.Args)) copy(d, data.Args) for i, v := range d { diff --git a/internal/logger/logger.go b/internal/logger/logger.go deleted file mode 100644 index 79c1c2baa..000000000 --- a/internal/logger/logger.go +++ /dev/null @@ -1,146 +0,0 @@ -package logger - -import ( - "bytes" - "context" - "encoding/json" - "os" - "strings" - "time" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/credentials" - slogger "github.com/osbuild/osbuild-composer/pkg/splunk_logger" - "github.com/redhatinsights/platform-go-middlewares/logging/cloudwatch" - "github.com/sirupsen/logrus" -) - -// If CW_AWS_ACCESS_KEY_ID is set in the environment it will assume that the -// logging sink is an aws cloudwatch instance. The following variables have to -// be set as well: -// CW_AWS_SECRET_ACCESS_KEY -// CW_AWS_REGION -// CW_LOG_GROUP - -// If CW_AWS_ACCESS_KEY_ID is not set, this logs to stdout with the following format: -// time="$timestamp" level=(debug|info|...) msg="error message" \ -// func=$caller file=*.go - -var logLevel logrus.Level - -var stdLoggerConfigd = false - -type Formatter struct { - Hostname string -} - -// NewCloudwatchFormatter creates a new log formatter -func NewCloudwatchFormatter() *Formatter { - f := &Formatter{} - - var err error - if f.Hostname, err = os.Hostname(); err != nil { - f.Hostname = "unknown" - } - - return f -} - -// Format is the log formatter for the entry -func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error) { - b := &bytes.Buffer{} - - now := time.Now() - - hostname, err := os.Hostname() - if err == nil { - f.Hostname = hostname - } - - // Based on https://github.com/RedHatInsights/insights-ingress-go/blob/master/logger/logger.go - data := map[string]interface{}{ - "@timestamp": now.Format("2006-01-02T15:04:05.999Z"), - "@version": 1, - "message": entry.Message, - "levelname": entry.Level.String(), - "source_host": f.Hostname, - "app": "image-builder", - "caller": entry.Caller.Func.Name(), - } - - for k, v := range entry.Data { - switch v := v.(type) { - case error: - data[k] = v.Error() - default: - data[k] = v - } - } - - j, err := json.Marshal(data) - if err != nil { - return nil, err - } - - b.Write(j) - b.WriteRune('\n') - - return b.Bytes(), nil -} - -func ConfigLogger(log *logrus.Logger, level string) error { - - // avoid configuring standard logger multiple times to avoid duplicate hooks - if stdLoggerConfigd && log == logrus.StandardLogger() { - return nil - } - - switch strings.ToUpper(level) { - case "TRACE": - logLevel = logrus.TraceLevel - case "DEBUG": - logLevel = logrus.DebugLevel - case "ERROR": - logLevel = logrus.ErrorLevel - case "INFO": - fallthrough - default: - logLevel = logrus.InfoLevel - } - - log.SetLevel(logLevel) - log.SetOutput(os.Stdout) - log.SetReportCaller(true) - log.SetFormatter(&logrus.TextFormatter{ - DisableColors: true, - }) - - if log == logrus.StandardLogger() { - stdLoggerConfigd = true - } - - return nil -} - -func AddCloudWatchHook(log *logrus.Logger, key, secret, region, group string) error { - f := NewCloudwatchFormatter() - log.SetFormatter(f) - cred := credentials.NewStaticCredentials(key, secret, "") - awsconf := aws.NewConfig().WithRegion(region).WithCredentials(cred) - // avoid the cloudwatch sequence token to get out of sync using the unique hostname per pod - hook, err := cloudwatch.NewBatchingHook(group, f.Hostname, awsconf, 10*time.Second) - if err != nil { - return err - } - log.AddHook(hook) - return nil -} - -func AddSplunkHook(log *logrus.Logger, host, port, token string) error { - hook, err := slogger.NewSplunkHook(context.Background(), host, port, token, "image-builder") - if err != nil { - return err - } - log.AddHook(hook) - return nil -} diff --git a/internal/logger/logger_test.go b/internal/logger/logger_test.go deleted file mode 100644 index 021d6c82c..000000000 --- a/internal/logger/logger_test.go +++ /dev/null @@ -1,63 +0,0 @@ -package logger - -import ( - "os" - "testing" - - "github.com/sirupsen/logrus" - "github.com/stretchr/testify/require" -) - -func CreateLogger() *logrus.Logger { - return &logrus.Logger{ - Out: os.Stderr, - Formatter: new(logrus.TextFormatter), - Hooks: make(logrus.LevelHooks), - Level: logrus.DebugLevel, - } -} - -func TestNewLoggerDEBUG(t *testing.T) { - log := CreateLogger() - err := ConfigLogger(log, "DEBUG") - - require.NoError(t, err) - require.Equal(t, logrus.DebugLevel, log.Level) - require.IsType(t, &logrus.TextFormatter{}, log.Formatter) -} - -func TestNewLoggerERROR(t *testing.T) { - log := CreateLogger() - err := ConfigLogger(log, "ERROR") - - require.NoError(t, err) - require.Equal(t, logrus.ErrorLevel, log.Level) - require.IsType(t, &logrus.TextFormatter{}, log.Formatter) -} - -func TestNewLoggerINFO(t *testing.T) { - log := CreateLogger() - err := ConfigLogger(log, "INFO") - - require.NoError(t, err) - require.Equal(t, logrus.InfoLevel, log.Level) - require.IsType(t, &logrus.TextFormatter{}, log.Formatter) -} - -func TestNewLoggerUnknownLevel(t *testing.T) { - log := CreateLogger() - err := ConfigLogger(log, "DummyLevel") - - require.NoError(t, err) - require.Equal(t, logrus.InfoLevel, log.Level) - require.IsType(t, &logrus.TextFormatter{}, log.Formatter) -} - -func TestNewLoggerWithInvalidKeyAndSecret(t *testing.T) { - log := CreateLogger() - err := ConfigLogger(log, "DEBUG") - require.NoError(t, err) - err = AddCloudWatchHook(log, "testSecret", "us-east-1", "image-builder", "") - - require.Error(t, err, "The security token included in the request is invalid") -} diff --git a/internal/oauth2/lazy_token.go b/internal/oauth2/lazy_token.go index 7748e4268..6d5c497a7 100644 --- a/internal/oauth2/lazy_token.go +++ b/internal/oauth2/lazy_token.go @@ -10,7 +10,7 @@ import ( "sync" "time" - "github.com/sirupsen/logrus" + "github.com/osbuild/logging/pkg/logrus" ) // Tokener is an interface that defines the AccessToken method. diff --git a/internal/oauth2/lazy_token_test.go b/internal/oauth2/lazy_token_test.go index 58e962c1e..c933c83bf 100644 --- a/internal/oauth2/lazy_token_test.go +++ b/internal/oauth2/lazy_token_test.go @@ -4,15 +4,15 @@ import ( "context" "encoding/json" "fmt" + "log/slog" "net/http" "net/http/httptest" "testing" "time" - "github.com/sirupsen/logrus" + "github.com/osbuild/logging/pkg/collect" + "github.com/osbuild/logging/pkg/logrus" "github.com/stretchr/testify/assert" - - logrusTest "github.com/sirupsen/logrus/hooks/test" "github.com/stretchr/testify/require" ) @@ -38,8 +38,16 @@ func TestLazyToken(t *testing.T) { })) defer mockServer.Close() - _, hook := logrusTest.NewNullLogger() - logrus.AddHook(hook) + // this is not thread-safe but tests are not running in parallel + collector := collect.NewTestHandler(slog.LevelDebug, false, false, false) + old := slog.Default().Handler() + slog.SetDefault(slog.New(collector)) + defer slog.SetDefault(slog.New(old)) + + // temporary logrus proxy - will be removed + oldP := logrus.Default() + logrus.SetDefault(logrus.NewProxyFor(slog.Default())) + defer logrus.SetDefault(oldP) clientID := "test-client-id" clientSecret := "test-client-secret" @@ -54,19 +62,21 @@ func TestLazyToken(t *testing.T) { require.Equal(t, "mock-token-1", token) // ensure no token is not part of the logs - assert.Equal(t, 1, len(hook.Entries)) - assert.Contains(t, hook.Entries[0].Message, "Acquired new token") - assert.NotContains(t, hook.Entries[0].Message, "mock-token-1") - hook.Reset() + field := collector.Last()["msg"] + assert.Equal(t, 1, len(collector.All())) + assert.Contains(t, field, "Acquired new token") + assert.NotContains(t, field, "mock-token-1") + collector.Reset() token, err = lazyToken.Token(ctx) require.NoError(t, err) require.Equal(t, "mock-token-1", token) - assert.Equal(t, 1, len(hook.Entries)) - assert.Contains(t, hook.Entries[0].Message, "AccessToken reused") - assert.NotContains(t, hook.Entries[0].Message, "mock-token-1") - hook.Reset() + field = collector.Last()["msg"] + assert.Equal(t, 1, len(collector.All())) + assert.Contains(t, field, "AccessToken reused") + assert.NotContains(t, field, "mock-token-1") + collector.Reset() // generates a new token when token expired lazyToken.Expiration = time.Now().Add(-time.Minute) // Expire the token diff --git a/internal/unleash/log-listener.go b/internal/unleash/log-listener.go index c28acaa8b..2767788ad 100644 --- a/internal/unleash/log-listener.go +++ b/internal/unleash/log-listener.go @@ -1,22 +1,22 @@ package unleash import ( - "github.com/sirupsen/logrus" + "log/slog" ) type LogListener struct{} // OnError prints out errors. func (l LogListener) OnError(err error) { - logrus.Errorf("Unleash Error: %v", err) + slog.Error("unleash Error", "err", err) } // OnWarning prints out warning. func (l LogListener) OnWarning(err error) { - logrus.Warnf("Unleash warning: %v", err) + slog.Warn("unleash warning", "warn", err) } // OnReady prints to the console when the repository is ready. func (l LogListener) OnReady() { - logrus.Info("Unleash is ready") + slog.Info("unleash is ready") } diff --git a/internal/v1/api.go b/internal/v1/api.go index 279ccd36f..ef5cba15e 100644 --- a/internal/v1/api.go +++ b/internal/v1/api.go @@ -998,7 +998,6 @@ type User struct { // Version defines model for Version. type Version struct { BuildCommit *string `json:"build_commit,omitempty"` - BuildTime *string `json:"build_time,omitempty"` Version string `json:"version"` } diff --git a/internal/v1/api.yaml b/internal/v1/api.yaml index 03b5827ca..30a23b613 100644 --- a/internal/v1/api.yaml +++ b/internal/v1/api.yaml @@ -747,8 +747,6 @@ components: properties: version: type: string - build_time: - type: string build_commit: type: string Readiness: diff --git a/internal/v1/handler.go b/internal/v1/handler.go index e3dd9bdba..283ca0bd1 100644 --- a/internal/v1/handler.go +++ b/internal/v1/handler.go @@ -12,6 +12,7 @@ import ( "time" "github.com/osbuild/image-builder/internal/distribution" + "github.com/osbuild/logging" "github.com/google/uuid" @@ -52,8 +53,7 @@ func (h *Handlers) newLinksWithExtraParams(path string, count, limit int, params func (h *Handlers) GetVersion(ctx echo.Context) error { version := Version{ Version: h.server.spec.Info.Version, - BuildCommit: common.ToPtr(common.BuildCommit), - BuildTime: common.ToPtr(common.BuildTime), + BuildCommit: common.ToPtr(logging.BuildID()), } return ctx.JSON(http.StatusOK, version) } diff --git a/internal/v1/server_test.go b/internal/v1/server_test.go index 88dd118a3..702578e8b 100644 --- a/internal/v1/server_test.go +++ b/internal/v1/server_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "log/slog" "net/http" "net/http/httptest" "os" @@ -12,7 +13,7 @@ import ( "time" "github.com/labstack/echo/v4" - "github.com/sirupsen/logrus" + "github.com/osbuild/logging/pkg/logrus" "github.com/stretchr/testify/require" "github.com/osbuild/image-builder/internal/clients/compliance" @@ -23,7 +24,6 @@ import ( "github.com/osbuild/image-builder/internal/common" "github.com/osbuild/image-builder/internal/db" "github.com/osbuild/image-builder/internal/distribution" - "github.com/osbuild/image-builder/internal/logger" "github.com/osbuild/image-builder/internal/oauth2" "github.com/osbuild/image-builder/internal/tutils" v1 "github.com/osbuild/image-builder/internal/v1" @@ -121,15 +121,8 @@ type testServer struct { func startServer(t *testing.T, tscc *testServerClientsConf, conf *v1.ServerConfig) *testServer { ctx := context.Background() - var log = &logrus.Logger{ - Out: os.Stderr, - Formatter: new(logrus.TextFormatter), - Hooks: make(logrus.LevelHooks), - Level: logrus.DebugLevel, - } - - err := logger.ConfigLogger(log, "DEBUG") - require.NoError(t, err) + logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})) + slog.SetDefault(logger) tokenServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json")