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

Removed unused time.Duration parameter from ShouldLog() function in middle.OptionalLogging interface #513

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
* [CHANGE] Expose `BuildHTTPMiddleware` to enable dskit `Server` instrumentation addition on external `*mux.Router`s. #459
* [CHANGE] Remove `RouteHTTPToGRPC` option and related functionality #460
* [CHANGE] Cache: Remove `MemcachedCache` and `RedisCache` structs in favor of `RemoteCacheAdapter` or using the underlying clients directly. #471
* [CHANGE] Removed unused `time.Duration` parameter from `ShouldLog()` function in `middle.OptionalLogging` interface. #513
* [FEATURE] Cache: Add support for configuring a Redis cache backend. #268 #271 #276
* [FEATURE] Add support for waiting on the rate limiter using the new `WaitN` method. #279
* [FEATURE] Add `log.BufferedLogger` type. #338
Expand Down
2 changes: 1 addition & 1 deletion httpgrpc/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestServerHandleDoNotLogError(t *testing.T) {
var optional middleware.OptionalLogging
if testData.doNotLogError {
require.ErrorAs(t, err, &optional)
require.False(t, optional.ShouldLog(context.Background(), 0))
require.False(t, optional.ShouldLog(context.Background()))
} else {
require.False(t, errors.As(err, &optional))
}
Expand Down
13 changes: 7 additions & 6 deletions middleware/grpc_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ const (
gRPC = "gRPC"
)

// An error can implement ShouldLog() to control whether GRPCServerLog will log.
// OptionalLogging is the interface that needs be implemented by an error that wants to control whether the log
// should be logged by GRPCServerLog.
type OptionalLogging interface {
ShouldLog(ctx context.Context, duration time.Duration) bool
ShouldLog(ctx context.Context) bool
}

type DoNotLogError struct{ Err error }

func (i DoNotLogError) Error() string { return i.Err.Error() }
func (i DoNotLogError) Unwrap() error { return i.Err }
func (i DoNotLogError) ShouldLog(_ context.Context, _ time.Duration) bool { return false }
func (i DoNotLogError) Error() string { return i.Err.Error() }
func (i DoNotLogError) Unwrap() error { return i.Err }
func (i DoNotLogError) ShouldLog(_ context.Context) bool { return false }

// GRPCServerLog logs grpc requests, errors, and latency.
type GRPCServerLog struct {
Expand All @@ -51,7 +52,7 @@ func (s GRPCServerLog) UnaryServerInterceptor(ctx context.Context, req interface
return resp, nil
}
var optional OptionalLogging
if errors.As(err, &optional) && !optional.ShouldLog(ctx, time.Since(begin)) {
if errors.As(err, &optional) && !optional.ShouldLog(ctx) {
return resp, err
}

Expand Down
7 changes: 3 additions & 4 deletions middleware/grpc_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"errors"
"testing"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand Down Expand Up @@ -37,9 +36,9 @@ func BenchmarkGRPCServerLog_UnaryServerInterceptor_NoError(b *testing.B) {

type doNotLogError struct{ Err error }

func (i doNotLogError) Error() string { return i.Err.Error() }
func (i doNotLogError) Unwrap() error { return i.Err }
func (i doNotLogError) ShouldLog(_ context.Context, _ time.Duration) bool { return false }
func (i doNotLogError) Error() string { return i.Err.Error() }
func (i doNotLogError) Unwrap() error { return i.Err }
func (i doNotLogError) ShouldLog(_ context.Context) bool { return false }

func TestGrpcLogging(t *testing.T) {
ctx := context.Background()
Expand Down