Skip to content

Commit 1a9862c

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 6b002a5 commit 1a9862c

File tree

8 files changed

+15
-50
lines changed

8 files changed

+15
-50
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-2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@ func NewServer(initConstants plugin.CMPServerInitConstants) (*ArgoCDCMPServer, e
5050

5151
serverLog := log.NewEntry(log.StandardLogger())
5252
streamInterceptors := []grpc.StreamServerInterceptor{
53-
otelgrpc.StreamServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
5453
grpc_logrus.StreamServerInterceptor(serverLog),
5554
serverMetrics.StreamServerInterceptor(),
5655
grpc_util.PanicLoggerStreamServerInterceptor(serverLog),
5756
}
5857
unaryInterceptors := []grpc.UnaryServerInterceptor{
59-
otelgrpc.UnaryServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
6058
grpc_logrus.UnaryServerInterceptor(serverLog),
6159
serverMetrics.UnaryServerInterceptor(),
6260
grpc_util.PanicLoggerUnaryServerInterceptor(serverLog),
@@ -72,6 +70,7 @@ func NewServer(initConstants plugin.CMPServerInitConstants) (*ArgoCDCMPServer, e
7270
MinTime: common.GetGRPCKeepAliveEnforcementMinimum(),
7371
},
7472
),
73+
grpc.StatsHandler(otelgrpc.NewServerHandler()),
7574
}
7675

7776
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-2
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,11 @@ func NewServer(metricsServer *metrics.MetricsServer, cache *reposervercache.Cach
7474

7575
serverLog := log.NewEntry(log.StandardLogger())
7676
streamInterceptors := []grpc.StreamServerInterceptor{
77-
otelgrpc.StreamServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
7877
grpc_logrus.StreamServerInterceptor(serverLog),
7978
serverMetrics.StreamServerInterceptor(),
8079
grpc_util.PanicLoggerStreamServerInterceptor(serverLog),
8180
}
8281
unaryInterceptors := []grpc.UnaryServerInterceptor{
83-
otelgrpc.UnaryServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
8482
grpc_logrus.UnaryServerInterceptor(serverLog),
8583
serverMetrics.UnaryServerInterceptor(),
8684
grpc_util.PanicLoggerUnaryServerInterceptor(serverLog),
@@ -97,6 +95,7 @@ func NewServer(metricsServer *metrics.MetricsServer, cache *reposervercache.Cach
9795
MinTime: common.GetGRPCKeepAliveEnforcementMinimum(),
9896
},
9997
),
98+
grpc.StatsHandler(otelgrpc.NewServerHandler()),
10099
}
101100

102101
// 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

+5-6
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,
@@ -933,9 +932,8 @@ func (server *ArgoCDServer) newGRPCServer() (*grpc.Server, application.AppResour
933932
// NOTE: notice we do not configure the gRPC server here with TLS (e.g. grpc.Creds(creds))
934933
// This is because TLS handshaking occurs in cmux handling
935934
sOpts = append(sOpts, grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
936-
otelgrpc.StreamServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
937935
grpc_logrus.StreamServerInterceptor(server.log),
938-
serverMetrics.StreamServerInterceptor(),
936+
grpc_prometheus.StreamServerInterceptor,
939937
grpc_auth.StreamServerInterceptor(server.Authenticate),
940938
grpc_util.UserAgentStreamServerInterceptor(common.ArgoCDUserAgentName, clientConstraint),
941939
grpc_util.PayloadStreamServerInterceptor(server.log, true, func(_ context.Context, fullMethodName string, _ any) bool {
@@ -947,9 +945,8 @@ func (server *ArgoCDServer) newGRPCServer() (*grpc.Server, application.AppResour
947945
)))
948946
sOpts = append(sOpts, grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
949947
bug21955WorkaroundInterceptor,
950-
otelgrpc.UnaryServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
951948
grpc_logrus.UnaryServerInterceptor(server.log),
952-
serverMetrics.UnaryServerInterceptor(),
949+
grpc_prometheus.UnaryServerInterceptor,
953950
grpc_auth.UnaryServerInterceptor(server.Authenticate),
954951
grpc_util.UserAgentUnaryServerInterceptor(common.ArgoCDUserAgentName, clientConstraint),
955952
grpc_util.PayloadUnaryServerInterceptor(server.log, true, func(_ context.Context, fullMethodName string, _ any) bool {
@@ -959,6 +956,8 @@ func (server *ArgoCDServer) newGRPCServer() (*grpc.Server, application.AppResour
959956
grpc_util.ErrorCodeGitUnaryServerInterceptor(),
960957
grpc_util.PanicLoggerUnaryServerInterceptor(server.log),
961958
)))
959+
sOpts = append(sOpts, grpc.StatsHandler(otelgrpc.NewServerHandler()))
960+
962961
grpcS := grpc.NewServer(sOpts...)
963962

964963
versionpkg.RegisterVersionServiceServer(grpcS, server.serviceSet.VersionService)

util/grpc/trace.go

-33
This file was deleted.

0 commit comments

Comments
 (0)