Skip to content

Commit c1e018a

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 9fe1dbf commit c1e018a

File tree

8 files changed

+20
-54
lines changed

8 files changed

+20
-54
lines changed

cmpserver/apiclient/clientset.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package apiclient
22

33
import (
44
"context"
5-
"github.com/argoproj/argo-cd/v2/common"
6-
"github.com/argoproj/argo-cd/v2/util/env"
75
"math"
86
"time"
97

8+
"github.com/argoproj/argo-cd/v2/common"
9+
"github.com/argoproj/argo-cd/v2/util/env"
10+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
11+
1012
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
1113
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
1214
log "github.com/sirupsen/logrus"
@@ -49,8 +51,7 @@ func NewConnection(address string) (*grpc.ClientConn, error) {
4951
grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)),
5052
grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(unaryInterceptors...)),
5153
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)),
52-
grpc.WithUnaryInterceptor(grpc_util.OTELUnaryClientInterceptor()),
53-
grpc.WithStreamInterceptor(grpc_util.OTELStreamClientInterceptor()),
54+
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
5455
}
5556

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

cmpserver/server.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ func NewServer(initConstants plugin.CMPServerInitConstants) (*ArgoCDCMPServer, e
4646

4747
serverLog := log.NewEntry(log.StandardLogger())
4848
streamInterceptors := []grpc.StreamServerInterceptor{
49-
otelgrpc.StreamServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
5049
grpc_logrus.StreamServerInterceptor(serverLog),
5150
grpc_prometheus.StreamServerInterceptor,
5251
grpc_util.PanicLoggerStreamServerInterceptor(serverLog),
5352
}
5453
unaryInterceptors := []grpc.UnaryServerInterceptor{
55-
otelgrpc.UnaryServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
5654
grpc_logrus.UnaryServerInterceptor(serverLog),
5755
grpc_prometheus.UnaryServerInterceptor,
5856
grpc_util.PanicLoggerUnaryServerInterceptor(serverLog),
@@ -68,6 +66,7 @@ func NewServer(initConstants plugin.CMPServerInitConstants) (*ArgoCDCMPServer, e
6866
MinTime: common.GetGRPCKeepAliveEnforcementMinimum(),
6967
},
7068
),
69+
grpc.StatsHandler(otelgrpc.NewServerHandler()),
7170
}
7271

7372
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"
@@ -528,8 +529,7 @@ func (c *client) newConn() (*grpc.ClientConn, io.Closer, error) {
528529
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)))
529530
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)))
530531
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(grpc_retry.UnaryClientInterceptor(retryOpts...))))
531-
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(grpc_util.OTELUnaryClientInterceptor()))
532-
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpc_util.OTELStreamClientInterceptor()))
532+
dialOpts = append(dialOpts, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
533533

534534
ctx := context.Background()
535535

reposerver/apiclient/clientset.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import (
44
"crypto/tls"
55
"crypto/x509"
66
"fmt"
7-
"github.com/argoproj/argo-cd/v2/common"
8-
"github.com/argoproj/argo-cd/v2/util/env"
97
"math"
108
"time"
119

10+
"github.com/argoproj/argo-cd/v2/common"
11+
"github.com/argoproj/argo-cd/v2/util/env"
12+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
13+
1214
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
1315
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
1416
log "github.com/sirupsen/logrus"
@@ -69,8 +71,7 @@ func NewConnection(address string, timeoutSeconds int, tlsConfig *TLSConfigurati
6971
grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)),
7072
grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(unaryInterceptors...)),
7173
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)),
72-
grpc.WithUnaryInterceptor(argogrpc.OTELUnaryClientInterceptor()),
73-
grpc.WithStreamInterceptor(argogrpc.OTELStreamClientInterceptor()),
74+
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
7475
}
7576

7677
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"
@@ -648,7 +649,7 @@ func (s *Server) GetManifestsWithFiles(stream application.ApplicationService_Get
648649
ProjectSourceRepos: proj.Spec.SourceRepos,
649650
}
650651

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

server/server.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,7 @@ func (a *ArgoCDServer) Listen() (*Listeners, error) {
455455
var dOpts []grpc.DialOption
456456
dOpts = append(dOpts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(apiclient.MaxGRPCMessageSize)))
457457
dOpts = append(dOpts, grpc.WithUserAgent(fmt.Sprintf("%s/%s", common.ArgoCDUserAgentName, common.GetVersion().Version)))
458-
dOpts = append(dOpts, grpc.WithUnaryInterceptor(grpc_util.OTELUnaryClientInterceptor()))
459-
dOpts = append(dOpts, grpc.WithStreamInterceptor(grpc_util.OTELStreamClientInterceptor()))
458+
dOpts = append(dOpts, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
460459
if a.useTLS() {
461460
// The following sets up the dial Options for grpc-gateway to talk to gRPC server over TLS.
462461
// grpc-gateway is just translating HTTP/HTTPS requests as gRPC requests over localhost,
@@ -771,7 +770,6 @@ func (a *ArgoCDServer) newGRPCServer() (*grpc.Server, application.AppResourceTre
771770
// NOTE: notice we do not configure the gRPC server here with TLS (e.g. grpc.Creds(creds))
772771
// This is because TLS handshaking occurs in cmux handling
773772
sOpts = append(sOpts, grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
774-
otelgrpc.StreamServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
775773
grpc_logrus.StreamServerInterceptor(a.log),
776774
grpc_prometheus.StreamServerInterceptor,
777775
grpc_auth.StreamServerInterceptor(a.Authenticate),
@@ -785,7 +783,6 @@ func (a *ArgoCDServer) newGRPCServer() (*grpc.Server, application.AppResourceTre
785783
)))
786784
sOpts = append(sOpts, grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
787785
bug21955WorkaroundInterceptor,
788-
otelgrpc.UnaryServerInterceptor(), //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
789786
grpc_logrus.UnaryServerInterceptor(a.log),
790787
grpc_prometheus.UnaryServerInterceptor,
791788
grpc_auth.UnaryServerInterceptor(a.Authenticate),
@@ -797,6 +794,8 @@ func (a *ArgoCDServer) newGRPCServer() (*grpc.Server, application.AppResourceTre
797794
grpc_util.ErrorCodeGitUnaryServerInterceptor(),
798795
grpc_util.PanicLoggerUnaryServerInterceptor(a.log),
799796
)))
797+
sOpts = append(sOpts, grpc.StatsHandler(otelgrpc.NewServerHandler()))
798+
800799
grpcS := grpc.NewServer(sOpts...)
801800

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

util/grpc/trace.go

-33
This file was deleted.

0 commit comments

Comments
 (0)