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

How can I step debug prometheus #2298

Closed
maklemenz opened this Issue Dec 22, 2016 · 9 comments

Comments

Projects
None yet
3 participants
@maklemenz
Copy link

maklemenz commented Dec 22, 2016

What did you do?

I tried the intellij golang debugger.
I tried to compile prometheus using go build.

What did you expect to see?

I expected to be able to step debug through the code

What did you see instead? Under which circumstances?

# command-line-arguments
cmd/prometheus/main.go:67: undefined: parse
cmd/prometheus/main.go:72: undefined: cfg in cfg.printVersion
cmd/prometheus/main.go:86: undefined: cfg in cfg.localStorageEngine
cmd/prometheus/main.go:88: undefined: cfg in cfg.storage
cmd/prometheus/main.go:93: undefined: cfg in cfg.localStorageEngine
cmd/prometheus/main.go:97: undefined: cfg in cfg.remote
cmd/prometheus/main.go:112: undefined: cfg in cfg.notifier
cmd/prometheus/main.go:114: undefined: cfg in cfg.queryEngine
cmd/prometheus/main.go:123: undefined: cfg in cfg.web
cmd/prometheus/main.go:126: undefined: cfg
cmd/prometheus/main.go:126: too many errors

Process finished with exit code 2

Environment

Ubuntu 16.04 LTS

@juliusv

This comment has been minimized.

Copy link
Member

juliusv commented Dec 22, 2016

How did you invoke go build? The error reads like you only invoked it on one file (main.go), not the entire directory / package (cmd/prometheus), since it cannot find e.g. parse(), which is defined in the same directory in config.go.

@maklemenz

This comment has been minimized.

Copy link
Author

maklemenz commented Dec 22, 2016

@juliusv yes I called it on the main.go

I guess my whole project setup is messed up:

mk@mk:~/git/prometheus$ go build cmd/prometheus/main.go 
# command-line-arguments
cmd/prometheus/main.go:67: undefined: parse
cmd/prometheus/main.go:72: undefined: cfg in cfg.printVersion
cmd/prometheus/main.go:86: undefined: cfg in cfg.localStorageEngine
cmd/prometheus/main.go:88: undefined: cfg in cfg.storage
cmd/prometheus/main.go:93: undefined: cfg in cfg.localStorageEngine
cmd/prometheus/main.go:97: undefined: cfg in cfg.remote
cmd/prometheus/main.go:112: undefined: cfg in cfg.notifier
cmd/prometheus/main.go:114: undefined: cfg in cfg.queryEngine
cmd/prometheus/main.go:123: undefined: cfg in cfg.web
cmd/prometheus/main.go:126: undefined: cfg
cmd/prometheus/main.go:126: too many errors

mk@mk:~/git/prometheus$ go build cmd/prometheus/
can't load package: package cmd/prometheus: open /usr/lib/go-1.6/src/cmd/prometheus: no such file or directory

mk@mk:~/git/prometheus$ go build cmd/prometheus/*
# command-line-arguments
cmd/prometheus/main.go:204: cannot use notifier (type *notifier.Notifier) as type "github.com/prometheus/client_golang/prometheus".Collector in argument to "github.com/prometheus/client_golang/prometheus".MustRegister:
	*notifier.Notifier does not implement "github.com/prometheus/client_golang/prometheus".Collector (wrong type for Collect method)
		have Collect(chan<- "github.com/prometheus/prometheus/vendor/github.com/prometheus/client_golang/prometheus".Metric)
		want Collect(chan<- "github.com/prometheus/client_golang/prometheus".Metric)
cmd/prometheus/main.go:282: cannot use []"github.com/prometheus/common/model".LabelSet literal (type []"github.com/prometheus/common/model".LabelSet) as type []"github.com/prometheus/prometheus/vendor/github.com/prometheus/common/model".LabelSet in field value

@juliusv

This comment has been minimized.

Copy link
Member

juliusv commented Dec 22, 2016

Try go build ./cmd/prometheus. go build normally expects the name of a package to build (in this case ./cmd/prometheus or canonically github.com/prometheus/prometheus/cmd/prometheus), although it also allows you to specify individual files for one-off use cases.

@maklemenz

This comment has been minimized.

Copy link
Author

maklemenz commented Dec 22, 2016

well, it would have been too easy if it would just work

mk@mk:~/git/prometheus$ go build ./cmd/prometheus/
# _/home/mk/git/prometheus/cmd/prometheus
cmd/prometheus/main.go:204: cannot use notifier (type *notifier.Notifier) as type "github.com/prometheus/client_golang/prometheus".Collector in argument to "github.com/prometheus/client_golang/prometheus".MustRegister:
	*notifier.Notifier does not implement "github.com/prometheus/client_golang/prometheus".Collector (wrong type for Collect method)
		have Collect(chan<- "github.com/prometheus/prometheus/vendor/github.com/prometheus/client_golang/prometheus".Metric)
		want Collect(chan<- "github.com/prometheus/client_golang/prometheus".Metric)
cmd/prometheus/main.go:282: cannot use []"github.com/prometheus/common/model".LabelSet literal (type []"github.com/prometheus/common/model".LabelSet) as type []"github.com/prometheus/prometheus/vendor/github.com/prometheus/common/model".LabelSet in field value

Running it is a whole other story:

mk@mk:~/git/prometheus$ go run ./cmd/prometheus
go run: no go files listed

make build works fine

@juliusv

This comment has been minimized.

Copy link
Member

juliusv commented Dec 22, 2016

Hmm, go build ./cmd/prometheus works for me.

The error you're getting reads like it's using a wrong version of the Prometheus client library that doesn't fit together with the Prometheus code base, although it should only be using the correct one that is vendored in Prometheus itself (under ./vendor/...). Not sure what is going on there in your setup... what Go version are you using? Maybe one that doesn't know about vendoring by default yet?

@maklemenz

This comment has been minimized.

Copy link
Author

maklemenz commented Dec 29, 2016

I found a way.

Make sure prometheus is in $GOPATH/src/github.com/prometheus/prometheus.
If you use intellij (not goland eap) use a Go Application (kind file) and not Go Single File as run configuration
Make sure your go compiler is up to date

While go build ./cmd/prometheus will work, go run ./cmd/prometheus will not. go run ./cmd/prometheus/main.go also does not work as expected. go run is the way that intellij will use to start and debug the application so that just has to work.
As a workaround (definitely not a solution) I had to copy the contents from cmd/prometheus/config.go into cmd/prometheus/main.go and remove cmd/prometheus/config*
Then go run $GOPAH/src/github.com/prometheus/prometheus/cmd/prometheus/main.go finally worked.

@maklemenz maklemenz closed this Dec 29, 2016

@candyleer

This comment has been minimized.

Copy link

candyleer commented Apr 17, 2018

@maklemenz when i build ,the error is

# command-line-arguments
cmd/prometheus/main.go:220:41: undefined: Uname
cmd/prometheus/main.go:221:38: undefined: FdLimits

in intellij
does this problem you have meet?

@candyleer

This comment has been minimized.

Copy link

candyleer commented Apr 17, 2018

@maklemenz i find the solution by
image
it works perfectly

@lock

This comment has been minimized.

Copy link

lock bot commented Mar 22, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 22, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.