@@ -15,6 +15,11 @@ import (
1515 "go.opentelemetry.io/otel/trace"
1616)
1717
18+ // Duration histograms measure things like API call execution, how long returning specific
19+ // CID/path, how long CAR fetch form backend took, etc.
20+ // We use fixed definition here, as we don't want to break existing buckets if we need to add more.
21+ var defaultDurationHistogramBuckets = []float64 {0.05 , 0.1 , 0.25 , 0.5 , 1 , 2 , 5 , 10 , 30 , 60 , 120 , 240 , 480 , 960 , 1920 }
22+
1823type ipfsBackendWithMetrics struct {
1924 api IPFSBackend
2025 apiCallMetric * prometheus.HistogramVec
@@ -30,7 +35,7 @@ func newIPFSBackendWithMetrics(api IPFSBackend) *ipfsBackendWithMetrics {
3035 Subsystem : "gw_backend" ,
3136 Name : "api_call_duration_seconds" ,
3237 Help : "The time spent in IPFSBackend API calls that returned success." ,
33- Buckets : [] float64 { 0.05 , 0.1 , 0.25 , 0.5 , 1 , 2 , 5 , 10 , 30 , 60 } ,
38+ Buckets : defaultDurationHistogramBuckets ,
3439 },
3540 []string {"name" , "result" },
3641 )
@@ -182,14 +187,6 @@ func newHandlerWithMetrics(c Config, api IPFSBackend) *handler {
182187 i := & handler {
183188 config : c ,
184189 api : newIPFSBackendWithMetrics (api ),
185- // Improved Metrics
186- // ----------------------------
187- // Time till the first content block (bar in /ipfs/cid/foo/bar)
188- // (format-agnostic, across all response types)
189- firstContentBlockGetMetric : newHistogramMetric (
190- "gw_first_content_block_get_latency_seconds" ,
191- "The time till the first content block is received on GET from the gateway." ,
192- ),
193190
194191 // Response-type specific metrics
195192 // ----------------------------
@@ -238,49 +235,20 @@ func newHandlerWithMetrics(c Config, api IPFSBackend) *handler {
238235 "gw_ipns_record_get_duration_seconds" ,
239236 "The time to GET an entire IPNS Record from the gateway." ,
240237 ),
241-
242- // Legacy Metrics
243- // ----------------------------
244- unixfsGetMetric : newSummaryMetric ( // TODO: remove?
245- // (deprecated, use firstContentBlockGetMetric instead)
246- "unixfs_get_latency_seconds" ,
247- "DEPRECATED: does not do what you think, use gw_first_content_block_get_latency_seconds instead." ,
248- ),
249238 }
250239 return i
251240}
252241
253- func newSummaryMetric (name string , help string ) * prometheus.SummaryVec {
254- summaryMetric := prometheus .NewSummaryVec (
255- prometheus.SummaryOpts {
256- Namespace : "ipfs" ,
257- Subsystem : "http" ,
258- Name : name ,
259- Help : help ,
260- },
261- []string {"gateway" },
262- )
263- if err := prometheus .Register (summaryMetric ); err != nil {
264- if are , ok := err .(prometheus.AlreadyRegisteredError ); ok {
265- summaryMetric = are .ExistingCollector .(* prometheus.SummaryVec )
266- } else {
267- log .Errorf ("failed to register ipfs_http_%s: %v" , name , err )
268- }
269- }
270- return summaryMetric
271- }
272-
273242func newHistogramMetric (name string , help string ) * prometheus.HistogramVec {
274243 // We can add buckets as a parameter in the future, but for now using static defaults
275244 // suggested in https://github.com/ipfs/kubo/issues/8441
276- defaultBuckets := []float64 {0.05 , 0.1 , 0.25 , 0.5 , 1 , 2 , 5 , 10 , 30 , 60 }
277245 histogramMetric := prometheus .NewHistogramVec (
278246 prometheus.HistogramOpts {
279247 Namespace : "ipfs" ,
280248 Subsystem : "http" ,
281249 Name : name ,
282250 Help : help ,
283- Buckets : defaultBuckets ,
251+ Buckets : defaultDurationHistogramBuckets ,
284252 },
285253 []string {"gateway" },
286254 )
0 commit comments