提交 dcf6272f 作者: Adrian Lanzafame 提交者: Steven Allen

address pr feedback

上级 7db237d9
......@@ -23,6 +23,7 @@ import (
ipath "github.com/ipfs/interface-go-ipfs-core/path"
routing "github.com/libp2p/go-libp2p-core/routing"
"github.com/multiformats/go-multibase"
prometheus "github.com/prometheus/client_golang/prometheus"
)
const (
......@@ -35,12 +36,32 @@ const (
type gatewayHandler struct {
config GatewayConfig
api coreiface.CoreAPI
unixfsGetMetric *prometheus.SummaryVec
}
func newGatewayHandler(c GatewayConfig, api coreiface.CoreAPI) *gatewayHandler {
unixfsGetMetric := prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: "ipfs",
Subsystem: "http",
Name: "unixfs_get_latency_seconds",
Help: "The time till the first block is received when 'getting' a file from the gateway.",
},
[]string{"gateway"},
)
if err := prometheus.Register(unixfsGetMetric); err != nil {
if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
unixfsGetMetric = are.ExistingCollector.(*prometheus.SummaryVec)
} else {
log.Errorf("failed to register unixfsGetMetric: %v", err)
}
}
i := &gatewayHandler{
config: c,
api: api,
config: c,
api: api,
unixfsGetMetric: unixfsGetMetric,
}
return i
}
......@@ -178,7 +199,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
return
}
unixfsGetMetric.WithLabelValues(parsedPath.Namespace()).Observe(time.Since(begin).Seconds())
i.unixfsGetMetric.WithLabelValues(parsedPath.Namespace()).Observe(time.Since(begin).Seconds())
defer dr.Close()
......
......@@ -29,16 +29,6 @@ func MetricsCollectionOption(handlerName string) ServeOption {
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
}
if handlerName == "gateway" {
if err := prometheus.Register(unixfsGetMetric); err != nil {
if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
unixfsGetMetric = are.ExistingCollector.(*prometheus.SummaryVec)
} else {
return nil, err
}
}
}
reqCnt := prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: opts.Namespace,
......@@ -110,16 +100,6 @@ var (
[]string{"transport"},
nil,
)
unixfsGetMetric = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: "ipfs",
Subsystem: "http",
Name: "unixfs_get_latency_seconds",
Help: "The time till the first block is received when 'getting' a file from the gateway.",
},
[]string{"gateway"},
)
)
type IpfsNodeCollector struct {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论