Skip to content

Commit de20c41

Browse files
chore(migrate): otelgrpc stats handler migrate
migrate cmdserver, server, pkg/apiclient, reposerver - server - migrate ServerInterceptor -> NewServerHandler - client - migrate ClientInterceptor -> NewClientHandler fix server/application - add ClientStream GenerateManfiestWithFiles retry.Disable() remove util/grpc/trace - remvoe util/grpc/trace.go Signed-off-by: Jack-R-lantern <[email protected]>
1 parent 1eeaab4 commit de20c41

File tree

10 files changed

+15
-44
lines changed

10 files changed

+15
-44
lines changed

cmpserver/apiclient/clientset.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
1212
log "github.com/sirupsen/logrus"
13+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
1314
"google.golang.org/grpc"
1415
"google.golang.org/grpc/credentials/insecure"
1516

@@ -47,8 +48,7 @@ func NewConnection(address string) (*grpc.ClientConn, error) {
4748
grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)),
4849
grpc.WithChainUnaryInterceptor(unaryInterceptors...),
4950
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)),
50-
grpc.WithUnaryInterceptor(grpc_util.OTELUnaryClientInterceptor()),
51-
grpc.WithStreamInterceptor(grpc_util.OTELStreamClientInterceptor()),
51+
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
5252
}
5353

5454
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))

cmpserver/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func NewServer(initConstants plugin.CMPServerInitConstants) (*ArgoCDCMPServer, e
7272
MinTime: common.GetGRPCKeepAliveEnforcementMinimum(),
7373
},
7474
),
75+
grpc.StatsHandler(otelgrpc.NewServerHandler()),
7576
}
7677

7778
return &ArgoCDCMPServer{

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ require (
5353
github.com/gorilla/handlers v1.5.2
5454
github.com/gorilla/websocket v1.5.3
5555
github.com/gosimple/slug v1.15.0
56+
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
5657
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
5758
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.1
5859
github.com/grpc-ecosystem/grpc-gateway v1.16.0

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ github.com/gregdel/pushover v1.3.1/go.mod h1:EcaO66Nn1StkpEm1iKtBTV3d2A16SoMsVER
463463
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA=
464464
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
465465
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI=
466+
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw=
467+
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y=
466468
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 h1:qnpSQwGEnkcRpTqNOIR6bJbR0gAorgP9CSALpRcKoAA=
467469
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1/go.mod h1:lXGCsh6c22WGtjr+qGHj1otzZpV/1kwTMAqkwZsnWRU=
468470
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.1 h1:KcFzXwzM/kGhIRHvc8jdixfIJjVzuUJdnv+5xsPutog=

pkg/apiclient/apiclient.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
2222
"github.com/hashicorp/go-retryablehttp"
2323
log "github.com/sirupsen/logrus"
24+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
2425
"golang.org/x/oauth2"
2526
"google.golang.org/grpc"
2627
"google.golang.org/grpc/codes"
@@ -522,10 +523,9 @@ func (c *client) newConn() (*grpc.ClientConn, io.Closer, error) {
522523
var dialOpts []grpc.DialOption
523524
dialOpts = append(dialOpts, grpc.WithPerRPCCredentials(endpointCredentials))
524525
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)))
525-
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)))
526+
// dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)))
526527
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(grpc_retry.UnaryClientInterceptor(retryOpts...)))
527-
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(grpc_util.OTELUnaryClientInterceptor()))
528-
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpc_util.OTELStreamClientInterceptor()))
528+
dialOpts = append(dialOpts, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
529529

530530
ctx := context.Background()
531531

reposerver/apiclient/clientset.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
1414
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/timeout"
1515
log "github.com/sirupsen/logrus"
16+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
1617
"google.golang.org/grpc"
1718
"google.golang.org/grpc/credentials"
1819
"google.golang.org/grpc/credentials/insecure"
1920

20-
argogrpc "github.com/argoproj/argo-cd/v3/util/grpc"
2121
"github.com/argoproj/argo-cd/v3/util/io"
2222
)
2323

@@ -66,8 +66,7 @@ func NewConnection(address string, timeoutSeconds int, tlsConfig *TLSConfigurati
6666
grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)),
6767
grpc.WithChainUnaryInterceptor(unaryInterceptors...),
6868
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)),
69-
grpc.WithUnaryInterceptor(argogrpc.OTELUnaryClientInterceptor()),
70-
grpc.WithStreamInterceptor(argogrpc.OTELStreamClientInterceptor()),
69+
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
7170
}
7271

7372
tlsC := &tls.Config{}

reposerver/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func NewServer(metricsServer *metrics.MetricsServer, cache *reposervercache.Cach
9797
MinTime: common.GetGRPCKeepAliveEnforcementMinimum(),
9898
},
9999
),
100+
grpc.StatsHandler(otelgrpc.NewServerHandler()),
100101
}
101102

102103
// We do allow for non-TLS servers to be created, in case of mTLS will be

server/application/application.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/argoproj/gitops-engine/pkg/utils/text"
2424
"github.com/argoproj/pkg/sync"
2525
jsonpatch "github.com/evanphx/json-patch"
26+
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
2627
log "github.com/sirupsen/logrus"
2728
"google.golang.org/grpc/codes"
2829
"google.golang.org/grpc/status"
@@ -669,7 +670,7 @@ func (s *Server) GetManifestsWithFiles(stream application.ApplicationService_Get
669670
AnnotationManifestGeneratePaths: a.GetAnnotation(v1alpha1.AnnotationKeyManifestGeneratePaths),
670671
}
671672

672-
repoStreamClient, err := client.GenerateManifestWithFiles(stream.Context())
673+
repoStreamClient, err := client.GenerateManifestWithFiles(stream.Context(), grpc_retry.Disable())
673674
if err != nil {
674675
return fmt.Errorf("error opening stream: %w", err)
675676
}

server/server.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,7 @@ func (server *ArgoCDServer) Listen() (*Listeners, error) {
506506
var dOpts []grpc.DialOption
507507
dOpts = append(dOpts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(apiclient.MaxGRPCMessageSize)))
508508
dOpts = append(dOpts, grpc.WithUserAgent(fmt.Sprintf("%s/%s", common.ArgoCDUserAgentName, common.GetVersion().Version)))
509-
dOpts = append(dOpts, grpc.WithUnaryInterceptor(grpc_util.OTELUnaryClientInterceptor()))
510-
dOpts = append(dOpts, grpc.WithStreamInterceptor(grpc_util.OTELStreamClientInterceptor()))
509+
dOpts = append(dOpts, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
511510
if server.useTLS() {
512511
// The following sets up the dial Options for grpc-gateway to talk to gRPC server over TLS.
513512
// grpc-gateway is just translating HTTP/HTTPS requests as gRPC requests over localhost,

util/grpc/trace.go

-33
This file was deleted.

0 commit comments

Comments
 (0)