Skip to content

Commit

Permalink
Merge branch 'master' into pincontrib
Browse files Browse the repository at this point in the history
  • Loading branch information
daixiang0 authored Jan 16, 2023
2 parents 98e54ce + d03a32d commit 7b0d373
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/grpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sort"
"strconv"
"sync"
"sync/atomic"
"time"

otelTrace "go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -407,13 +408,24 @@ type invokeServiceResp struct {
trailers metadata.MD
}

// These flags are used to make sure that we are printing the deprecation warning log messages in "InvokeService" just once.
// By using "CompareAndSwap(false, true)" we replace the value "false" with "true" only if it's not already "true".
// "CompareAndSwap" returns true if the swap happened (i.e. if the value was not already "true"), so we can use that as a flag to make sure we only run the code once.
// Why not using "sync.Once"? In our tests (https://github.com/dapr/dapr/pull/5740), that seems to be causing a regression in the perf tests. This is probably because when using "sync.Once" and the callback needs to be executed for the first time, all concurrent requests are blocked too. Additionally, the use of closures in this case _could_ have an impact on the GC as well.
var (
invokeServiceDeprecationNoticeShown = atomic.Bool{}
invokeServiceHTTPDeprecationNoticeShown = atomic.Bool{}
)

// Deprecated: Use proxy mode service invocation instead.
func (a *api) InvokeService(ctx context.Context, in *runtimev1pb.InvokeServiceRequest) (*commonv1pb.InvokeResponse, error) {
if a.directMessaging == nil {
return nil, status.Errorf(codes.Internal, messages.ErrDirectInvokeNotReady)
}

apiServerLogger.Warn("[DEPRECATION NOTICE] InvokeService is deprecated and will be removed in the future, please use proxy mode instead.")
if invokeServiceDeprecationNoticeShown.CompareAndSwap(false, true) {
apiServerLogger.Warn("[DEPRECATION NOTICE] InvokeService is deprecated and will be removed in the future, please use proxy mode instead.")
}
policyDef := a.resiliency.EndpointPolicy(in.Id, in.Id+":"+in.Message.Method)

req := invokev1.FromInvokeRequestMessage(in.GetMessage())
Expand Down Expand Up @@ -450,7 +462,9 @@ func (a *api) InvokeService(ctx context.Context, in *runtimev1pb.InvokeServiceRe
rResp.headers = invokev1.InternalMetadataToGrpcMetadata(ctx, imr.Headers(), true)

if imr.IsHTTPResponse() {
apiServerLogger.Warn("[DEPRECATION NOTICE] Invocation path of gRPC -> HTTP is deprecated and will be removed in the future.")
if invokeServiceHTTPDeprecationNoticeShown.CompareAndSwap(false, true) {
apiServerLogger.Warn("[DEPRECATION NOTICE] Invocation path of gRPC -> HTTP is deprecated and will be removed in the future.")
}
var errorMessage string
if rResp.message != nil && rResp.message.Data != nil {
errorMessage = string(rResp.message.Data.Value)
Expand Down

0 comments on commit 7b0d373

Please sign in to comment.