Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zoekt: upgrade to grpc-ecosystem/[email protected] #648

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions cmd/zoekt-sourcegraph-indexserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"text/tabwriter"
"time"

grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/openmetrics/v2"
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
"github.com/keegancsmith/tmpfriend"
"github.com/peterbourgon/ff/v3/ffcli"
Expand Down Expand Up @@ -131,7 +131,7 @@ var (
})

clientMetricsOnce sync.Once
clientMetrics *grpc_prometheus.ClientMetrics
clientMetrics *grpcprom.ClientMetrics
)

// set of repositories that we want to capture separate indexing metrics for
Expand Down Expand Up @@ -1477,14 +1477,14 @@ func dialGRPCClient(addr string, logger sglog.Logger, additionalOpts ...grpc.Dia
opts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithChainStreamInterceptor(
grpc_prometheus.StreamClientInterceptor(metrics),
metrics.StreamClientInterceptor(),
internalActorStreamInterceptor(),
internalerrs.LoggingStreamClientInterceptor(logger),
internalerrs.PrometheusStreamClientInterceptor,
retry.StreamClientInterceptor(retryOpts...),
),
grpc.WithChainUnaryInterceptor(
grpc_prometheus.UnaryClientInterceptor(metrics),
metrics.UnaryClientInterceptor(),
internalActorUnaryInterceptor(),
internalerrs.LoggingUnaryClientInterceptor(logger),
internalerrs.PrometheusUnaryClientInterceptor,
Expand Down Expand Up @@ -1520,14 +1520,16 @@ func dialGRPCClient(addr string, logger sglog.Logger, additionalOpts ...grpc.Dia
//
// This function panics if the metrics cannot be registered with the default
// Prometheus registry.
func mustGetClientMetrics() *grpc_prometheus.ClientMetrics {
func mustGetClientMetrics() *grpcprom.ClientMetrics {
clientMetricsOnce.Do(func() {
clientMetrics = grpc_prometheus.NewRegisteredClientMetrics(prometheus.DefaultRegisterer,
grpc_prometheus.WithClientCounterOptions(),
grpc_prometheus.WithClientHandlingTimeHistogram(), // record the overall request latency for a gRPC request
grpc_prometheus.WithClientStreamRecvHistogram(), // record how long it takes for a client to receive a message during a streaming RPC
grpc_prometheus.WithClientStreamSendHistogram(), // record how long it takes for a client to send a message during a streaming RPC
clientMetrics = grpcprom.NewClientMetrics(
grpcprom.WithClientCounterOptions(),
grpcprom.WithClientHandlingTimeHistogram(), // record the overall request latency for a gRPC request
grpcprom.WithClientStreamRecvHistogram(), // record how long it takes for a client to receive a message during a streaming RPC
grpcprom.WithClientStreamSendHistogram(), // record how long it takes for a client to send a message during a streaming RPC
)

prometheus.DefaultRegisterer.MustRegister(clientMetrics)
})

return clientMetrics
Expand Down
18 changes: 10 additions & 8 deletions cmd/zoekt-webserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"sync"
"time"

grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/openmetrics/v2"
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
"github.com/sourcegraph/mountinfo"
zoektgrpc "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/server"
"github.com/sourcegraph/zoekt/grpc/internalerrs"
Expand Down Expand Up @@ -636,12 +636,12 @@ func newGRPCServer(logger sglog.Logger, streamer zoekt.Streamer, additionalOpts
opts := []grpc.ServerOption{
grpc.ChainStreamInterceptor(
otelgrpc.StreamServerInterceptor(),
grpc_prometheus.StreamServerInterceptor(metrics),
metrics.StreamServerInterceptor(),
internalerrs.LoggingStreamServerInterceptor(logger),
),
grpc.ChainUnaryInterceptor(
otelgrpc.UnaryServerInterceptor(),
grpc_prometheus.UnaryServerInterceptor(metrics),
metrics.UnaryServerInterceptor(),
internalerrs.LoggingUnaryServerInterceptor(logger),
),
}
Expand Down Expand Up @@ -680,20 +680,22 @@ var (
})

serverMetricsOnce sync.Once
serverMetrics *grpc_prometheus.ServerMetrics
serverMetrics *grpcprom.ServerMetrics
)

// mustGetServerMetrics returns a singleton instance of the server metrics
// that are shared across all gRPC servers that this process creates.
//
// This function panics if the metrics cannot be registered with the default
// Prometheus registry.
func mustGetServerMetrics() *grpc_prometheus.ServerMetrics {
func mustGetServerMetrics() *grpcprom.ServerMetrics {
serverMetricsOnce.Do(func() {
serverMetrics = grpc_prometheus.NewRegisteredServerMetrics(prometheus.DefaultRegisterer,
grpc_prometheus.WithServerCounterOptions(),
grpc_prometheus.WithServerHandlingTimeHistogram(), // record the overall response latency for a gRPC request)
serverMetrics = grpcprom.NewServerMetrics(
grpcprom.WithServerCounterOptions(),
grpcprom.WithServerHandlingTimeHistogram(), // record the overall response latency for a gRPC request)
)

prometheus.DefaultRegisterer.MustRegister(serverMetrics)
})

return serverMetrics
Expand Down
23 changes: 7 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ require (
github.com/google/go-github/v27 v27.0.6
github.com/google/slothfs v0.0.0-20190717100203-59c1163fd173
github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db
github.com/grpc-ecosystem/go-grpc-middleware/providers/openmetrics/v2 v2.0.0-rc.3
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20210128111500-3ff779b52992
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.0-rc.0
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0
github.com/hashicorp/go-retryablehttp v0.7.4
github.com/keegancsmith/rpc v1.3.0
github.com/keegancsmith/tmpfriend v0.0.0-20180423180255-86e88902a513
Expand All @@ -34,7 +34,7 @@ require (
github.com/sourcegraph/go-ctags v0.0.0-20230111110657-c27675da7f71
github.com/sourcegraph/log v0.0.0-20230523201558-ad2d71b4d2ee
github.com/sourcegraph/mountinfo v0.0.0-20230106004439-7026e28cef67
github.com/stretchr/testify v1.8.3
github.com/stretchr/testify v1.8.4
github.com/uber/jaeger-client-go v2.30.0+incompatible
github.com/uber/jaeger-lib v2.4.1+incompatible
github.com/xanzy/go-gitlab v0.86.0
Expand All @@ -52,10 +52,10 @@ require (
go.uber.org/atomic v1.11.0
go.uber.org/automaxprocs v1.5.2
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
golang.org/x/net v0.11.0
golang.org/x/net v0.14.0
golang.org/x/oauth2 v0.9.0
golang.org/x/sync v0.3.0
golang.org/x/sys v0.9.0
golang.org/x/sys v0.11.0
google.golang.org/grpc v1.56.1
google.golang.org/protobuf v1.31.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
Expand Down Expand Up @@ -129,9 +129,9 @@ require (
go.opentelemetry.io/proto/otlp v0.20.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.10.0 // indirect
google.golang.org/api v0.129.0 // indirect
Expand All @@ -143,13 +143,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// As of https://github.com/grpc-ecosystem/go-grpc-middleware/blob/7ac0846398432dee083fd8bc4ad7abacf8147ff2/providers/openmetrics/go.mod#L7,
// the latest release of the gRPC Prometheus middleware depends on a version of go-grpc-middleware that is two years old, and
// is incompatible with the latest gRPC releases.
//
// The parent project is currently working around this by using a local replace directive in their go.mod file (which ensures
// that they always use the current version of go-grpc-middleware that they're developing). Until this issue is fixed,
// we'll need to ensure that we explicitly depend on the latest version of go-grpc-middleware (v2.0.0-rc.3) as of this writing.
replace github.com/grpc-ecosystem/go-grpc-middleware/v2 => github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.3

go 1.18
Loading
Loading