Skip to content

Commit 834db0f

Browse files
elekStorj Robot
authored and
Storj Robot
committed
peertls/tlsopts: disable distributed tracing for verifyIdentity
verifyIdentity uses default, un-parented context, therefore it doesn't make sense to include in distributed traces, it just increases the noise. To avoid circurlar dependency, this requires to move the excluded.go to a separated package (tracing), but for backward-compatility, a deprecated version is also kept. Majority of this commit is just package rename. The real change is in `peertls/tlsopts/tls.go` (2 lines). storj/storj#5722 Change-Id: I6b48f788998adb414f0bd86f6a434fbb6eb1214d
1 parent 9c59714 commit 834db0f

File tree

6 files changed

+45
-18
lines changed

6 files changed

+45
-18
lines changed

peertls/tlsopts/tls.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
package tlsopts
55

66
import (
7+
"context"
78
"crypto/tls"
89
"crypto/x509"
910

1011
"storj.io/common/identity"
1112
"storj.io/common/peertls"
1213
"storj.io/common/storj"
14+
"storj.io/common/tracing"
1315
)
1416

1517
// StorjApplicationProtocol defines storj's application protocol.
@@ -76,7 +78,8 @@ func (opts *Options) tlsConfig(isServer bool, verificationFuncs ...peertls.PeerC
7678

7779
func verifyIdentity(id storj.NodeID) peertls.PeerCertVerificationFunc {
7880
return func(_ [][]byte, parsedChains [][]*x509.Certificate) (err error) {
79-
defer mon.TaskNamed("verifyIdentity")(nil)(&err)
81+
ctx := tracing.WithoutDistributedTracing(context.Background())
82+
defer mon.TaskNamed("verifyIdentity")(&ctx)(&err)
8083
peer, err := identity.PeerIdentityFromChain(parsedChains[0])
8184
if err != nil {
8285
return err

rpc/rpctracing/excluded.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,18 @@ import (
77
"context"
88

99
"github.com/spacemonkeygo/monkit/v3"
10-
)
11-
12-
type contextKey int
1310

14-
var (
15-
excludeFromTracing contextKey = 1
11+
"storj.io/common/tracing"
1612
)
1713

1814
// WithoutDistributedTracing disables distributed tracing for the current span.
15+
// Deprecated: use tracing.WithoutDistributedTracing.
1916
func WithoutDistributedTracing(ctx context.Context) context.Context {
20-
return context.WithValue(ctx, excludeFromTracing, true)
17+
return tracing.WithoutDistributedTracing(ctx)
2118
}
2219

2320
// IsExcluded check if span shouldn't be reported to remote location.
21+
// Deprecated: use tracing.IsExcluded.
2422
func IsExcluded(span *monkit.Span) bool {
25-
val, ok := span.Value(excludeFromTracing).(bool)
26-
return ok && val
23+
return tracing.IsExcluded(span)
2724
}

signing/encode.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"context"
88

99
"storj.io/common/pb"
10-
"storj.io/common/rpc/rpctracing"
10+
"storj.io/common/tracing"
1111
)
1212

1313
// EncodeOrderLimit encodes order limit into bytes for signing. Removes signature from serialized limit.
@@ -52,7 +52,7 @@ func EncodeOrderLimit(ctx context.Context, limit *pb.OrderLimit) (_ []byte, err
5252

5353
// EncodeOrder encodes order into bytes for signing. Removes signature from serialized order.
5454
func EncodeOrder(ctx context.Context, order *pb.Order) (_ []byte, err error) {
55-
ctx = rpctracing.WithoutDistributedTracing(ctx)
55+
ctx = tracing.WithoutDistributedTracing(ctx)
5656
defer mon.Task()(&ctx)(&err)
5757

5858
// protobuf has problems with serializing types with nullable=false

signing/sign.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/zeebo/errs"
1010

1111
"storj.io/common/pb"
12-
"storj.io/common/rpc/rpctracing"
1312
"storj.io/common/storj"
13+
"storj.io/common/tracing"
1414
)
1515

1616
// Error is the default error class for signing package.
@@ -46,7 +46,7 @@ func SignOrderLimit(ctx context.Context, satellite Signer, unsigned *pb.OrderLim
4646
// SignUplinkOrder signs the order using the specified signer.
4747
// Signer is an uplink.
4848
func SignUplinkOrder(ctx context.Context, privateKey storj.PiecePrivateKey, unsigned *pb.Order) (_ *pb.Order, err error) {
49-
ctx = rpctracing.WithoutDistributedTracing(ctx)
49+
ctx = tracing.WithoutDistributedTracing(ctx)
5050
defer mon.Task()(&ctx)(&err)
5151

5252
bytes, err := EncodeOrder(ctx, unsigned)

signing/verify.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"context"
88

99
"storj.io/common/pb"
10-
"storj.io/common/rpc/rpctracing"
1110
"storj.io/common/storj"
11+
"storj.io/common/tracing"
1212
)
1313

1414
var verifyOrderLimitSignatureMon = mon.Task()
@@ -21,7 +21,7 @@ type Signee interface {
2121

2222
// VerifyOrderLimitSignature verifies that the signature inside order limit is valid and belongs to the satellite.
2323
func VerifyOrderLimitSignature(ctx context.Context, satellite Signee, signed *pb.OrderLimit) (err error) {
24-
ctx = rpctracing.WithoutDistributedTracing(ctx)
24+
ctx = tracing.WithoutDistributedTracing(ctx)
2525
defer verifyOrderLimitSignatureMon(&ctx)(&err)
2626

2727
bytes, err := EncodeOrderLimit(ctx, signed)
@@ -50,7 +50,7 @@ func VerifyOrderSignature(ctx context.Context, uplink Signee, signed *pb.Order)
5050

5151
// VerifyUplinkOrderSignature verifies that the signature inside order is valid and belongs to the uplink.
5252
func VerifyUplinkOrderSignature(ctx context.Context, publicKey storj.PiecePublicKey, signed *pb.Order) (err error) {
53-
ctx = rpctracing.WithoutDistributedTracing(ctx)
53+
ctx = tracing.WithoutDistributedTracing(ctx)
5454
defer mon.Task()(&ctx)(&err)
5555

5656
if len(signed.XXX_unrecognized) > 0 {
@@ -67,7 +67,7 @@ func VerifyUplinkOrderSignature(ctx context.Context, publicKey storj.PiecePublic
6767

6868
// VerifyPieceHashSignature verifies that the signature inside piece hash is valid and belongs to the signer, which is either uplink or storage node.
6969
func VerifyPieceHashSignature(ctx context.Context, signee Signee, signed *pb.PieceHash) (err error) {
70-
ctx = rpctracing.WithoutDistributedTracing(ctx)
70+
ctx = tracing.WithoutDistributedTracing(ctx)
7171
defer mon.Task()(&ctx)(&err)
7272

7373
if len(signed.XXX_unrecognized) > 0 {
@@ -84,7 +84,7 @@ func VerifyPieceHashSignature(ctx context.Context, signee Signee, signed *pb.Pie
8484

8585
// VerifyUplinkPieceHashSignature verifies that the signature inside piece hash is valid and belongs to the signer, which is either uplink or storage node.
8686
func VerifyUplinkPieceHashSignature(ctx context.Context, publicKey storj.PiecePublicKey, signed *pb.PieceHash) (err error) {
87-
ctx = rpctracing.WithoutDistributedTracing(ctx)
87+
ctx = tracing.WithoutDistributedTracing(ctx)
8888
defer mon.Task()(&ctx)(&err)
8989

9090
if len(signed.XXX_unrecognized) > 0 {

tracing/excluded.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2022 Storj Labs, Inc.
2+
// See LICENSE for copying information.
3+
4+
package tracing
5+
6+
import (
7+
"context"
8+
9+
"github.com/spacemonkeygo/monkit/v3"
10+
)
11+
12+
type contextKey int
13+
14+
var (
15+
excludeFromTracing contextKey = 1
16+
)
17+
18+
// WithoutDistributedTracing disables distributed tracing for the current span.
19+
func WithoutDistributedTracing(ctx context.Context) context.Context {
20+
return context.WithValue(ctx, excludeFromTracing, true)
21+
}
22+
23+
// IsExcluded check if span shouldn't be reported to remote location.
24+
func IsExcluded(span *monkit.Span) bool {
25+
val, ok := span.Value(excludeFromTracing).(bool)
26+
return ok && val
27+
}

0 commit comments

Comments
 (0)