-
Notifications
You must be signed in to change notification settings - Fork 924
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
feat: add operator build_info metrics and go runtime metrics #6044
base: master
Are you sure you want to change the base?
Changes from all commits
3f919e8
fb2da37
851c785
e1acbcf
5868c91
4880924
a65fcac
d7fd1fd
e13e2e7
366033d
d76e794
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -19,17 +19,20 @@ package version | |||||||
import ( | ||||||||
"fmt" | ||||||||
"runtime" | ||||||||
|
||||||||
"github.com/prometheus/client_golang/prometheus" | ||||||||
) | ||||||||
|
||||||||
// Info contains versioning information. | ||||||||
type Info struct { | ||||||||
GitVersion string `json:"gitVersion"` | ||||||||
GitCommit string `json:"gitCommit"` | ||||||||
GitTreeState string `json:"gitTreeState"` | ||||||||
BuildDate string `json:"buildDate"` | ||||||||
GoVersion string `json:"goVersion"` | ||||||||
Compiler string `json:"compiler"` | ||||||||
Platform string `json:"platform"` | ||||||||
GitVersion string `json:"gitVersion"` | ||||||||
GitCommit string `json:"gitCommit"` | ||||||||
GitAbbreviativeCommit string `json:"gitAbbreviativeCommit"` | ||||||||
GitTreeState string `json:"gitTreeState"` | ||||||||
BuildDate string `json:"buildDate"` | ||||||||
GoVersion string `json:"goVersion"` | ||||||||
Compiler string `json:"compiler"` | ||||||||
Platform string `json:"platform"` | ||||||||
} | ||||||||
|
||||||||
// String returns a Go-syntax representation of the Info. | ||||||||
|
@@ -41,12 +44,38 @@ func (info Info) String() string { | |||||||
// what code a binary was built from. | ||||||||
func Get() Info { | ||||||||
return Info{ | ||||||||
GitVersion: gitVersion, | ||||||||
GitCommit: gitCommit, | ||||||||
GitTreeState: gitTreeState, | ||||||||
BuildDate: buildDate, | ||||||||
GoVersion: runtime.Version(), | ||||||||
Compiler: runtime.Compiler, | ||||||||
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), | ||||||||
GitVersion: gitVersion, | ||||||||
GitAbbreviativeCommit: gitAbbreviativeCommit, | ||||||||
GitCommit: gitCommit, | ||||||||
GitTreeState: gitTreeState, | ||||||||
BuildDate: buildDate, | ||||||||
GoVersion: runtime.Version(), | ||||||||
Compiler: runtime.Compiler, | ||||||||
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
// NewCollector returns a collector that exports metrics about current version | ||||||||
// information. | ||||||||
func NewCollector(program string) prometheus.Collector { | ||||||||
return prometheus.NewGaugeFunc( | ||||||||
prometheus.GaugeOpts{ | ||||||||
Namespace: program, | ||||||||
Name: "build_info", | ||||||||
Help: fmt.Sprintf( | ||||||||
"A metric with a constant '1' value labeled by version, revision, branch, goversion from which %s was built, and the goos and goarch for the build.", | ||||||||
program, | ||||||||
), | ||||||||
ConstLabels: prometheus.Labels{ | ||||||||
"version": Get().GitVersion, | ||||||||
"revision": Get().GitAbbreviativeCommit, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmmm....🤔 @RainbowMango Probably best to stay consistent with prometheus's specification. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I apologize for not explaining why I suggested those changes. Regarding your point about maintaining consistency with Prometheus, I'd love to, but Karmada might emit both commit and abbreviate commit, we should differentiate them in terms of naming to avoid confusion. |
||||||||
"goversion": runtime.Version(), | ||||||||
"goos": runtime.GOOS, | ||||||||
"goarch": runtime.GOARCH, | ||||||||
"compiler": runtime.Compiler, | ||||||||
"platform": fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), | ||||||||
}, | ||||||||
}, | ||||||||
func() float64 { return 1 }, | ||||||||
) | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can omit the component name?
Because the metric emitted from a component indicates it's build info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The metrcs specification defines different metrics names, and is not distinguished by different tags of the same metrics name.
ref: https://github.com/prometheus/client_golang/blob/main/prometheus/collectors/version/version.go#L28-L30