Skip to content

Commit e7aa6a1

Browse files
hacdiaslidel
authored andcommitted
feat: metric for implicit index.html in dirs
1 parent 6984b64 commit e7aa6a1

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

gateway/handler.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@ type handler struct {
7474
unixfsGetMetric *prometheus.SummaryVec // deprecated, use firstContentBlockGetMetric
7575

7676
// response type metrics
77-
getMetric *prometheus.HistogramVec
78-
unixfsFileGetMetric *prometheus.HistogramVec
79-
unixfsGenDirGetMetric *prometheus.HistogramVec
80-
carStreamGetMetric *prometheus.HistogramVec
81-
rawBlockGetMetric *prometheus.HistogramVec
82-
tarStreamGetMetric *prometheus.HistogramVec
83-
jsoncborDocumentGetMetric *prometheus.HistogramVec
84-
ipnsRecordGetMetric *prometheus.HistogramVec
77+
getMetric *prometheus.HistogramVec
78+
unixfsFileGetMetric *prometheus.HistogramVec
79+
unixfsDirIndexGetMetric *prometheus.HistogramVec
80+
unixfsGenDirListingGetMetric *prometheus.HistogramVec
81+
carStreamGetMetric *prometheus.HistogramVec
82+
rawBlockGetMetric *prometheus.HistogramVec
83+
tarStreamGetMetric *prometheus.HistogramVec
84+
jsoncborDocumentGetMetric *prometheus.HistogramVec
85+
ipnsRecordGetMetric *prometheus.HistogramVec
8586
}
8687

8788
// StatusResponseWriter enables us to override HTTP Status Code passed to
@@ -246,8 +247,13 @@ func newHandler(c Config, api API) *handler {
246247
"gw_unixfs_file_get_duration_seconds",
247248
"The time to serve an entire UnixFS file from the gateway.",
248249
),
250+
// UnixFS: time it takes to find and serve an index.html file on behalf of a directory.
251+
unixfsDirIndexGetMetric: newHistogramMetric(
252+
"gw_unixfs_dir_indexhtml_get_duration_seconds",
253+
"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.",
254+
),
249255
// UnixFS: time it takes to generate static HTML with directory listing
250-
unixfsGenDirGetMetric: newHistogramMetric(
256+
unixfsGenDirListingGetMetric: newHistogramMetric(
251257
"gw_unixfs_gen_dir_listing_get_duration_seconds",
252258
"The time to serve a generated UnixFS HTML directory listing from the gateway.",
253259
),

gateway/handler_unixfs_dir.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ func (i *handler) serveDirectory(ctx context.Context, w http.ResponseWriter, r *
7777

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

200204
// Update metrics
201-
i.unixfsGenDirGetMetric.WithLabelValues(contentPath.Namespace()).Observe(time.Since(begin).Seconds())
205+
i.unixfsGenDirListingGetMetric.WithLabelValues(contentPath.Namespace()).Observe(time.Since(begin).Seconds())
202206
return true
203207
}
204208

0 commit comments

Comments
 (0)