Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix cacher interceptor ordering #1914

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions internal/cmd/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,8 @@ func NewGRPCServer(
otelgrpc.UnaryServerInterceptor(),
}

var cacher cache.Cacher
if cfg.Cache.Enabled {
var cacher cache.Cacher

switch cfg.Cache.Backend {
case config.CacheMemory:
cacher = memory.NewCache(cfg.Cache)
Expand Down Expand Up @@ -268,7 +267,6 @@ func NewGRPCServer(
}))
}

interceptors = append(interceptors, middlewaregrpc.CacheUnaryInterceptor(cacher, logger))
store = storagecache.New(store, cacher, logger)

logger.Debug("cache enabled", zap.Stringer("backend", cacher))
Expand Down Expand Up @@ -325,7 +323,12 @@ func NewGRPCServer(
)...,
)

// audit sinks configuration.
// cache must come after auth interceptors
if cfg.Cache.Enabled && cacher != nil {
interceptors = append(interceptors, middlewaregrpc.CacheUnaryInterceptor(cacher, logger))
}

// audit sinks configuration
sinks := make([]audit.Sink, 0)

if cfg.Audit.Sinks.LogFile.Enabled {
Expand All @@ -337,8 +340,8 @@ func NewGRPCServer(
sinks = append(sinks, logFileSink)
}

// Based on audit sink configuration from the user, provision the audit sinks and add them to a slice,
// and if the slice has a non-zero length, add the audit sink interceptor.
// based on audit sink configuration from the user, provision the audit sinks and add them to a slice,
// and if the slice has a non-zero length, add the audit sink interceptor
if len(sinks) > 0 {
sse := audit.NewSinkSpanExporter(logger, sinks)
tracingProvider.RegisterSpanProcessor(tracesdk.NewBatchSpanProcessor(sse, tracesdk.WithBatchTimeout(cfg.Audit.Buffer.FlushPeriod), tracesdk.WithMaxExportBatchSize(cfg.Audit.Buffer.Capacity)))
Expand Down
Loading