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

Update provider/kit #490

Merged
merged 2 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
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
24 changes: 9 additions & 15 deletions providers/kit/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ package kit_test
import (
"context"
"testing"
"time"

"github.com/go-kit/log"
"github.com/grpc-ecosystem/go-grpc-middleware/providers/kit/v2"
"google.golang.org/grpc"

"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/tags"
"google.golang.org/grpc"
)

var (
Expand Down Expand Up @@ -51,7 +50,6 @@ func Example_initializationWithDurationFieldOverride() {
logging.UnaryServerInterceptor(kit.InterceptorLogger(logger), opts...),
),
grpc.ChainStreamInterceptor(
tags.StreamServerInterceptor(),
logging.StreamServerInterceptor(kit.InterceptorLogger(logger), opts...),
),
)
Expand All @@ -63,11 +61,9 @@ func Example_initializationWithCodeGenRequestFieldExtractor() {
// Create a server, make sure we put the tags context before everything else.
_ = grpc.NewServer(
grpc.ChainUnaryInterceptor(
tags.UnaryServerInterceptor(tags.WithFieldExtractor(tags.CodeGenRequestFieldExtractor)),
logging.UnaryServerInterceptor(kit.InterceptorLogger(logger)),
),
grpc.ChainStreamInterceptor(
tags.StreamServerInterceptor(tags.WithFieldExtractor(tags.CodeGenRequestFieldExtractor)),
logging.StreamServerInterceptor(kit.InterceptorLogger(logger)),
),
)
Expand All @@ -78,7 +74,7 @@ func ExampleWithDecider() {
logger := log.NewNopLogger()
// Shared options for the logger, with a custom decider that log everything except successful calls from "/blah.foo.healthcheck/Check" method.
opts := []logging.Option{
logging.WithDecider(func(methodFullName string) logging.Decision {
logging.WithDecider(func(methodFullName string, err error) logging.Decision {
// will not log gRPC calls if it was a call to healthcheck and no error was raised
if methodFullName == "/blah.foo.healthcheck/Check" {
return logging.NoLogCall
Expand All @@ -90,11 +86,9 @@ func ExampleWithDecider() {
// Create a server, make sure we put the tags context before everything else.
_ = []grpc.ServerOption{
grpc.ChainUnaryInterceptor(
tags.UnaryServerInterceptor(),
logging.UnaryServerInterceptor(kit.InterceptorLogger(logger), opts...),
),
grpc.ChainStreamInterceptor(
tags.StreamServerInterceptor(),
logging.StreamServerInterceptor(kit.InterceptorLogger(logger), opts...),
),
}
Expand All @@ -104,21 +98,21 @@ func ExampleServerPayloadLoggingDecider() {
// Logger is used, allowing pre-definition of certain fields by the user.
logger := log.NewNopLogger()
// Expect payload from "/blah.foo.healthcheck/Check" call to be logged.
payloadDecider := func(ctx context.Context, fullMethodName string, servingObject interface{}) bool {
return fullMethodName == "/blah.foo.healthcheck/Check"
payloadDecider := func(ctx context.Context, fullMethodName string, servingObject interface{}) logging.PayloadDecision {
// return fullMethodName == "/blah.foo.healthcheck/Check"
// TODO Fix
return 0
}

// Create a server, make sure we put the tags context before everything else.
_ = []grpc.ServerOption{
grpc.ChainUnaryInterceptor(
tags.UnaryServerInterceptor(),
logging.UnaryServerInterceptor(kit.InterceptorLogger(logger)),
logging.PayloadUnaryServerInterceptor(kit.InterceptorLogger(logger), payloadDecider),
logging.PayloadUnaryServerInterceptor(kit.InterceptorLogger(logger), payloadDecider, time.RFC3339Nano),
),
grpc.ChainStreamInterceptor(
tags.StreamServerInterceptor(),
logging.StreamServerInterceptor(kit.InterceptorLogger(logger)),
logging.PayloadStreamServerInterceptor(kit.InterceptorLogger(logger), payloadDecider),
logging.PayloadStreamServerInterceptor(kit.InterceptorLogger(logger), payloadDecider, time.RFC3339Nano),
),
}
}
Expand Down
9 changes: 7 additions & 2 deletions providers/kit/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ module github.com/grpc-ecosystem/go-grpc-middleware/providers/kit/v2
go 1.14

require (
github.com/go-kit/log v0.1.0
github.com/go-kit/log v0.2.0
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20201002093600-73cf2ae9d891
google.golang.org/grpc v1.30.0
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd // indirect
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f // indirect
google.golang.org/genproto v0.0.0-20220401170504-314d38edb7de // indirect
google.golang.org/grpc v1.45.0
)

replace github.com/grpc-ecosystem/go-grpc-middleware/v2 => ../..
Loading