Skip to content

Commit

Permalink
zoekt: upgrade to grpc-ecosystem/[email protected] (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggilmore authored Sep 18, 2023
1 parent 19f03ee commit 089709e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 553 deletions.
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/peterbourgon/ff/v3/ffcli"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -129,7 +129,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 @@ -1481,14 +1481,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 @@ -1524,14 +1524,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 @@ -39,7 +39,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 @@ -647,12 +647,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 @@ -691,20 +691,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/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f
Expand All @@ -33,7 +33,7 @@ require (
github.com/sourcegraph/go-ctags v0.0.0-20230111110657-c27675da7f71
github.com/sourcegraph/log v0.0.0-20230711093019-40c57b632cca
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 @@ -51,10 +51,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 @@ -128,9 +128,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 @@ -142,13 +142,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

0 comments on commit 089709e

Please sign in to comment.