···132132 Help: "Counts the number of repos we stopped tracking.",
133133 })
134134135135- clientMetricsOnce sync.Once
136136- clientMetrics *grpcprom.ClientMetrics
135135+ // clientMetricsOnce returns a singleton instance of the client metrics
136136+ // that are shared across all gRPC clients that this process creates.
137137+ //
138138+ // This function panics if the metrics cannot be registered with the default
139139+ // Prometheus registry.
140140+ clientMetricsOnce = sync.OnceValue(func() *grpcprom.ClientMetrics {
141141+ clientMetrics := grpcprom.NewClientMetrics(
142142+ grpcprom.WithClientCounterOptions(),
143143+ grpcprom.WithClientHandlingTimeHistogram(), // record the overall request latency for a gRPC request
144144+ grpcprom.WithClientStreamRecvHistogram(), // record how long it takes for a client to receive a message during a streaming RPC
145145+ grpcprom.WithClientStreamSendHistogram(), // record how long it takes for a client to send a message during a streaming RPC
146146+ )
147147+ prometheus.DefaultRegisterer.MustRegister(clientMetrics)
148148+ return clientMetrics
149149+ })
137150)
138151139152// 1 MB; match https://sourcegraph.sgdev.org/github.com/sourcegraph/sourcegraph/-/blob/cmd/symbols/internal/symbols/search.go#L22
···15051518const defaultGRPCMessageReceiveSizeBytes = 90 * 1024 * 1024 // 90 MB
1506151915071520func dialGRPCClient(addr string, logger sglog.Logger, additionalOpts ...grpc.DialOption) (proto.ZoektConfigurationServiceClient, error) {
15081508- metrics := mustGetClientMetrics()
15211521+ metrics := clientMetricsOnce()
1509152215101523 // If the service seems to be unavailable, this
15111524 // will retry after [1s, 2s, 4s, 8s, 16s] with a jitterFraction of .1
···1557157015581571 client := proto.NewZoektConfigurationServiceClient(cc)
15591572 return client, nil
15601560-}
15611561-15621562-// mustGetClientMetrics returns a singleton instance of the client metrics
15631563-// that are shared across all gRPC clients that this process creates.
15641564-//
15651565-// This function panics if the metrics cannot be registered with the default
15661566-// Prometheus registry.
15671567-func mustGetClientMetrics() *grpcprom.ClientMetrics {
15681568- clientMetricsOnce.Do(func() {
15691569- clientMetrics = grpcprom.NewClientMetrics(
15701570- grpcprom.WithClientCounterOptions(),
15711571- grpcprom.WithClientHandlingTimeHistogram(), // record the overall request latency for a gRPC request
15721572- grpcprom.WithClientStreamRecvHistogram(), // record how long it takes for a client to receive a message during a streaming RPC
15731573- grpcprom.WithClientStreamSendHistogram(), // record how long it takes for a client to send a message during a streaming RPC
15741574- )
15751575-15761576- prometheus.DefaultRegisterer.MustRegister(clientMetrics)
15771577- })
15781578-15791579- return clientMetrics
15801573}
1581157415821575// addDefaultPort adds a default port to a URL if one is not specified.
+10-17
cmd/zoekt-webserver/main.go
···639639}
640640641641func newGRPCServer(logger sglog.Logger, streamer zoekt.Streamer, additionalOpts ...grpc.ServerOption) *grpc.Server {
642642- metrics := mustGetServerMetrics()
642642+ metrics := serverMetricsOnce()
643643644644 opts := []grpc.ServerOption{
645645 grpc.ChainStreamInterceptor(
···689689 Help: "The total number of search requests that zoekt received",
690690 })
691691692692- serverMetricsOnce sync.Once
693693- serverMetrics *grpcprom.ServerMetrics
694694-)
695695-696696-// mustGetServerMetrics returns a singleton instance of the server metrics
697697-// that are shared across all gRPC servers that this process creates.
698698-//
699699-// This function panics if the metrics cannot be registered with the default
700700-// Prometheus registry.
701701-func mustGetServerMetrics() *grpcprom.ServerMetrics {
702702- serverMetricsOnce.Do(func() {
703703- serverMetrics = grpcprom.NewServerMetrics(
692692+ // serviceMetricsOnce returns a singleton instance of the server metrics
693693+ // that are shared across all gRPC servers that this process creates.
694694+ //
695695+ // This function panics if the metrics cannot be registered with the default
696696+ // Prometheus registry.
697697+ serverMetricsOnce = sync.OnceValue(func() *grpcprom.ServerMetrics {
698698+ serverMetrics := grpcprom.NewServerMetrics(
704699 grpcprom.WithServerCounterOptions(),
705700 grpcprom.WithServerHandlingTimeHistogram(), // record the overall response latency for a gRPC request)
706701 )
707707-708702 prometheus.DefaultRegisterer.MustRegister(serverMetrics)
703703+ return serverMetrics
709704 })
710710-711711- return serverMetrics
712712-}
705705+)