Skip to content

Commit 692bb36

Browse files
committed
Fix conditional logging in key cache initialization
Ensure that logging only occurs when an error is present during the initialization of the key caches. This prevents unnecessary log entries when no error is encountered, improving log clarity and reducing noise.
1 parent 495c28f commit 692bb36

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

coderd/coderd.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ func New(options *Options) *API {
462462
fetcher,
463463
codersdk.CryptoKeyFeatureOIDCConvert,
464464
)
465-
options.Logger.Critical(ctx, "failed to properly instantiate oidc convert signing cache", slog.Error(err))
465+
if err != nil {
466+
options.Logger.Critical(ctx, "failed to properly instantiate oidc convert signing cache", slog.Error(err))
467+
}
466468
}
467469

468470
if options.AppSigningKeyCache == nil {
@@ -471,7 +473,9 @@ func New(options *Options) *API {
471473
fetcher,
472474
codersdk.CryptoKeyFeatureWorkspaceAppsToken,
473475
)
474-
options.Logger.Critical(ctx, "failed to properly instantiate app signing key cache", slog.Error(err))
476+
if err != nil {
477+
options.Logger.Critical(ctx, "failed to properly instantiate app signing key cache", slog.Error(err))
478+
}
475479
}
476480

477481
if options.AppEncryptionKeyCache == nil {
@@ -480,7 +484,9 @@ func New(options *Options) *API {
480484
fetcher,
481485
codersdk.CryptoKeyFeatureWorkspaceAppsAPIKey,
482486
)
483-
options.Logger.Critical(ctx, "failed to properly instantiate app encryption key cache", slog.Error(err))
487+
if err != nil {
488+
options.Logger.Critical(ctx, "failed to properly instantiate app encryption key cache", slog.Error(err))
489+
}
484490
}
485491

486492
// Start a background process that rotates keys. We intentionally start this after the caches

coderd/workspaceapps_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
"testing"
88
"time"
99

10-
"cdr.dev/slog/sloggers/slogtest"
1110
"github.com/go-jose/go-jose/v4/jwt"
1211
"github.com/stretchr/testify/require"
1312

13+
"cdr.dev/slog/sloggers/slogtest"
14+
1415
"github.com/coder/coder/v2/coderd/coderdtest"
1516
"github.com/coder/coder/v2/coderd/cryptokeys"
1617
"github.com/coder/coder/v2/coderd/database"

0 commit comments

Comments
 (0)