Skip to content

Commit

Permalink
contrib/google.golang.org/grpc.v12: replace missing {From,New}Context…
Browse files Browse the repository at this point in the history
… with equivalent functions (#2624)
  • Loading branch information
darccio authored Mar 26, 2024
1 parent ceb3d7a commit 00882a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/unit-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,26 @@ jobs:
- name: Testing outlier gRPC v1.2
run: |
# This hacky approach is necessary because running the tests regularly
# do not allow using [email protected] alongside [email protected]
# do not allow using [email protected] alongside [email protected].
# [email protected] is no longer possible to test because internal/datastreams/propagator.go
# expects sketches-go to have the package `github.com/DataDog/sketches-go/ddsketch/encoding` which
# is only present from v1.1.0 onwards.
go mod vendor
# Checkout [email protected]
cd vendor/google.golang.org && rm -rf grpc
git clone https://github.com/grpc/grpc-go grpc && cd grpc
git fetch origin && git checkout v1.2.0 && cd ../..
git fetch origin && git checkout v1.2.0 && cd ../../..
# Checkout sketches-go@v1.0.0
# Checkout sketches-go@v1.1.0
cd vendor/github.com/DataDog && rm -rf sketches-go
git clone https://github.com/DataDog/sketches-go && cd sketches-go
git fetch origin && git checkout v1.0.0 && cd ../..
git fetch origin && git checkout v1.1.0 && cd ../../../..
# Revert to old metadata functions as FromIncomingContext and NewOutgoingContext are not present in v1.2.0.
# These functions were updated to current versions to avoid compilation errors in the development environments.
sed -i 's/metadata\.FromIncomingContext/metadata.FromContext/g' ./contrib/google.golang.org/grpc.v12/*
sed -i 's/metadata\.NewOutgoingContext/metadata.NewContext/g' ./contrib/google.golang.org/grpc.v12/*
go test -mod=vendor -v ./contrib/google.golang.org/grpc.v12/...
Expand Down
6 changes: 3 additions & 3 deletions contrib/google.golang.org/grpc.v12/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func startServerSpanFromContext(ctx context.Context, method string, cfg *interce
// we will add the items in extraOpts
optsLocal := options.Copy(cfg.spanOpts...)
optsLocal = append(optsLocal, extraOpts...)
md, _ := metadata.FromContext(ctx) // nil is ok
md, _ := metadata.FromIncomingContext(ctx) // nil is ok
if sctx, err := tracer.Extract(grpcutil.MDCarrier(md)); err == nil {
optsLocal = append(optsLocal, tracer.ChildOf(sctx))
}
Expand Down Expand Up @@ -108,12 +108,12 @@ func UnaryClientInterceptor(opts ...InterceptorOption) grpc.UnaryClientIntercept
tracer.Tag(ext.GRPCFullMethod, method),
)
span, ctx = tracer.StartSpanFromContext(ctx, cfg.spanName, spanopts...)
md, ok := metadata.FromContext(ctx)
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
md = metadata.MD{}
}
_ = tracer.Inject(span.Context(), grpcutil.MDCarrier(md))
ctx = metadata.NewContext(ctx, md)
ctx = metadata.NewOutgoingContext(ctx, md)
opts = append(opts, grpc.Peer(&p))
err := invoker(ctx, method, req, reply, cc, opts...)
if p.Addr != nil {
Expand Down

0 comments on commit 00882a7

Please sign in to comment.