···3131 "text/tabwriter"
3232 "time"
33333434+ grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/openmetrics/v2"
3435 "github.com/keegancsmith/tmpfriend"
3536 "github.com/peterbourgon/ff/v3/ffcli"
3637 "github.com/prometheus/client_golang/prometheus"
3738 "github.com/prometheus/client_golang/prometheus/promauto"
3839 sglog "github.com/sourcegraph/log"
4040+ proto "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1"
3941 "github.com/sourcegraph/zoekt/grpc/internalerrs"
4042 "github.com/sourcegraph/zoekt/grpc/messagesize"
4143 "go.uber.org/automaxprocs/maxprocs"
···49515052 "github.com/sourcegraph/zoekt"
5153 "github.com/sourcegraph/zoekt/build"
5252- proto "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1"
5354 "github.com/sourcegraph/zoekt/debugserver"
5455 "github.com/sourcegraph/zoekt/internal/profiler"
5556)
···126127 Name: "index_num_stopped_tracking_total",
127128 Help: "Counts the number of repos we stopped tracking.",
128129 })
130130+131131+ clientMetricsOnce sync.Once
132132+ clientMetrics *grpc_prometheus.ClientMetrics
129133)
130134131135// set of repositories that we want to capture separate indexing metrics for
···14571461const defaultGRPCMessageReceiveSizeBytes = 90 * 1024 * 1024 // 90 MB
1458146214591463func dialGRPCClient(addr string, logger sglog.Logger, additionalOpts ...grpc.DialOption) (proto.ZoektConfigurationServiceClient, error) {
14641464+ metrics := mustGetClientMetrics()
14651465+14601466 opts := []grpc.DialOption{
14611467 grpc.WithTransportCredentials(insecure.NewCredentials()),
14621468 grpc.WithChainStreamInterceptor(
14691469+ grpc_prometheus.StreamClientInterceptor(metrics),
14631470 internalActorStreamInterceptor(),
14641471 internalerrs.LoggingStreamClientInterceptor(logger),
14651472 internalerrs.PrometheusStreamClientInterceptor,
14661473 ),
14671474 grpc.WithChainUnaryInterceptor(
14751475+ grpc_prometheus.UnaryClientInterceptor(metrics),
14681476 internalActorUnaryInterceptor(),
14691477 internalerrs.LoggingUnaryClientInterceptor(logger),
14701478 internalerrs.PrometheusUnaryClientInterceptor,
···1492150014931501 client := proto.NewZoektConfigurationServiceClient(cc)
14941502 return client, nil
15031503+}
15041504+15051505+// mustGetClientMetrics returns a singleton instance of the client metrics
15061506+// that are shared across all gRPC clients that this process creates.
15071507+//
15081508+// This function panics if the metrics cannot be registered with the default
15091509+// Prometheus registry.
15101510+func mustGetClientMetrics() *grpc_prometheus.ClientMetrics {
15111511+ clientMetricsOnce.Do(func() {
15121512+ clientMetrics = grpc_prometheus.NewRegisteredClientMetrics(prometheus.DefaultRegisterer,
15131513+ grpc_prometheus.WithClientCounterOptions(),
15141514+ grpc_prometheus.WithClientHandlingTimeHistogram(), // record the overall request latency for a gRPC request
15151515+ grpc_prometheus.WithClientStreamRecvHistogram(), // record how long it takes for a client to receive a message during a streaming RPC
15161516+ grpc_prometheus.WithClientStreamSendHistogram(), // record how long it takes for a client to send a message during a streaming RPC
15171517+ )
15181518+ })
15191519+15201520+ return clientMetrics
14951521}
1496152214971523// addDefaultPort adds a default port to a URL if one is not specified.
···23232424 "github.com/go-git/go-git/v5"
2525 retryablehttp "github.com/hashicorp/go-retryablehttp"
2626+ proto "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1"
2627 "golang.org/x/net/trace"
2728 "google.golang.org/grpc"
28292930 "github.com/sourcegraph/zoekt"
3030- proto "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1"
3131)
32323333// SourcegraphListResult is the return value of Sourcegraph.List. It is its
+28-3
cmd/zoekt-webserver/main.go
···3535 "runtime"
3636 "strconv"
3737 "strings"
3838+ "sync"
3839 "time"
39404141+ grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/openmetrics/v2"
4042 "github.com/sourcegraph/mountinfo"
4343+ zoektgrpc "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/server"
4144 "github.com/sourcegraph/zoekt/grpc/internalerrs"
4245 "github.com/sourcegraph/zoekt/grpc/messagesize"
4343- zoektgrpc "github.com/sourcegraph/zoekt/grpc/server"
4646+ proto "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1"
4447 "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
4548 "golang.org/x/net/http2"
4649 "golang.org/x/net/http2/h2c"
···4952 "github.com/sourcegraph/zoekt"
5053 "github.com/sourcegraph/zoekt/build"
5154 "github.com/sourcegraph/zoekt/debugserver"
5252- v1 "github.com/sourcegraph/zoekt/grpc/v1"
5355 "github.com/sourcegraph/zoekt/internal/profiler"
5456 "github.com/sourcegraph/zoekt/internal/tracer"
5557 "github.com/sourcegraph/zoekt/query"
···629631}
630632631633func newGRPCServer(logger sglog.Logger, streamer zoekt.Streamer, additionalOpts ...grpc.ServerOption) *grpc.Server {
634634+ metrics := mustGetServerMetrics()
635635+632636 opts := []grpc.ServerOption{
633637 grpc.ChainStreamInterceptor(
634638 otelgrpc.StreamServerInterceptor(),
639639+ grpc_prometheus.StreamServerInterceptor(metrics),
635640 internalerrs.LoggingStreamServerInterceptor(logger),
636641 ),
637642 grpc.ChainUnaryInterceptor(
638643 otelgrpc.UnaryServerInterceptor(),
644644+ grpc_prometheus.UnaryServerInterceptor(metrics),
639645 internalerrs.LoggingUnaryServerInterceptor(logger),
640646 ),
641647 }
···650656 opts = append(opts, messagesize.MustGetServerMessageSizeFromEnv()...)
651657652658 s := grpc.NewServer(opts...)
653653- v1.RegisterWebserverServiceServer(s, zoektgrpc.NewServer(streamer))
659659+ proto.RegisterWebserverServiceServer(s, zoektgrpc.NewServer(streamer))
654660655661 return s
656662}
···672678 Name: "zoekt_search_requests_total",
673679 Help: "The total number of search requests that zoekt received",
674680 })
681681+682682+ serverMetricsOnce sync.Once
683683+ serverMetrics *grpc_prometheus.ServerMetrics
675684)
685685+686686+// mustGetServerMetrics returns a singleton instance of the server metrics
687687+// that are shared across all gRPC servers that this process creates.
688688+//
689689+// This function panics if the metrics cannot be registered with the default
690690+// Prometheus registry.
691691+func mustGetServerMetrics() *grpc_prometheus.ServerMetrics {
692692+ serverMetricsOnce.Do(func() {
693693+ serverMetrics = grpc_prometheus.NewRegisteredServerMetrics(prometheus.DefaultRegisterer,
694694+ grpc_prometheus.WithServerCounterOptions(),
695695+ grpc_prometheus.WithServerHandlingTimeHistogram(), // record the overall response latency for a gRPC request)
696696+ )
697697+ })
698698+699699+ return serverMetrics
700700+}
+6-1
gen-proto.sh
···5566find . -name "buf.gen.yaml" -not -path ".git" | while read -r buf_yaml; do
77 pushd "$(dirname "${buf_yaml}")" >/dev/null
88- buf generate
88+99+ if ! buf generate; then
1010+ echo "failed to generate ${buf_yaml}" >&2
1111+ exit 1
1212+ fi
1313+914 popd >/dev/null
1015done
+11
go.mod
···1717 github.com/google/go-github/v27 v27.0.6
1818 github.com/google/slothfs v0.0.0-20190717100203-59c1163fd173
1919 github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db
2020+ github.com/grpc-ecosystem/go-grpc-middleware/providers/openmetrics/v2 v2.0.0-rc.3
2021 github.com/hashicorp/go-retryablehttp v0.7.4
2122 github.com/keegancsmith/rpc v1.3.0
2223 github.com/keegancsmith/tmpfriend v0.0.0-20180423180255-86e88902a513
···9495 github.com/google/uuid v1.3.0 // indirect
9596 github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
9697 github.com/googleapis/gax-go/v2 v2.11.0 // indirect
9898+ github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20210128111500-3ff779b52992 // indirect
9799 github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
98100 github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
99101 github.com/hashicorp/go-hclog v0.16.2 // indirect
···139141 gopkg.in/warnings.v0 v0.1.2 // indirect
140142 gopkg.in/yaml.v3 v3.0.1 // indirect
141143)
144144+145145+// As of https://github.com/grpc-ecosystem/go-grpc-middleware/blob/7ac0846398432dee083fd8bc4ad7abacf8147ff2/providers/openmetrics/go.mod#L7,
146146+// the latest release of the gRPC Prometheus middleware depends on a version of go-grpc-middleware that is two years old, and
147147+// is incompatible with the latest gRPC releases.
148148+//
149149+// The parent project is currently working around this by using a local replace directive in their go.mod file (which ensures
150150+// that they always use the current version of go-grpc-middleware that they're developing). Until this issue is fixed,
151151+// 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.
152152+replace github.com/grpc-ecosystem/go-grpc-middleware/v2 => github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.3
142153143154go 1.18