Skip to content

Commit 464c408

Browse files
migrate reposerver
- server - migrate ServerInterceptor -> ServerHandler - client - migrate ClientInterceptor -> ClientHandler Signed-off-by: Jack-R-lantern <[email protected]>
1 parent cd6a280 commit 464c408

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

reposerver/apiclient/clientset.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ 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+
1213
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
1314
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
1415
log "github.com/sirupsen/logrus"
@@ -69,8 +70,7 @@ func NewConnection(address string, timeoutSeconds int, tlsConfig *TLSConfigurati
6970
grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)),
7071
grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(unaryInterceptors...)),
7172
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)),
72-
grpc.WithUnaryInterceptor(argogrpc.OTELUnaryClientInterceptor()),
73-
grpc.WithStreamInterceptor(argogrpc.OTELStreamClientInterceptor()),
73+
grpc.WithStatsHandler(argogrpc.OTELClientStatsHandler()),
7474
}
7575

7676
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

util/grpc/trace.go

+12
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import (
55

66
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
77
"google.golang.org/grpc"
8+
"google.golang.org/grpc/stats"
89
)
910

1011
var (
1112
otelUnaryInterceptor grpc.UnaryClientInterceptor
1213
otelStreamInterceptor grpc.StreamClientInterceptor
1314
interceptorsInitialized = sync.Once{}
15+
16+
clientStatsHandler stats.Handler
17+
statsHandlerInitialzied = sync.Once{}
1418
)
1519

1620
// otel interceptors must be created once to avoid memory leak
@@ -20,6 +24,9 @@ func ensureInitialized() {
2024
otelUnaryInterceptor = otelgrpc.UnaryClientInterceptor() //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
2125
otelStreamInterceptor = otelgrpc.StreamClientInterceptor() //nolint:staticcheck // TODO: ignore SA1019 for depreciation: see https://github.com/argoproj/argo-cd/issues/18258
2226
})
27+
statsHandlerInitialzied.Do(func() {
28+
clientStatsHandler = otelgrpc.NewClientHandler()
29+
})
2330
}
2431

2532
func OTELUnaryClientInterceptor() grpc.UnaryClientInterceptor {
@@ -31,3 +38,8 @@ func OTELStreamClientInterceptor() grpc.StreamClientInterceptor {
3138
ensureInitialized()
3239
return otelStreamInterceptor
3340
}
41+
42+
func OTELClientStatsHandler() stats.Handler {
43+
ensureInitialized()
44+
return clientStatsHandler
45+
}

0 commit comments

Comments
 (0)