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

Use module github.com/prometheus/prometheus/v2 in go.mod #7663

Closed
bogdandrutu opened this issue Jul 24, 2020 · 11 comments
Closed

Use module github.com/prometheus/prometheus/v2 in go.mod #7663

bogdandrutu opened this issue Jul 24, 2020 · 11 comments

Comments

@bogdandrutu
Copy link
Contributor

In order to follow golang conventions for versions you need to update the module in go.mod to be v2.

Try:

go get github.com/prometheus/prometheus@v2.19.3

go: finding github.com/prometheus/prometheus v2.19.3
go: finding github.com/prometheus/prometheus v2.19.3
go get github.com/prometheus/prometheus@v2.19.3: github.com/prometheus/prometheus@v2.19.3: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2
@roidelapluie
Copy link
Member

roidelapluie commented Jul 24, 2020

Prometheus is NOT following golang convention.

Adding v2 would mistake people into believing that we follow Go conventions and semver from a go mod perspective. This is not the case.

You can go get specific commit id's or tag ids:

git rev-list -n 1 v2.19.3
657ba53

go get github.com/prometheus/prometheus@657ba532e42f1db8d7c77bf802378643da0d3118

@roidelapluie
Copy link
Member

Duplicate of #6048

@roidelapluie roidelapluie marked this as a duplicate of #6048 Jul 24, 2020
@Benjamintf1
Copy link

Benjamintf1 commented Aug 19, 2020

@roidelapluie mistake people into believing that we follow Go conventions If you are using go mod, you should be following go conventions. This makes it impossible for anyone else to use go mod to pull in prometheus. We followed the workaround, and it doesn't work.

@roidelapluie
Copy link
Member

Hi Benjamin,

We are happy to help you on the prometheus-developers mailing list about this matter, if you can provide us with more details there about what does not work.

@Benjamintf1
Copy link

Use go (I believe) 1.14.x. Try and import promethues. See that it gives the following error github.com/prometheus/prometheus@v2.19.3: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2, even when imported using the former method.

@roidelapluie
Copy link
Member

Yes, you need to

go get github.com/prometheus/prometheus@657ba532e42f1db8d7c77bf802378643da0d3118

@Benjamintf1
Copy link

Benjamintf1 commented Aug 19, 2020

yeah, that doesn't work. It works if you're using old golang versions(aka 1.13), but not with newer version(aka 1.14) Are you still using 1.13?

@roidelapluie
Copy link
Member

I am on go 1.15. It works for me:

~/testgoprom $ go mod init github.com/roidelapluie/testgoprom
go: creating new go.mod: module github.com/roidelapluie/testgoprom
~/testgoprom $ go get github.com/prometheus/prometheus@657ba532e42f1db8d7c77bf802378643da0d3118
go: downloading github.com/prometheus/prometheus v1.8.2-0.20200724121523-657ba532e42f
go: github.com/prometheus/prometheus 657ba532e42f1db8d7c77bf802378643da0d3118 => v1.8.2-0.20200724121523-657ba532e42f
~/testgoprom $ go version
go version go1.15 linux/amd64

@roidelapluie
Copy link
Member

Note that you can ignore the v1.8.2, that does not reflect the reality.

@Benjamintf1
Copy link

Hmm, I'm majorly confused. I was in a state where I was getting the error, now I'm suddenly not? I still have some major concerns about the workaround required to be functional with go mod(especially as it's been the very strong stance of go mod that users of go mod should use major versioning in their modules, and as they've reduced workarounds to do so, like removing +incompatible to do so. https://blog.golang.org/v2-go-modules. We'll keep investigating.

@Benjamintf1
Copy link

Benjamintf1 commented Aug 19, 2020

go mod can be a frustrating mystery sometimes :/ My apologies for some of my tone earlier.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants