Skip to content

Commit 9e03229

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 b0024d1 commit 9e03229

File tree

8 files changed

+14
-50
lines changed

8 files changed

+14
-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
@@ -47,13 +47,11 @@ func NewServer(initConstants plugin.CMPServerInitConstants) (*ArgoCDCMPServer, e
4747

4848
serverLog := log.NewEntry(log.StandardLogger())
4949
streamInterceptors := []grpc.StreamServerInterceptor{
50-
otelgrpc.StreamServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
5150
grpc_logrus.StreamServerInterceptor(serverLog),
5251
grpc_prometheus.StreamServerInterceptor,
5352
grpc_util.PanicLoggerStreamServerInterceptor(serverLog),
5453
}
5554
unaryInterceptors := []grpc.UnaryServerInterceptor{
56-
otelgrpc.UnaryServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
5755
grpc_logrus.UnaryServerInterceptor(serverLog),
5856
grpc_prometheus.UnaryServerInterceptor,
5957
grpc_util.PanicLoggerUnaryServerInterceptor(serverLog),
@@ -69,6 +67,7 @@ func NewServer(initConstants plugin.CMPServerInitConstants) (*ArgoCDCMPServer, e
6967
MinTime: common.GetGRPCKeepAliveEnforcementMinimum(),
7068
},
7169
),
70+
grpc.StatsHandler(otelgrpc.NewServerHandler()),
7271
}
7372

7473
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"
@@ -520,8 +521,7 @@ func (c *client) newConn() (*grpc.ClientConn, io.Closer, error) {
520521
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)))
521522
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)))
522523
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(grpc_retry.UnaryClientInterceptor(retryOpts...))))
523-
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(grpc_util.OTELUnaryClientInterceptor()))
524-
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpc_util.OTELStreamClientInterceptor()))
524+
dialOpts = append(dialOpts, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
525525

526526
ctx := context.Background()
527527

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import (
66
"os"
77
"path/filepath"
88

9-
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
10-
119
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
1210
grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
1311
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
1412
log "github.com/sirupsen/logrus"
13+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
1514
"google.golang.org/grpc"
1615
"google.golang.org/grpc/credentials"
1716
"google.golang.org/grpc/health"
@@ -70,13 +69,11 @@ func NewServer(metricsServer *metrics.MetricsServer, cache *reposervercache.Cach
7069

7170
serverLog := log.NewEntry(log.StandardLogger())
7271
streamInterceptors := []grpc.StreamServerInterceptor{
73-
otelgrpc.StreamServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
7472
grpc_logrus.StreamServerInterceptor(serverLog),
7573
grpc_prometheus.StreamServerInterceptor,
7674
grpc_util.PanicLoggerStreamServerInterceptor(serverLog),
7775
}
7876
unaryInterceptors := []grpc.UnaryServerInterceptor{
79-
otelgrpc.UnaryServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
8077
grpc_logrus.UnaryServerInterceptor(serverLog),
8178
grpc_prometheus.UnaryServerInterceptor,
8279
grpc_util.PanicLoggerUnaryServerInterceptor(serverLog),
@@ -93,6 +90,7 @@ func NewServer(metricsServer *metrics.MetricsServer, cache *reposervercache.Cach
9390
MinTime: common.GetGRPCKeepAliveEnforcementMinimum(),
9491
},
9592
),
93+
grpc.StatsHandler(otelgrpc.NewServerHandler()),
9694
}
9795

9896
// 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
@@ -19,6 +19,7 @@ import (
1919
"github.com/argoproj/gitops-engine/pkg/utils/text"
2020
"github.com/argoproj/pkg/sync"
2121
jsonpatch "github.com/evanphx/json-patch"
22+
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
2223
log "github.com/sirupsen/logrus"
2324
"google.golang.org/grpc/codes"
2425
"google.golang.org/grpc/status"
@@ -647,7 +648,7 @@ func (s *Server) GetManifestsWithFiles(stream application.ApplicationService_Get
647648
ProjectSourceRepos: proj.Spec.SourceRepos,
648649
}
649650

650-
repoStreamClient, err := client.GenerateManifestWithFiles(stream.Context())
651+
repoStreamClient, err := client.GenerateManifestWithFiles(stream.Context(), grpc_retry.Disable())
651652
if err != nil {
652653
return fmt.Errorf("error opening stream: %w", err)
653654
}

server/server.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,7 @@ func (a *ArgoCDServer) Listen() (*Listeners, error) {
472472
var dOpts []grpc.DialOption
473473
dOpts = append(dOpts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(apiclient.MaxGRPCMessageSize)))
474474
dOpts = append(dOpts, grpc.WithUserAgent(fmt.Sprintf("%s/%s", common.ArgoCDUserAgentName, common.GetVersion().Version)))
475-
dOpts = append(dOpts, grpc.WithUnaryInterceptor(grpc_util.OTELUnaryClientInterceptor()))
476-
dOpts = append(dOpts, grpc.WithStreamInterceptor(grpc_util.OTELStreamClientInterceptor()))
475+
dOpts = append(dOpts, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
477476
if a.useTLS() {
478477
// The following sets up the dial Options for grpc-gateway to talk to gRPC server over TLS.
479478
// grpc-gateway is just translating HTTP/HTTPS requests as gRPC requests over localhost,
@@ -787,7 +786,6 @@ func (a *ArgoCDServer) newGRPCServer() (*grpc.Server, application.AppResourceTre
787786
// NOTE: notice we do not configure the gRPC server here with TLS (e.g. grpc.Creds(creds))
788787
// This is because TLS handshaking occurs in cmux handling
789788
sOpts = append(sOpts, grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
790-
otelgrpc.StreamServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
791789
grpc_logrus.StreamServerInterceptor(a.log),
792790
grpc_prometheus.StreamServerInterceptor,
793791
grpc_auth.StreamServerInterceptor(a.Authenticate),
@@ -801,7 +799,6 @@ func (a *ArgoCDServer) newGRPCServer() (*grpc.Server, application.AppResourceTre
801799
)))
802800
sOpts = append(sOpts, grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
803801
bug21955WorkaroundInterceptor,
804-
otelgrpc.UnaryServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
805802
grpc_logrus.UnaryServerInterceptor(a.log),
806803
grpc_prometheus.UnaryServerInterceptor,
807804
grpc_auth.UnaryServerInterceptor(a.Authenticate),
@@ -813,6 +810,8 @@ func (a *ArgoCDServer) newGRPCServer() (*grpc.Server, application.AppResourceTre
813810
grpc_util.ErrorCodeGitUnaryServerInterceptor(),
814811
grpc_util.PanicLoggerUnaryServerInterceptor(a.log),
815812
)))
813+
sOpts = append(sOpts, grpc.StatsHandler(otelgrpc.NewServerHandler()))
814+
816815
grpcS := grpc.NewServer(sOpts...)
817816

818817
versionpkg.RegisterVersionServiceServer(grpcS, a.serviceSet.VersionService)

util/grpc/trace.go

-33
This file was deleted.

0 commit comments

Comments
 (0)