From de34ef813b99d58b4d8eba2ad26e75738ae5f789 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 18 Oct 2016 08:59:15 +0200 Subject: [PATCH 1/3] Fix metrics being injected after node initalization License: MIT Signed-off-by: Jakub Sztandera --- cmd/ipfs/daemon.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 4bda0128368..c8aff04ffa0 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -181,6 +181,13 @@ func defaultMux(path string) corehttp.ServeOption { var fileDescriptorCheck = func() error { return nil } func daemonFunc(req cmds.Request, res cmds.Response) { + // Inject metrics before we do anything + + err := mprome.Inject() + if err != nil { + log.Warningf("Injecting prometheus handler for metrics failed with message: %s\n", err.Error()) + } + // let the user know we're going. fmt.Printf("Initializing daemon...\n") @@ -388,10 +395,6 @@ func daemonFunc(req cmds.Request, res cmds.Response) { } // initialize metrics collector - err = mprome.Inject() - if err != nil { - log.Warningf("Injecting prometheus handler for metrics failed with message: %s\n", err.Error()) - } prometheus.MustRegister(&corehttp.IpfsNodeCollector{Node: node}) fmt.Printf("Daemon is ready\n") From e254f0d8b59745db00c8171e6e9f7413c68b0584 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 18 Oct 2016 09:01:00 +0200 Subject: [PATCH 2/3] test: check if metrics work in sharness License: MIT Signed-off-by: Jakub Sztandera --- test/sharness/t0600-issues-and-regressions-online.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/sharness/t0600-issues-and-regressions-online.sh b/test/sharness/t0600-issues-and-regressions-online.sh index ca95514b8ed..7499b0e1d15 100755 --- a/test/sharness/t0600-issues-and-regressions-online.sh +++ b/test/sharness/t0600-issues-and-regressions-online.sh @@ -27,6 +27,12 @@ test_expect_success "no panic traces on daemon" ' test_must_fail grep "nil pointer dereference" daemon_err ' +test_expect_success "metrics work" ' + curl "$API_ADDR/debug/metrics/prometheus" > pro_data && + grep "ipfs_bs_cache_arc_hits_total" < pro_data || + test_fsh cat pro_data +' + test_kill_ipfs_daemon test_expect_success "ipfs daemon --offline --mount fails - #2995" ' From 06a5381c2a4c2480725cf32a10efdc0576141edc Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 18 Oct 2016 18:19:02 +0200 Subject: [PATCH 3/3] feat: make metrics injection log an error instead of warning License: MIT Signed-off-by: Jakub Sztandera --- cmd/ipfs/daemon.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index c8aff04ffa0..5fe063c86a7 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -185,7 +185,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) { err := mprome.Inject() if err != nil { - log.Warningf("Injecting prometheus handler for metrics failed with message: %s\n", err.Error()) + log.Errorf("Injecting prometheus handler for metrics failed with message: %s\n", err.Error()) } // let the user know we're going.