I have a couple of cmd apps with some imports:
cmd/monitorrules/main.go:
package main
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"sort"
"strings"
"github.com/lightbend/console-api/monitors"
"gopkg.in/alecthomas/kingpin.v2"
)
...cmd/yamltojson/main.go:
package main
import (
"fmt"
"io/ioutil"
"os"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/ghodss/yaml"
)
...I also have a tools.go file:
// +build tools
package tools
import (
_ "golang.org/x/lint/golint"
_ "github.com/prometheus/prometheus/cmd/promtool@6f92ce56053866194ae5937012c1bec40f1dd1d9"
)An empty go.mod file:
module github.com/lightbend/observability/monitors
go 1.13Now I'm trying to figure out what the correct way is to:
- Populate the
go.modandgo.sumfiles. - On the build machine, download the tools so that the build scripts can use them.
This seems to get me part of the way there:
➜ monitors git:(generate-monitors) ✗ go get ./...
go: finding github.com/lightbend/console-api/monitors latestgo.mod:
module github.com/lightbend/observability/monitors
go 1.13
require (
github.com/ghodss/yaml v1.0.0
github.com/lightbend/console-api v1.2.4
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)Ok so the imports from the cmd apps are there but not the tools.
Following https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md it would seem I have to use go install.
➜ monitors git:(generate-monitors) ✗ go install golang.org/x/lint/golintNo output but exit code was 0 so I guess just carry on?
➜ monitors git:(generate-monitors) ✗ go install github.com/prometheus/prometheus/cmd/promtool@6f92ce56053866194ae5937012c1bec40f1dd1d9
can't load package: package github.com/prometheus/prometheus/cmd/promtool@6f92ce56053866194ae5937012c1bec40f1dd1d9: can only use path@version syntax with 'go get'Oops! Hmm so no version allowed here apparently.
Hmm that's not great, going to get bit by prometheus/prometheus#5590.
Oh well...
➜ monitors git:(generate-monitors) ✗ go install github.com/prometheus/prometheus/cmd/promtoolUmmm ok that worked but it shouldn't have?
go.mod:
module github.com/lightbend/observability/monitors
go 1.13
require (
github.com/ghodss/yaml v1.0.0
github.com/lightbend/console-api v1.2.4
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)Still the same.
go mod tidygo.mod:
module github.com/lightbend/observability/monitors
go 1.13
require (
github.com/ghodss/yaml v1.0.0
github.com/lightbend/console-api v1.2.4
github.com/prometheus/prometheus v0.0.0-20190525122359-d20e84d0fb64
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)
🤨
➜ monitors git:(generate-monitors) ✗ rm go.sum && echo 'module github.com/lightbend/observability/monitors
go 1.13' > go.mod
➜ monitors git:(generate-monitors) ✗ go get github.com/prometheus/prometheus/cmd/promtool@6f92ce56053866194ae5937012c1bec40f1dd1d9
go: finding github.com/prometheus/prometheus/cmd/promtool 6f92ce56053866194ae5937012c1bec40f1dd1d9
go: finding github.com/prometheus 6f92ce56053866194ae5937012c1bec40f1dd1d9
go: finding github.com 6f92ce56053866194ae5937012c1bec40f1dd1d9
go: finding github.com/prometheus/prometheus 6f92ce56053866194ae5937012c1bec40f1dd1d9
go: finding github.com/prometheus/prometheus/cmd 6f92ce56053866194ae5937012c1bec40f1dd1d9
➜ monitors git:(generate-monitors) ✗ go get ./...
go: finding github.com/lightbend/console-api/monitors latest
➜ monitors git:(generate-monitors) ✗ rm go.sum && echo 'module github.com/lightbend/observability/monitors
go 1.13' > go.mod
➜ monitors git:(generate-monitors) ✗ go get ./...
go: finding github.com/lightbend/console-api/monitors latest
➜ monitors git:(generate-monitors) ✗ go get github.com/prometheus/prometheus/cmd/promtool@6f92ce56053866194ae5937012c1bec40f1dd1d9
go: finding github.com 6f92ce56053866194ae5937012c1bec40f1dd1d9
go: finding github.com/prometheus/prometheus 6f92ce56053866194ae5937012c1bec40f1dd1d9
go: finding github.com/prometheus 6f92ce56053866194ae5937012c1bec40f1dd1d9
go: finding github.com/prometheus/prometheus/cmd/promtool 6f92ce56053866194ae5937012c1bec40f1dd1d9
go: finding github.com/prometheus/prometheus/cmd 6f92ce56053866194ae5937012c1bec40f1dd1d9
# k8s.io/client-go/rest
../../../go/pkg/mod/k8s.io/[email protected]+incompatible/rest/request.go:598:31: not enough arguments in call to watch.NewStreamWatcher
have (*versioned.Decoder)
want (watch.Decoder, watch.Reporter)WTF! Why does the order matter?
➜ monitors git:(generate-monitors) ✗ rm go.sum && echo 'module github.com/lightbend/observability/monitors
go 1.13' > go.mod
➜ monitors git:(generate-monitors) ✗ rm go.sum && echo 'module github.com/lightbend/observability/monitors\[C
➜ monitors git:(generate-monitors) ✗ go get github.com/prometheus/prometheus/cmd/promtool
go: finding github.com/google/pprof latest
go: finding github.com/prometheus/client_model latest
go: finding golang.org/x/oauth2 latest
go: finding k8s.io/api latest
go: finding k8s.io/apimachinery latest
go: finding github.com/mwitkow/go-conntrack latest
go: finding github.com/samuel/go-zookeeper latest
go: finding k8s.io/utils latest
build github.com/prometheus/prometheus/cmd/promtool: cannot load github.com/Azure/azure-sdk-for-go/arm/compute: module github.com/Azure/azure-sdk-for-go@latest (v36.1.0+incompatible) found, but does not contain package github.com/Azure/azure-sdk-for-go/arm/compute
➜ monitors git:(generate-monitors) ✗ rm go.sum && echo 'module github.com/lightbend/observability/monitors
go 1.13' > go.mod
➜ monitors git:(generate-monitors) ✗ go get ./...
go: finding github.com/lightbend/console-api/monitors latest
➜ monitors git:(generate-monitors) ✗ go get github.com/prometheus/prometheus/cmd/promtoolThis time it is the reverse problem. 🤯