PromQL模块缺失

huangapple go评论77阅读模式
英文:

PromQL Module Missing

问题

我正在尝试使用 promql 包 这里

package main

import (
	"fmt"    
	"github.com/prometheus/prometheus/promql/parser"
)

func main() {
	fmt.Println("Hello")
    parser.ParseExpr("foobar")    
}

导入时遇到了问题。这是错误信息:

> 未找到所需的模块提供包 github.com/prometheus/prometheus/promql/parser;要添加它:
>     go get github.com/prometheus/prometheus/promql/parser (编译)

我尝试运行 go get github.com/prometheus/prometheus/promql/parser,但失败了。

> go get: 找到模块 github.com/prometheus/prometheus@upgrade (v2.5.0+incompatible),但不包含包 github.com/prometheus/prometheus/promql/parser

这是我的 go.mod 文件的当前内容:

module foo.com/bar/parser

go 1.17

require github.com/prometheus/prometheus v2.5.0+incompatible // indirect
英文:

I am trying to use the promql package here

package main

import (
	"fmt"    
	"github.com/prometheus/prometheus/promql/parser"
)

func main() {
	fmt.Println("Hello")
    parser.ParseExpr("foobar")    
}

Having trouble importing. This is the error:

> no required module provides package
> github.com/prometheus/prometheus/promql/parser; to add it:
> go get github.com/prometheus/prometheus/promql/parser (compile)

I tried to run go get github.com/prometheus/prometheus/promql/parser as suggested but it fails.

> go get: module github.com/prometheus/prometheus@upgrade found
> (v2.5.0+incompatible), but does not contain package
> github.com/prometheus/prometheus/promql/parser

Here is my go.mod currently:

module foo.com/bar/parser

go 1.17

require github.com/prometheus/prometheus v2.5.0+incompatible // indirect

答案1

得分: 2

使用go get github.com/prometheus/prometheus@83032011a5d3e6102624fe58241a374a7201fee8(该提交是此时最新的发布版本,v2.33.4)

需要这样做的原因是这个问题

> 这是Go模块的已知问题。Prometheus版本的语义化版本控制了Prometheus作为服务器的行为,而不是作为库的代码。通过将模块路径更改为v2,我们将暗示Prometheus遵守Go模块作为库的契约,但实际上它并没有遵守,即使是在次要版本中也会有许多破坏性变更。

以及

> Prometheus最初并不打算用作库。现在情况已经改变,它被打算用作库,即使我们不接受所有通用贡献。

你看到的错误是因为go get默认获取的是一个旧版本v2.5.0,该版本于2018年发布,不包含parser包。这是因为Prometheus使用的版本控制方案与Go假设的版本控制方案不一致。

有关更多信息,请参见此问题

英文:

Use go get github.com/prometheus/prometheus@83032011a5d3e6102624fe58241a374a7201fee8 (that commit is the latest release at this point in time, v2.33.4)

The reason this is needed is that

>This is a known issue with Go Modules. The semantic versioning of Prometheus versions the behavior of Prometheus as a server, not its code as a library. By changing the module path to v2, we would suggest that Prometheus obeys the contract of Go Modules as a library, but it doesn't, i.e. there are many breaking changes to expect even in a minor release.

and:

>Prometheus was not intended to be used as a library. Now that has changed, and it is intended to be used as such, even if we do not accept all general-purpose contributions.

The error you are seeing is because go get is grabbing an old release v2.5.0 by default which was released back in 2018 and does not include the parser package. This happens because the versioning scheme used by Prometheus does not align with that assumed by Go.

See this issue for additional info.

huangapple
  • 本文由 发表于 2022年2月28日 08:21:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/71289498.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定