Skip to content

Commit 01ea333

Browse files
Merge pull request #3315 from ipfs/fix/metrics-injection
Fix metrics injection
2 parents 716aa86 + 06a5381 commit 01ea333

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

cmd/ipfs/daemon.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ func defaultMux(path string) corehttp.ServeOption {
181181
var fileDescriptorCheck = func() error { return nil }
182182

183183
func daemonFunc(req cmds.Request, res cmds.Response) {
184+
// Inject metrics before we do anything
185+
186+
err := mprome.Inject()
187+
if err != nil {
188+
log.Errorf("Injecting prometheus handler for metrics failed with message: %s\n", err.Error())
189+
}
190+
184191
// let the user know we're going.
185192
fmt.Printf("Initializing daemon...\n")
186193

@@ -388,10 +395,6 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
388395
}
389396

390397
// initialize metrics collector
391-
err = mprome.Inject()
392-
if err != nil {
393-
log.Warningf("Injecting prometheus handler for metrics failed with message: %s\n", err.Error())
394-
}
395398
prometheus.MustRegister(&corehttp.IpfsNodeCollector{Node: node})
396399

397400
fmt.Printf("Daemon is ready\n")

test/sharness/t0600-issues-and-regressions-online.sh

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ test_expect_success "no panic traces on daemon" '
2727
test_must_fail grep "nil pointer dereference" daemon_err
2828
'
2929

30+
test_expect_success "metrics work" '
31+
curl "$API_ADDR/debug/metrics/prometheus" > pro_data &&
32+
grep "ipfs_bs_cache_arc_hits_total" < pro_data ||
33+
test_fsh cat pro_data
34+
'
35+
3036
test_kill_ipfs_daemon
3137

3238
test_expect_success "ipfs daemon --offline --mount fails - #2995" '

0 commit comments

Comments
 (0)