From 5e86735aee448241cef8dd5b3b16059797c60565 Mon Sep 17 00:00:00 2001 From: Ramon de Klein Date: Mon, 13 Jan 2025 15:54:21 +0100 Subject: [PATCH] Improvements after testing --- internal/http/log.go | 43 +++++++++++++++++-------------- internal/keystore/vault/config.go | 1 + internal/keystore/vault/vault.go | 4 +-- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/internal/http/log.go b/internal/http/log.go index 55b19d02..3adf3b5a 100644 --- a/internal/http/log.go +++ b/internal/http/log.go @@ -19,27 +19,30 @@ func (lt *LoggingTransport) RoundTrip(req *http.Request) (*http.Response, error) } start := time.Now() - resp, err := rt.RoundTrip(req) - switch { - case err != nil: - slog.Info("HTTP error", - slog.String("method", req.Method), - slog.String("url", req.URL.String()), - slog.Duration("duration", time.Since(start)), - slog.String("error", err.Error())) - case resp.StatusCode < 300: - slog.Info("HTTP error response", - slog.String("method", req.Method), - slog.String("url", req.URL.String()), - slog.Duration("duration", time.Since(start)), - slog.String("status", resp.Status)) - default: - slog.Debug("HTTP success response", - slog.String("method", req.Method), - slog.String("url", req.URL.String()), - slog.Duration("duration", time.Since(start)), - slog.String("status", resp.Status)) + + // don't log health checks + if req.URL.Path != "/v1/sys/health" { + switch { + case err != nil: + slog.Info("HTTP error", + slog.String("method", req.Method), + slog.String("url", req.URL.String()), + slog.Duration("duration", time.Since(start)), + slog.String("error", err.Error())) + case resp.StatusCode >= 300: + slog.Info("HTTP error response", + slog.String("method", req.Method), + slog.String("url", req.URL.String()), + slog.Duration("duration", time.Since(start)), + slog.String("status", resp.Status)) + default: + slog.Debug("HTTP success response", + slog.String("method", req.Method), + slog.String("url", req.URL.String()), + slog.Duration("duration", time.Since(start)), + slog.String("status", resp.Status)) + } } return resp, err diff --git a/internal/keystore/vault/config.go b/internal/keystore/vault/config.go index 9d85126d..7b16fa93 100644 --- a/internal/keystore/vault/config.go +++ b/internal/keystore/vault/config.go @@ -249,5 +249,6 @@ func (c *Config) Clone() *Config { PrivateKey: c.PrivateKey, Certificate: c.Certificate, CAPath: c.CAPath, + Verbose: c.Verbose, } } diff --git a/internal/keystore/vault/vault.go b/internal/keystore/vault/vault.go index 3e438182..8ee80ae8 100644 --- a/internal/keystore/vault/vault.go +++ b/internal/keystore/vault/vault.go @@ -142,7 +142,7 @@ func Connect(ctx context.Context, c *Config) (*Store, error) { // log authentication events lastAuthSuccess := false - authenticate = func(ctx context.Context) (*vaultapi.Secret, error) { + authenticateLogged := func(ctx context.Context) (*vaultapi.Secret, error) { secret, err := authenticate(ctx) if err != nil { if lastAuthSuccess { @@ -164,7 +164,7 @@ func Connect(ctx context.Context, c *Config) (*Store, error) { return secret, err } - auth, err := authenticate(ctx) + auth, err := authenticateLogged(ctx) if err != nil { return nil, err }