Go Path Issues Installing Sensu Go from Source

Installing Sensu Go with the MIT license from source (https://github.com/sensu/sensu-go) has proved challenging. Following the directions presented in the readme.md does not let me install the service and instead I get a tremendous amount of go pathing issues.

ubuntu@ip-10-4-1-129:~/go/src/github.com/sensu/sensu-go$ pwd
ubuntu@ip-10-4-1-129:~/go/src/github.com/sensu/sensu-go$ echo GOPATH /home/ubuntu/go ubuntu@ip-10-4-1-129:~/go/src/github.com/sensu/sensu-go echo GOROOT /home/ubuntu/go ubuntu@ip-10-4-1-129:~/go/src/github.com/sensu/sensu-go ls
CHANGELOG.md DCO README.md asset build.ps1 cmd docker-compose.yaml go.sum js rpc testing types
CODE_OF_CONDUCT.md FAQ.md agent backend build.sh command docker-scripts graphql licenses scripts token util
CONTRIBUTING.md LICENSE api bonsai cli dashboard go.mod handler process system transport version
ubuntu@ip-10-4-1-129:~/go/src/github.com/sensu/sensu-go$ ls cmd
loadit sensu-agent sensu-backend sensuctl
ubuntu@ip-10-4-1-129:~/go/src/github.com/sensu/sensu-go$ ls cmd/sensu-backend/
LICENSE main.go
ubuntu@ip-10-4-1-129:~/go/src/github.com/sensu/sensu-go$ go run ./cmd/sensu-backend
warning: GOPATH set to GOROOT (/home/ubuntu/go) has no effect
go run: no go files listed

As seen above my Go path is set to “/home/ubuntu/go”, but it doesn’t seem to recognize “sensu-go/cmd/sensu-backend/main.go” is a Go file.

When I try to build directly (not using the “run” command) I get the following pathing issues:

There seems to be an ongoing issue with this regarding Go and Sensu-Go:

Using GOROOT and putting the source under your GOPATH is no longer required with newer versions of Go.

Here are the steps I used and was able to compile from source (Using Go 1.13.1 installed in /usr/local/go on Fedora 30) :

$ which go
$  go version
go version go1.13.1 linux/amd64
$ env | grep GO
$ go build ./cmd/sensu-agent
go: downloading golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980
go: downloading github.com/gorilla/mux v1.7.3
go: downloading go.etcd.io/bbolt v1.3.4
[many lines of go: downloading deleted for brevity]
go: finding github.com/libp2p/go-reuseport v0.0.1
go: finding github.com/shirou/gopsutil v0.0.0-20190901111213-e4ec7b275ada
$ ls -l sensu-agent
-rwxrwxr-x 1 todd todd 72772879 Jun 11 07:56 sensu-agent
$ go build ./cmd/sensu-backend
go: downloading github.com/stretchr/testify v1.6.0
go: downloading github.com/mattn/go-isatty v0.0.8
[many lines of go: downloading deleted for brevity]
go: finding github.com/stretchr/testify v1.6.0
go: finding gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
$ ls -l sensu-backend
-rwxrwxr-x 1 todd todd 86723826 Jun 11 07:58 sensu-backend

Thank you Todd, I still have no luck following the steps above:

It seems like the main.go has the wrong path to the build files or something of that nature.

Ah, your version of Go is way outdated and doesn’t support the new modules paradigm. You will need a newer version of Go. I suggest the latest iteration of 1.13.

1 Like

Perfect! That worked for me, thank you Todd!

1 Like