mirror of
https://github.com/ipfs/kubo.git
synced 2025-08-06 19:44:01 +08:00

* feat(gw): response type histogram metrics - response-type agnostic firstContentBlockGetMetric which counts the latency til the first content block. - car/block/file/gen-dir-index duration histogram metrics that show how long each response type takes * docs: improve metrics descriptions * feat: more gw histogram buckets 0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 30, 60 secs as suggested in reviews at https://github.com/ipfs/go-ipfs/pull/8443 Co-authored-by: Marcin Rataj <lidel@lidel.org> Co-authored-by: Gus Eggert <gus@gus.dev>
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package corehttp
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"time"
|
|
|
|
cid "github.com/ipfs/go-cid"
|
|
ipath "github.com/ipfs/interface-go-ipfs-core/path"
|
|
)
|
|
|
|
// serveRawBlock returns bytes behind a raw block
|
|
func (i *gatewayHandler) serveRawBlock(w http.ResponseWriter, r *http.Request, blockCid cid.Cid, contentPath ipath.Path, begin time.Time) {
|
|
blockReader, err := i.api.Block().Get(r.Context(), contentPath)
|
|
if err != nil {
|
|
webError(w, "ipfs block get "+blockCid.String(), err, http.StatusInternalServerError)
|
|
return
|
|
}
|
|
block, err := ioutil.ReadAll(blockReader)
|
|
if err != nil {
|
|
webError(w, "ipfs block get "+blockCid.String(), err, http.StatusInternalServerError)
|
|
return
|
|
}
|
|
content := bytes.NewReader(block)
|
|
|
|
// Set Content-Disposition
|
|
name := blockCid.String() + ".bin"
|
|
setContentDispositionHeader(w, name, "attachment")
|
|
|
|
// Set remaining headers
|
|
modtime := addCacheControlHeaders(w, r, contentPath, blockCid)
|
|
w.Header().Set("Content-Type", "application/vnd.ipld.raw")
|
|
w.Header().Set("X-Content-Type-Options", "nosniff") // no funny business in the browsers :^)
|
|
|
|
// Done: http.ServeContent will take care of
|
|
// If-None-Match+Etag, Content-Length and range requests
|
|
http.ServeContent(w, r, name, modtime, content)
|
|
|
|
// Update metrics
|
|
i.rawBlockGetMetric.WithLabelValues(contentPath.Namespace()).Observe(time.Since(begin).Seconds())
|
|
}
|