Skip to content

Commit 5a2cc73

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 bd1018a commit 5a2cc73

File tree

8 files changed

+11
-42
lines changed

8 files changed

+11
-42
lines changed

cmpserver/apiclient/clientset.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
1212
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
1313
log "github.com/sirupsen/logrus"
14+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
1415
"google.golang.org/grpc"
1516
"google.golang.org/grpc/credentials/insecure"
1617

@@ -48,8 +49,7 @@ func NewConnection(address string) (*grpc.ClientConn, error) {
4849
grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)),
4950
grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(unaryInterceptors...)),
5051
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)),
51-
grpc.WithUnaryInterceptor(grpc_util.OTELUnaryClientInterceptor()),
52-
grpc.WithStreamInterceptor(grpc_util.OTELStreamClientInterceptor()),
52+
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
5353
}
5454

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

cmpserver/server.go

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

7677
return &ArgoCDCMPServer{

pkg/apiclient/apiclient.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
2323
"github.com/hashicorp/go-retryablehttp"
2424
log "github.com/sirupsen/logrus"
25+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
2526
"golang.org/x/oauth2"
2627
"google.golang.org/grpc"
2728
"google.golang.org/grpc/codes"
@@ -524,8 +525,7 @@ func (c *client) newConn() (*grpc.ClientConn, io.Closer, error) {
524525
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)))
525526
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)))
526527
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(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-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
1414
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
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"
@@ -66,8 +67,7 @@ func NewConnection(address string, timeoutSeconds int, tlsConfig *TLSConfigurati
6667
grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)),
6768
grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(unaryInterceptors...)),
6869
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)),
69-
grpc.WithUnaryInterceptor(argogrpc.OTELUnaryClientInterceptor()),
70-
grpc.WithStreamInterceptor(argogrpc.OTELStreamClientInterceptor()),
70+
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
7171
}
7272

7373
tlsC := &tls.Config{}

reposerver/server.go

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

101102
// 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"
@@ -675,7 +676,7 @@ func (s *Server) GetManifestsWithFiles(stream application.ApplicationService_Get
675676
AnnotationManifestGeneratePaths: a.GetAnnotation(v1alpha1.AnnotationKeyManifestGeneratePaths),
676677
}
677678

678-
repoStreamClient, err := client.GenerateManifestWithFiles(stream.Context())
679+
repoStreamClient, err := client.GenerateManifestWithFiles(stream.Context(), grpc_retry.Disable())
679680
if err != nil {
680681
return fmt.Errorf("error opening stream: %w", err)
681682
}

server/server.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,7 @@ func (server *ArgoCDServer) Listen() (*Listeners, error) {
505505
var dOpts []grpc.DialOption
506506
dOpts = append(dOpts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(apiclient.MaxGRPCMessageSize)))
507507
dOpts = append(dOpts, grpc.WithUserAgent(fmt.Sprintf("%s/%s", common.ArgoCDUserAgentName, common.GetVersion().Version)))
508-
dOpts = append(dOpts, grpc.WithUnaryInterceptor(grpc_util.OTELUnaryClientInterceptor()))
509-
dOpts = append(dOpts, grpc.WithStreamInterceptor(grpc_util.OTELStreamClientInterceptor()))
508+
dOpts = append(dOpts, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
510509
if server.useTLS() {
511510
// The following sets up the dial Options for grpc-gateway to talk to gRPC server over TLS.
512511
// 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)