Skip to content

Commit

Permalink
feat: metric for implicit index.html in dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias authored and lidel committed Feb 15, 2023
1 parent 6984b64 commit e7aa6a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
24 changes: 15 additions & 9 deletions gateway/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ type handler struct {
unixfsGetMetric *prometheus.SummaryVec // deprecated, use firstContentBlockGetMetric

// response type metrics
getMetric *prometheus.HistogramVec
unixfsFileGetMetric *prometheus.HistogramVec
unixfsGenDirGetMetric *prometheus.HistogramVec
carStreamGetMetric *prometheus.HistogramVec
rawBlockGetMetric *prometheus.HistogramVec
tarStreamGetMetric *prometheus.HistogramVec
jsoncborDocumentGetMetric *prometheus.HistogramVec
ipnsRecordGetMetric *prometheus.HistogramVec
getMetric *prometheus.HistogramVec
unixfsFileGetMetric *prometheus.HistogramVec
unixfsDirIndexGetMetric *prometheus.HistogramVec
unixfsGenDirListingGetMetric *prometheus.HistogramVec
carStreamGetMetric *prometheus.HistogramVec
rawBlockGetMetric *prometheus.HistogramVec
tarStreamGetMetric *prometheus.HistogramVec
jsoncborDocumentGetMetric *prometheus.HistogramVec
ipnsRecordGetMetric *prometheus.HistogramVec
}

// StatusResponseWriter enables us to override HTTP Status Code passed to
Expand Down Expand Up @@ -246,8 +247,13 @@ func newHandler(c Config, api API) *handler {
"gw_unixfs_file_get_duration_seconds",
"The time to serve an entire UnixFS file from the gateway.",
),
// UnixFS: time it takes to find and serve an index.html file on behalf of a directory.
unixfsDirIndexGetMetric: newHistogramMetric(
"gw_unixfs_dir_indexhtml_get_duration_seconds",
"The time to serve an index.html file on behalf of a directory from the gateway. This is a subset of gw_unixfs_file_get_duration_seconds.",
),
// UnixFS: time it takes to generate static HTML with directory listing
unixfsGenDirGetMetric: newHistogramMetric(
unixfsGenDirListingGetMetric: newHistogramMetric(
"gw_unixfs_gen_dir_listing_get_duration_seconds",
"The time to serve a generated UnixFS HTML directory listing from the gateway.",
),
Expand Down
8 changes: 6 additions & 2 deletions gateway/handler_unixfs_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ func (i *handler) serveDirectory(ctx context.Context, w http.ResponseWriter, r *

logger.Debugw("serving index.html file", "path", idxPath)
// write to request
return i.serveFile(ctx, w, r, resolvedPath, idxPath, f, begin)
success := i.serveFile(ctx, w, r, resolvedPath, idxPath, f, begin)
if success {
i.unixfsDirIndexGetMetric.WithLabelValues(contentPath.Namespace()).Observe(time.Since(begin).Seconds())
}
return success
case resolver.ErrNoLink:
logger.Debugw("no index.html; noop", "path", idxPath)
default:
Expand Down Expand Up @@ -198,7 +202,7 @@ func (i *handler) serveDirectory(ctx context.Context, w http.ResponseWriter, r *
}

// Update metrics
i.unixfsGenDirGetMetric.WithLabelValues(contentPath.Namespace()).Observe(time.Since(begin).Seconds())
i.unixfsGenDirListingGetMetric.WithLabelValues(contentPath.Namespace()).Observe(time.Since(begin).Seconds())
return true
}

Expand Down

0 comments on commit e7aa6a1

Please sign in to comment.