Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add gateway histogram metrics #8443

Merged
merged 4 commits into from
Mar 21, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add gateway unixfs time to first block histogram
  • Loading branch information
aschmahmann authored and lidel committed Mar 18, 2022
commit 1990b49d71c9b8ab46e00ced381d494661712dee
32 changes: 27 additions & 5 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ type gatewayHandler struct {
config GatewayConfig
api coreiface.CoreAPI

unixfsGetMetric *prometheus.SummaryVec
unixfsGetMetric *prometheus.SummaryVec
unixfsGetHistMetric *prometheus.HistogramVec
}

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

unixfsGetHistMetric := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "ipfs",
Subsystem: "http",
Name: "unixfs_get_latency_hist_seconds",
Help: "The time till the first block is received when 'getting' a file from the gateway.",
Buckets: []float64{0.1, 0.5, 1, 2, 3, 5, 8, 13},
},
[]string{"gateway"},
)
if err := prometheus.Register(unixfsGetHistMetric); err != nil {
if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
unixfsGetHistMetric = are.ExistingCollector.(*prometheus.HistogramVec)
} else {
log.Errorf("failed to register unixfsGetMetric: %v", err)
}
}

i := &gatewayHandler{
config: c,
api: api,
unixfsGetMetric: unixfsGetMetric,
config: c,
api: api,
unixfsGetMetric: unixfsGetMetric,
unixfsGetHistMetric: unixfsGetHistMetric,
}
return i
}
Expand Down Expand Up @@ -291,7 +311,9 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
webError(w, "ipfs block get "+resolvedPath.Cid().String(), err, http.StatusInternalServerError)
return
}
i.unixfsGetMetric.WithLabelValues(contentPath.Namespace()).Observe(time.Since(begin).Seconds())
timeToGetFirstContentBlock := time.Since(begin).Seconds()
i.unixfsGetMetric.WithLabelValues(contentPath.Namespace()).Observe(timeToGetFirstContentBlock)
i.unixfsGetHistMetric.WithLabelValues(contentPath.Namespace()).Observe(timeToGetFirstContentBlock)

// HTTP Headers
i.addUserHeaders(w) // ok, _now_ write user's headers.
Expand Down