Skip to content

Commit

Permalink
feat(gw): add ipfs_http_gw_car_stream_fail_duration_seconds (#312)
Browse files Browse the repository at this point in the history
Closes #288
  • Loading branch information
lidel committed May 22, 2023
1 parent fee5f6b commit e468223
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gateway/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ type handler struct {
unixfsDirIndexGetMetric *prometheus.HistogramVec
unixfsGenDirListingGetMetric *prometheus.HistogramVec
carStreamGetMetric *prometheus.HistogramVec
carStreamFailMetric *prometheus.HistogramVec
rawBlockGetMetric *prometheus.HistogramVec
tarStreamGetMetric *prometheus.HistogramVec
tarStreamFailMetric *prometheus.HistogramVec
jsoncborDocumentGetMetric *prometheus.HistogramVec
ipnsRecordGetMetric *prometheus.HistogramVec
}
Expand Down
3 changes: 3 additions & 0 deletions gateway/handler_car.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func (i *handler) serveCAR(ctx context.Context, w http.ResponseWriter, r *http.R
carErr := <-errCh
streamErr := multierr.Combine(carErr, copyErr)
if streamErr != nil {
// Update fail metric
i.carStreamFailMetric.WithLabelValues(contentPath.Namespace()).Observe(time.Since(begin).Seconds())

// We return error as a trailer, however it is not something browsers can access
// (https://github.com/mdn/browser-compat-data/issues/14703)
// Due to this, we suggest client always verify that
Expand Down
3 changes: 3 additions & 0 deletions gateway/handler_tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func (i *handler) serveTAR(ctx context.Context, w http.ResponseWriter, r *http.R

// The TAR has a top-level directory (or file) named by the CID.
if err := tarw.WriteFile(file, rootCid.String()); err != nil {
// Update fail metric
i.tarStreamFailMetric.WithLabelValues(contentPath.Namespace()).Observe(time.Since(begin).Seconds())

w.Header().Set("X-Stream-Error", err.Error())
// Trailer headers do not work in web browsers
// (see https://github.com/mdn/browser-compat-data/issues/14703)
Expand Down
9 changes: 9 additions & 0 deletions gateway/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ func newHandlerWithMetrics(c Config, api IPFSBackend) *handler {
"gw_car_stream_get_duration_seconds",
"The time to GET an entire CAR stream from the gateway.",
),
carStreamFailMetric: newHistogramMetric(
"gw_car_stream_fail_duration_seconds",
"How long a CAR was streamed before failing mid-stream.",
),
// Block: time it takes to return requested Block
rawBlockGetMetric: newHistogramMetric(
"gw_raw_block_get_duration_seconds",
Expand All @@ -229,6 +233,11 @@ func newHandlerWithMetrics(c Config, api IPFSBackend) *handler {
"gw_tar_stream_get_duration_seconds",
"The time to GET an entire TAR stream from the gateway.",
),
// TAR: time it takes to return requested TAR stream
tarStreamFailMetric: newHistogramMetric(
"gw_tar_stream_fail_duration_seconds",
"How long a TAR was streamed before failing mid-stream.",
),
// JSON/CBOR: time it takes to return requested DAG-JSON/-CBOR document
jsoncborDocumentGetMetric: newHistogramMetric(
"gw_jsoncbor_get_duration_seconds",
Expand Down

0 comments on commit e468223

Please sign in to comment.