Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix metrics injection #3315

Merged
merged 3 commits into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this just be a warning? Or should we actually error out here?

Also, can we (in a future PR) have a flag to disable metrics entirely?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can have flag, lacking metrics won't hurt working of the daemon so IMO it is better to continue.

If you want I can do Error log here instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling of the metrics would be just not injecting the metrics.

}

// let the user know we're going.
fmt.Printf("Initializing daemon...\n")

Expand Down Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions test/sharness/t0600-issues-and-regressions-online.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" '
Expand Down