Node_exporter: Can't build on Ubuntu 16.04

Created on 8 Jun 2018  路  10Comments  路  Source: prometheus/node_exporter

Host operating system: output of uname -a

Linux calculate-production-14 2.6.32-042stab127.2 #1 SMP Thu Jan 4 16:41:44 MSK 2018 x86_64 x86_64 x86_64 GNU/Linux

What did you do that produced an error?

make

What did you see?

Makefile:74: warning: overriding recipe for target 'test'
Makefile.common:61: warning: ignoring old recipe for target 'test'
Makefile:105: warning: overriding recipe for target 'docker'
Makefile.common:89: warning: ignoring old recipe for target 'docker'
>> checking code style
! gofmt -d $(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
GOOS= GOARCH= go get -u honnef.co/go/tools/cmd/staticcheck

>> running staticcheck
/root/gocode/bin/staticcheck -ignore "" ./...
vendor/github.com/beevik/ntp/ntp.go:28:1: only the first constant has an explicit type (SA9004)
vendor/github.com/golang/protobuf/proto/properties.go:218:2: this value of s is never used (SA4006)
vendor/github.com/golang/protobuf/proto/properties.go:329:5: ineffective break statement. Did you mean to break out of the outer loop? (SA4011)
vendor/golang.org/x/net/bpf/constants.go:131:1: only the first constant has an explicit type (SA9004)
vendor/gopkg.in/alecthomas/kingpin.v2/app.go:186:2: this value of selected is never used (SA4006)
Makefile.common:73: recipe for target 'staticcheck' failed
make: *** [staticcheck] Error 1

Most helpful comment

That's very strange, staticcheck normally ignores the vendor directory. I'm running on 16.04 and do not see this. What version of golang are you using?

You can always skip the staticcheck by just running make build.

All 10 comments

What is the pwd when you are running make? This appears to be the error you would get if you ran it outside of your $GOPATH.

root@calculate-production-13:~/gocode/src/github.com/prometheus/node_exporter# echo $GOPATH
/root/gocode
root@calculate-production-13:~/gocode/src/github.com/prometheus/node_exporter# pwd
/root/gocode/src/github.com/prometheus/node_exporter

That's very strange, staticcheck normally ignores the vendor directory. I'm running on 16.04 and do not see this. What version of golang are you using?

You can always skip the staticcheck by just running make build.

thanks will do make build

go version go1.6.1 linux/amd64, and I also tried for 1.10 with same result

We currently require at least 1.7. 1.10 should work ok, but there are CGO bugs, so you will want to build with CGO_ENABLED=0. Our current official builds are with 1.9.x.

I have no idea why staticcheck is failing in that way, I would possibly delete your /root/gocode/bin/staticcheck and rebuild it.

Just ran into the same issue. Could it be because of this line?

https://github.com/prometheus/node_exporter/blob/606568314befb8127ce48de29ecb647bd9d8507a/Makefile#L25-L27

It seems to later get used to pass explicit ignore rules to the staticcheck binary which I think is why the resulting command executed for myself and the OP is:

staticcheck -ignore "" ./...

@jeteon I don't think so. even with an empty ignore, staticcheck should ignore the vendor/ directory. Our CI pipeline runs a full make all the time, we would see this issue.

How old is your staticcheck binary?

ls -l $(which staticcheck)

I'm not sure how to check how old it is. It was compiled today when I did the build if that's what you're asking. When I run bin/staticcheck -version all I get is:

staticcheck (no version)

If it helps, the Go I used to compile it is:

go version go1.6.2 linux/amd64

Go 1.6 is too old, we only support >= 1.7.

This is highly likely due to Ubuntu's distribution compiler, I recommend removing any 1.6 packages and getting golang-1.9 from xenial-backports.

Like I said above, there are known issues with 1.10 and the node_exporter.

I installed a clean Ubuntu 16.04 machine and have verified that this is a bug in the default Go 1.6 version.

The easiest way to fix this is to update your Go compiler.

$ sudo apt install golang-1.10
$ export PATH="/usr/lib/go-1.10/bin:${PATH}"
$ CGO_ENABLE=0 make
Was this page helpful?
0 / 5 - 0 ratings