This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
generated from ipfs/ipfs-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds generic HTTP metrics per handler/method/code: - ipfs_http_requests_inflight (gauge) - partially addresses #112 (outgoing tracked in caboose) - ipfs_http_requests_total (counter) - ipfs_http_request_duration_seconds (summary) - partially addresses #120 - ipfs_http_request_size_bytes (summary) - ipfs_http_response_size_bytes (summary)
- Loading branch information
Showing
5 changed files
with
110 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
func registerVersionMetric(version string) { | ||
m := prometheus.NewGauge(prometheus.GaugeOpts{ | ||
Namespace: "ipfs", | ||
Subsystem: "bifrost_gateway", | ||
Name: "info", | ||
Help: "Information about bifrost-gateway instance.", | ||
ConstLabels: prometheus.Labels{"version": version}, | ||
}) | ||
prometheus.MustRegister(m) | ||
m.Set(1) | ||
} | ||
|
||
// withHTTPMetrics collects metrics around HTTP request/response count, duration, and size | ||
// per specific handler. Allows us to track them separately for /ipns and /ipfs. | ||
func withHTTPMetrics(handler http.Handler, handlerName string) http.Handler { | ||
|
||
// TODO: move HTTP metrics below to separate file | ||
// HTTP metric template names match Kubo: | ||
// https://github.com/ipfs/kubo/blob/e550d9e4761ea394357c413c02ade142c0dea88c/core/corehttp/metrics.go#L79-L152 | ||
// This allows Kubo users to migrate to bifrost-gateway and compare global totals. | ||
opts := prometheus.SummaryOpts{ | ||
Namespace: "ipfs", | ||
Subsystem: "http", | ||
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, | ||
ConstLabels: prometheus.Labels{"handler": handlerName}, | ||
} | ||
// Dynamic labels 'method or 'code' are auto-filled | ||
// by https://pkg.go.dev/github.com/prometheus/client_golang/prometheus/promhttp#InstrumentHandlerResponseSize | ||
labels := []string{"method", "code"} | ||
|
||
reqWip := prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Namespace: opts.Namespace, | ||
Subsystem: opts.Subsystem, | ||
Name: "requests_inflight", | ||
Help: "Tracks the number of HTTP client requests currently in progress.", | ||
ConstLabels: opts.ConstLabels, | ||
}, | ||
) | ||
prometheus.MustRegister(reqWip) | ||
|
||
reqCnt := prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Namespace: opts.Namespace, | ||
Subsystem: opts.Subsystem, | ||
Name: "requests_total", | ||
Help: "Total number of HTTP requests made.", | ||
ConstLabels: opts.ConstLabels, | ||
}, | ||
labels, | ||
) | ||
prometheus.MustRegister(reqCnt) | ||
|
||
opts.Name = "request_duration_seconds" | ||
opts.Help = "The HTTP request latencies in seconds." | ||
reqDur := prometheus.NewSummaryVec(opts, labels) | ||
prometheus.MustRegister(reqDur) | ||
|
||
opts.Name = "request_size_bytes" | ||
opts.Help = "The HTTP request sizes in bytes." | ||
reqSz := prometheus.NewSummaryVec(opts, labels) | ||
prometheus.MustRegister(reqSz) | ||
|
||
opts.Name = "response_size_bytes" | ||
opts.Help = "The HTTP response sizes in bytes." | ||
resSz := prometheus.NewSummaryVec(opts, labels) | ||
prometheus.MustRegister(resSz) | ||
|
||
handler = promhttp.InstrumentHandlerInFlight(reqWip, handler) | ||
handler = promhttp.InstrumentHandlerCounter(reqCnt, handler) | ||
handler = promhttp.InstrumentHandlerDuration(reqDur, handler) | ||
handler = promhttp.InstrumentHandlerRequestSize(reqSz, handler) | ||
handler = promhttp.InstrumentHandlerResponseSize(resSz, handler) | ||
|
||
return handler | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters