Skip to content

Commit 0176b66

Browse files
committed
feat: add gateway unixfs time to first block histogram
1 parent 92854db commit 0176b66

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

core/corehttp/gateway_handler.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ type gatewayHandler struct {
6464
config GatewayConfig
6565
api coreiface.CoreAPI
6666

67-
unixfsGetMetric *prometheus.SummaryVec
67+
unixfsGetMetric *prometheus.SummaryVec
68+
unixfsGetHistMetric *prometheus.HistogramVec
6869
}
6970

7071
// StatusResponseWriter enables us to override HTTP Status Code passed to
@@ -104,10 +105,29 @@ func newGatewayHandler(c GatewayConfig, api coreiface.CoreAPI) *gatewayHandler {
104105
}
105106
}
106107

108+
unixfsGetHistMetric := prometheus.NewHistogramVec(
109+
prometheus.HistogramOpts{
110+
Namespace: "ipfs",
111+
Subsystem: "http",
112+
Name: "unixfs_get_latency_hist_seconds",
113+
Help: "The time till the first block is received when 'getting' a file from the gateway.",
114+
Buckets: []float64{0.1, 0.5, 1, 2, 3, 5, 8, 13},
115+
},
116+
[]string{"gateway"},
117+
)
118+
if err := prometheus.Register(unixfsGetHistMetric); err != nil {
119+
if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
120+
unixfsGetHistMetric = are.ExistingCollector.(*prometheus.HistogramVec)
121+
} else {
122+
log.Errorf("failed to register unixfsGetMetric: %v", err)
123+
}
124+
}
125+
107126
i := &gatewayHandler{
108-
config: c,
109-
api: api,
110-
unixfsGetMetric: unixfsGetMetric,
127+
config: c,
128+
api: api,
129+
unixfsGetMetric: unixfsGetMetric,
130+
unixfsGetHistMetric: unixfsGetHistMetric,
111131
}
112132
return i
113133
}
@@ -292,7 +312,9 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
292312
return
293313
}
294314

295-
i.unixfsGetMetric.WithLabelValues(parsedPath.Namespace()).Observe(time.Since(begin).Seconds())
315+
timeToGetFirstNode := time.Since(begin).Seconds()
316+
i.unixfsGetMetric.WithLabelValues(parsedPath.Namespace()).Observe(timeToGetFirstNode)
317+
i.unixfsGetHistMetric.WithLabelValues(parsedPath.Namespace()).Observe(timeToGetFirstNode)
296318

297319
defer dr.Close()
298320

0 commit comments

Comments
 (0)