Skip to content

Commit

Permalink
Improvements after testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ramondeklein committed Jan 13, 2025
1 parent 9f2be64 commit 5e86735
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
43 changes: 23 additions & 20 deletions internal/http/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/keystore/vault/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,6 @@ func (c *Config) Clone() *Config {
PrivateKey: c.PrivateKey,
Certificate: c.Certificate,
CAPath: c.CAPath,
Verbose: c.Verbose,
}
}
4 changes: 2 additions & 2 deletions internal/keystore/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 5e86735

Please sign in to comment.