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(gw): add ipfs_http_gw_car_stream_fail_duration_seconds #312

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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