@cryptotaxi247 / kubo / commits / 4ba03fa8d

revert registration of metrics against unexposed prom registry

lanzafame committed Mar 17, 2021 at 10:15 UTC 4ba03fa8df0e0d398bb946421c2a179828595221
1 file changed +4 -5
core/corehttp/metrics.go
+4 -5
@@ -59,7 +59,6 @@ func MetricsOpenCensusCollectionOption() ServeOption {
59 // This adds collection of net/http-related metrics
60 func MetricsCollectionOption(handlerName string) ServeOption {
61 return func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
62 - promRegistry := prometheus.NewRegistry()
62 // Adapted from github.com/prometheus/client_golang/prometheus/http.go
63 // Work around https://github.com/prometheus/client_golang/pull/311
64 opts := prometheus.SummaryOpts{
@@ -79,7 +78,7 @@ func MetricsCollectionOption(handlerName string) ServeOption {
78 },
79 []string{"method", "code"},
80 )
82 - if err := promRegistry.Register(reqCnt); err != nil {
81 + if err := prometheus.Register(reqCnt); err != nil {
82 if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
83 reqCnt = are.ExistingCollector.(*prometheus.CounterVec)
84 } else {
@@ -90,7 +89,7 @@ func MetricsCollectionOption(handlerName string) ServeOption {
89 opts.Name = "request_duration_seconds"
90 opts.Help = "The HTTP request latencies in seconds."
91 reqDur := prometheus.NewSummaryVec(opts, nil)
93 - if err := promRegistry.Register(reqDur); err != nil {
92 + if err := prometheus.Register(reqDur); err != nil {
93 if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
94 reqDur = are.ExistingCollector.(*prometheus.SummaryVec)
95 } else {
@@ -101,7 +100,7 @@ func MetricsCollectionOption(handlerName string) ServeOption {
100 opts.Name = "request_size_bytes"
101 opts.Help = "The HTTP request sizes in bytes."
102 reqSz := prometheus.NewSummaryVec(opts, nil)
104 - if err := promRegistry.Register(reqSz); err != nil {
103 + if err := prometheus.Register(reqSz); err != nil {
104 if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
105 reqSz = are.ExistingCollector.(*prometheus.SummaryVec)
106 } else {
@@ -112,7 +111,7 @@ func MetricsCollectionOption(handlerName string) ServeOption {
111 opts.Name = "response_size_bytes"
112 opts.Help = "The HTTP response sizes in bytes."
113 resSz := prometheus.NewSummaryVec(opts, nil)
115 - if err := promRegistry.Register(resSz); err != nil {
114 + if err := prometheus.Register(resSz); err != nil {
115 if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
116 resSz = are.ExistingCollector.(*prometheus.SummaryVec)
117 } else {