Skip to content

Commit 41d484f

Browse files
akosyakovroboquat
authored andcommitted
[supervisor]: add grpc observability
1 parent 40526fb commit 41d484f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232

3333
"github.com/gorilla/websocket"
3434
grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
35+
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
3536
grpcruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
3637
"github.com/improbable-eng/grpc-web/go/grpcweb"
3738
"github.com/prometheus/common/route"
@@ -1107,6 +1108,15 @@ func startAPIEndpoint(ctx context.Context, cfg *Config, wg *sync.WaitGroup, serv
11071108
)
11081109
}
11091110

1111+
grpcMetrics := grpc_prometheus.NewServerMetrics()
1112+
grpcMetrics.EnableHandlingTimeHistogram(
1113+
grpc_prometheus.WithHistogramBuckets([]float64{.005, .025, .05, .1, .5, 1, 2.5, 5, 30, 60, 120, 240, 600}),
1114+
)
1115+
opts = append(opts,
1116+
grpc.StreamInterceptor(grpcMetrics.StreamServerInterceptor()),
1117+
grpc.UnaryInterceptor(grpcMetrics.UnaryServerInterceptor()),
1118+
)
1119+
11101120
m := cmux.New(l)
11111121
restMux := grpcruntime.NewServeMux()
11121122
grpcMux := m.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))
@@ -1131,8 +1141,13 @@ func startAPIEndpoint(ctx context.Context, cfg *Config, wg *sync.WaitGroup, serv
11311141
return true
11321142
}))
11331143

1144+
metricsRegistry := prometheus.NewRegistry()
1145+
err = metricsRegistry.Register(grpcMetrics)
1146+
if err != nil {
1147+
log.WithError(err).Error("supervisor: failed to register grpc metrics")
1148+
}
11341149
metricStore := storage.NewDiskMetricStore("", time.Minute*5, prometheus.DefaultGatherer, nil)
1135-
metricsGatherer := prometheus.Gatherers{prometheus.GathererFunc(func() ([]*dto.MetricFamily, error) {
1150+
metricsGatherer := prometheus.Gatherers{metricsRegistry, prometheus.GathererFunc(func() ([]*dto.MetricFamily, error) {
11361151
return metricStore.GetMetricFamilies(), nil
11371152
})}
11381153

0 commit comments

Comments
 (0)